[SourceKit] Remove diagnostics path calculation

The diagnostic group documentation now point to the swift.org URL rather
than the toolchain path, so it no longer needs to be passed all the way
through sourcekitd.

Resolves rdar://151500502.

(cherry picked from commit 381684a389)
This commit is contained in:
Ben Barham
2025-05-16 17:49:25 -07:00
parent b923bf401f
commit 03ca9ea0a5
22 changed files with 47 additions and 107 deletions

View File

@@ -33,7 +33,6 @@ namespace ide {
class CompileInstance {
const std::string &SwiftExecutablePath;
const std::string &RuntimeResourcePath;
const std::string &DiagnosticDocumentationPath;
const std::shared_ptr<swift::PluginRegistry> Plugins;
struct Options {
@@ -70,12 +69,10 @@ class CompileInstance {
public:
CompileInstance(const std::string &SwiftExecutablePath,
const std::string &RuntimeResourcePath,
const std::string &DiagnosticDocumentationPath,
std::shared_ptr<swift::PluginRegistry> Plugins = nullptr)
: SwiftExecutablePath(SwiftExecutablePath),
RuntimeResourcePath(RuntimeResourcePath),
DiagnosticDocumentationPath(DiagnosticDocumentationPath),
Plugins(Plugins), CachedCIInvalidated(false), CachedReuseCount(0) {}
RuntimeResourcePath(RuntimeResourcePath), Plugins(Plugins),
CachedCIInvalidated(false), CachedReuseCount(0) {}
/// NOTE: \p Args is only used for checking the equaity of the invocation.
/// Since this function assumes that it is already normalized, exact the same

View File

@@ -27,8 +27,7 @@ bool initCompilerInvocation(
StringRef UnresolvedPrimaryFile,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
const std::string &swiftExecutablePath,
const std::string &runtimeResourcePath,
const std::string &diagnosticDocumentationPath, time_t sessionTimestamp,
const std::string &runtimeResourcePath, time_t sessionTimestamp,
std::string &Error);
bool initInvocationByClangArguments(ArrayRef<const char *> ArgList,

View File

@@ -258,11 +258,9 @@ bool CompileInstance::setupCI(
auto &Diags = CI->getDiags();
SmallVector<const char *, 16> args;
// Put '-resource-dir' and '-diagnostic-documentation-path' at the top to
// allow overriding them with the passed in arguments.
// Put '-resource-dir' at the top to allow overriding them with the passed in
// arguments.
args.append({"-resource-dir", RuntimeResourcePath.c_str()});
args.append({"-Xfrontend", "-diagnostic-documentation-path", "-Xfrontend",
DiagnosticDocumentationPath.c_str()});
args.append(origArgs.begin(), origArgs.end());
SmallString<256> driverPath(SwiftExecutablePath);

View File

@@ -157,18 +157,13 @@ bool ide::initCompilerInvocation(
StringRef UnresolvedPrimaryFile,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
const std::string &swiftExecutablePath,
const std::string &runtimeResourcePath,
const std::string &diagnosticDocumentationPath, time_t sessionTimestamp,
const std::string &runtimeResourcePath, time_t sessionTimestamp,
std::string &Error) {
SmallVector<const char *, 16> Args;
// Make sure to put '-resource-dir' and '-diagnostic-documentation-path' at
// the top to allow overriding them with the passed in arguments.
// Make sure to put '-resource-dir' at the top to allow overriding them with
// the passed in arguments.
Args.push_back("-resource-dir");
Args.push_back(runtimeResourcePath.c_str());
Args.push_back("-Xfrontend");
Args.push_back("-diagnostic-documentation-path");
Args.push_back("-Xfrontend");
Args.push_back(diagnosticDocumentationPath.c_str());
Args.append(OrigArgs.begin(), OrigArgs.end());
SmallString<32> ErrStr;

View File

@@ -1,11 +1,11 @@
typealias Crap = () -> ()
extension Crap {}
typealias Foo = () -> ()
extension Foo {}
// RUN: %sourcekitd-test -req=sema %s -- %s | %FileCheck %s -check-prefix=NO_OVERRIDE
// NO_OVERRIDE: key.description: "non-nominal type
// NO_OVERRIDE: key.educational_note_paths: [
// NO_OVERRIDE-NEXT: share{{[/\\]+}}doc{{[/\\]+}}swift{{[/\\]+}}diagnostics{{[/\\]+}}nominal-types"
// NO_OVERRIDE-NEXT: "https://docs.swift.org/compiler/documentation/diagnostics/nominal-types"
// NO_OVERRIDE-NEXT: ]
// RUN: %sourcekitd-test -req=sema %s -- -Xfrontend -diagnostic-documentation-path -Xfrontend /educational/notes/path/prefix %s | %FileCheck %s -check-prefix=OVERRIDE

View File

@@ -166,7 +166,6 @@ class Context {
/// Used to find clang relative to it.
std::string SwiftExecutablePath;
std::string RuntimeLibPath;
std::string DiagnosticDocumentationPath;
std::unique_ptr<LangSupport> SwiftLang;
std::shared_ptr<NotificationCenter> NotificationCtr;
std::shared_ptr<GlobalConfig> Config;
@@ -176,7 +175,6 @@ class Context {
public:
Context(StringRef SwiftExecutablePath, StringRef RuntimeLibPath,
StringRef DiagnosticDocumentationPath,
llvm::function_ref<std::unique_ptr<LangSupport>(Context &)>
LangSupportFactoryFn,
llvm::function_ref<std::shared_ptr<PluginSupport>(Context &)>
@@ -187,9 +185,6 @@ public:
StringRef getSwiftExecutablePath() const { return SwiftExecutablePath; }
StringRef getRuntimeLibPath() const { return RuntimeLibPath; }
StringRef getDiagnosticDocumentationPath() const {
return DiagnosticDocumentationPath;
}
LangSupport &getSwiftLangSupport() { return *SwiftLang; }

View File

@@ -37,14 +37,12 @@ GlobalConfig::getIDEInspectionOpts() const {
SourceKit::Context::Context(
StringRef SwiftExecutablePath, StringRef RuntimeLibPath,
StringRef DiagnosticDocumentationPath,
llvm::function_ref<std::unique_ptr<LangSupport>(Context &)>
LangSupportFactoryFn,
llvm::function_ref<std::shared_ptr<PluginSupport>(Context &)>
PluginSupportFactoryFn,
bool shouldDispatchNotificationsOnMain)
: SwiftExecutablePath(SwiftExecutablePath), RuntimeLibPath(RuntimeLibPath),
DiagnosticDocumentationPath(DiagnosticDocumentationPath),
NotificationCtr(
new NotificationCenter(shouldDispatchNotificationsOnMain)),
Config(new GlobalConfig()), ReqTracker(new RequestTracker()),

View File

@@ -564,12 +564,11 @@ struct SwiftASTManager::Implementation {
std::shared_ptr<SwiftStatistics> Stats,
std::shared_ptr<RequestTracker> ReqTracker,
std::shared_ptr<PluginRegistry> Plugins, StringRef SwiftExecutablePath,
StringRef RuntimeResourcePath, StringRef DiagnosticDocumentationPath)
StringRef RuntimeResourcePath)
: EditorDocs(EditorDocs), Config(Config), Stats(Stats),
ReqTracker(ReqTracker), Plugins(Plugins),
SwiftExecutablePath(SwiftExecutablePath),
RuntimeResourcePath(RuntimeResourcePath),
DiagnosticDocumentationPath(DiagnosticDocumentationPath),
SessionTimestamp(llvm::sys::toTimeT(std::chrono::system_clock::now())) {
}
@@ -582,7 +581,6 @@ struct SwiftASTManager::Implementation {
/// Used to find clang relative to it.
std::string SwiftExecutablePath;
std::string RuntimeResourcePath;
std::string DiagnosticDocumentationPath;
SourceManager SourceMgr;
Cache<ASTKey, ASTProducerRef> ASTCache{ "sourcekit.swift.ASTCache" };
llvm::sys::Mutex CacheMtx;
@@ -668,10 +666,9 @@ SwiftASTManager::SwiftASTManager(
std::shared_ptr<SwiftStatistics> Stats,
std::shared_ptr<RequestTracker> ReqTracker,
std::shared_ptr<PluginRegistry> Plugins, StringRef SwiftExecutablePath,
StringRef RuntimeResourcePath, StringRef DiagnosticDocumentationPath)
StringRef RuntimeResourcePath)
: Impl(*new Implementation(EditorDocs, Config, Stats, ReqTracker, Plugins,
SwiftExecutablePath, RuntimeResourcePath,
DiagnosticDocumentationPath)) {}
SwiftExecutablePath, RuntimeResourcePath)) {}
SwiftASTManager::~SwiftASTManager() {
delete &Impl;
@@ -710,8 +707,8 @@ bool SwiftASTManager::initCompilerInvocation(
std::string &Error) {
return ide::initCompilerInvocation(
Invocation, OrigArgs, Action, Diags, UnresolvedPrimaryFile, FileSystem,
Impl.SwiftExecutablePath, Impl.RuntimeResourcePath,
Impl.DiagnosticDocumentationPath, Impl.SessionTimestamp, Error);
Impl.SwiftExecutablePath, Impl.RuntimeResourcePath, Impl.SessionTimestamp,
Error);
}
bool SwiftASTManager::initCompilerInvocation(

View File

@@ -259,8 +259,7 @@ public:
std::shared_ptr<RequestTracker> ReqTracker,
std::shared_ptr<swift::PluginRegistry> Plugins,
StringRef SwiftExecutablePath,
StringRef RuntimeResourcePath,
StringRef DiagnosticDocumentationPath);
StringRef RuntimeResourcePath);
~SwiftASTManager();
SwiftInvocationRef getTypecheckInvocation(ArrayRef<const char *> Args,

View File

@@ -31,10 +31,9 @@ compile::SessionManager::getSession(StringRef name) {
}
bool inserted = false;
std::tie(i, inserted) =
sessions.try_emplace(name, std::make_shared<compile::Session>(
SwiftExecutablePath, RuntimeResourcePath,
DiagnosticDocumentationPath, Plugins));
std::tie(i, inserted) = sessions.try_emplace(
name, std::make_shared<compile::Session>(SwiftExecutablePath,
RuntimeResourcePath, Plugins));
assert(inserted);
return i->second;
}

View File

@@ -281,7 +281,6 @@ SwiftLangSupport::SwiftLangSupport(SourceKit::Context &SKCtx)
llvm::SmallString<128> LibPath(SKCtx.getRuntimeLibPath());
llvm::sys::path::append(LibPath, "swift");
RuntimeResourcePath = std::string(LibPath.str());
DiagnosticDocumentationPath = SKCtx.getDiagnosticDocumentationPath().str();
Stats = std::make_shared<SwiftStatistics>();
EditorDocuments = std::make_shared<SwiftEditorDocumentFileMap>();
@@ -290,16 +289,14 @@ SwiftLangSupport::SwiftLangSupport(SourceKit::Context &SKCtx)
ASTMgr = std::make_shared<SwiftASTManager>(
EditorDocuments, SKCtx.getGlobalConfiguration(), Stats, ReqTracker,
Plugins, SwiftExecutablePath, RuntimeResourcePath,
DiagnosticDocumentationPath);
Plugins, SwiftExecutablePath, RuntimeResourcePath);
IDEInspectionInst = std::make_shared<IDEInspectionInstance>(Plugins);
configureIDEInspectionInstance(IDEInspectionInst,
SKCtx.getGlobalConfiguration());
CompileManager = std::make_shared<compile::SessionManager>(
SwiftExecutablePath, RuntimeResourcePath, DiagnosticDocumentationPath,
Plugins);
SwiftExecutablePath, RuntimeResourcePath, Plugins);
// By default, just use the in-memory cache.
CCCache->inMemory = std::make_unique<ide::CodeCompletionCache>();

View File

@@ -283,10 +283,8 @@ class Session {
public:
Session(const std::string &SwiftExecutablePath,
const std::string &RuntimeResourcePath,
const std::string &DiagnosticDocumentationPath,
std::shared_ptr<swift::PluginRegistry> Plugins)
: Compiler(SwiftExecutablePath, RuntimeResourcePath,
DiagnosticDocumentationPath, Plugins) {}
: Compiler(SwiftExecutablePath, RuntimeResourcePath, Plugins) {}
bool
performCompile(llvm::ArrayRef<const char *> Args,
@@ -300,7 +298,6 @@ public:
class SessionManager {
const std::string &SwiftExecutablePath;
const std::string &RuntimeResourcePath;
const std::string &DiagnosticDocumentationPath;
const std::shared_ptr<swift::PluginRegistry> Plugins;
llvm::StringMap<std::shared_ptr<Session>> sessions;
@@ -311,12 +308,9 @@ class SessionManager {
public:
SessionManager(const std::string &SwiftExecutablePath,
const std::string &RuntimeResourcePath,
const std::string &DiagnosticDocumentationPath,
const std::shared_ptr<swift::PluginRegistry> Plugins)
: SwiftExecutablePath(SwiftExecutablePath),
RuntimeResourcePath(RuntimeResourcePath),
DiagnosticDocumentationPath(DiagnosticDocumentationPath),
Plugins(Plugins) {}
RuntimeResourcePath(RuntimeResourcePath), Plugins(Plugins) {}
std::shared_ptr<Session> getSession(StringRef name);
@@ -342,7 +336,6 @@ class SwiftLangSupport : public LangSupport {
/// Used to find clang relative to it.
std::string SwiftExecutablePath;
std::string RuntimeResourcePath;
std::string DiagnosticDocumentationPath;
std::shared_ptr<SwiftASTManager> ASTMgr;
std::shared_ptr<SwiftEditorDocumentFileMap> EditorDocuments;
std::shared_ptr<RequestTracker> ReqTracker;
@@ -366,9 +359,6 @@ public:
}
StringRef getRuntimeResourcePath() const { return RuntimeResourcePath; }
StringRef getDiagnosticDocumentationPath() const {
return DiagnosticDocumentationPath;
}
std::shared_ptr<SwiftASTManager> getASTManager() { return ASTMgr; }

View File

@@ -75,7 +75,6 @@ class Connection {
std::shared_ptr<CodeCompletionCache> completionCache;
std::string swiftExecutablePath;
std::string runtimeResourcePath;
std::string diagnosticsDocumentationPath;
std::shared_ptr<SourceKit::RequestTracker> requestTracker;
public:
@@ -87,7 +86,6 @@ public:
completionCache(std::make_shared<CodeCompletionCache>()),
swiftExecutablePath(getSwiftExecutablePath()),
runtimeResourcePath(getRuntimeResourcesPath()),
diagnosticsDocumentationPath(getDiagnosticDocumentationPath()),
requestTracker(new SourceKit::RequestTracker()),
sessionTimestamp(llvm::sys::toTimeT(std::chrono::system_clock::now())) {
if (ideInspectionInstance == nullptr) {
@@ -371,8 +369,8 @@ void Connection::codeComplete(
std::string compilerInvocationError;
bool creatingInvocationFailed = initCompilerInvocation(
invocation, args, FrontendOptions::ActionType::Typecheck, diags, path,
fileSystem, swiftExecutablePath, runtimeResourcePath,
diagnosticsDocumentationPath, sessionTimestamp, compilerInvocationError);
fileSystem, swiftExecutablePath, runtimeResourcePath, sessionTimestamp,
compilerInvocationError);
if (creatingInvocationFailed) {
callback(ResultType::failure(compilerInvocationError));
return;

View File

@@ -193,7 +193,7 @@ _ZN10sourcekitd13handleRequestEPvPKvNSt3__18functionIFvS0_EEE
_ZN10sourcekitd16requestIsBarrierEPv
_ZN10sourcekitd23requestIsEnableBarriersEPv
_ZN10sourcekitd27sendBarriersEnabledResponseENSt3__18functionIFvPvEEE
_ZN10sourcekitd17initializeServiceEN4llvm9StringRefES1_S1_NSt3__18functionIFvPvEEE
_ZN10sourcekitd17initializeServiceEN4llvm9StringRefES1_NSt3__18functionIFvPvEEE
_ZN10sourcekitd24createErrorRequestFailedEN4llvm9StringRefE
_ZN10sourcekitd24disposeCancellationTokenEPKv
_ZN10sourcekitd11loadPluginsEN4llvm8ArrayRefINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEERNS_16PluginInitParamsE

View File

@@ -98,13 +98,6 @@ std::string sourcekitdInProc::getSwiftExecutablePath() {
return path.str().str();
}
std::string sourcekitdInProc::getDiagnosticDocumentationPath() {
llvm::SmallString<128> docPath;
getToolchainPrefixPath(docPath);
llvm::sys::path::append(docPath, "share", "doc", "swift", "diagnostics");
return docPath.str().str();
}
static std::vector<std::string> registeredPlugins;
void sourcekitd_load_client_plugins(void) {
@@ -117,10 +110,9 @@ void sourcekitd_initialize(void) {
"sourcekitdInProc.msgHandlingQueue");
if (sourcekitd::initializeClient()) {
LOG_INFO_FUNC(High, "initializing");
sourcekitd::initializeService(
sourcekitdInProc::getSwiftExecutablePath(),
sourcekitdInProc::getRuntimeLibPath(),
sourcekitdInProc::getDiagnosticDocumentationPath(), postNotification);
sourcekitd::initializeService(sourcekitdInProc::getSwiftExecutablePath(),
sourcekitdInProc::getRuntimeLibPath(),
postNotification);
static std::once_flag flag;
std::call_once(flag, [] {
sourcekitd::PluginInitParams pluginParams(

View File

@@ -225,13 +225,6 @@ static std::string getSwiftExecutablePath() {
return path.str().str();
}
static std::string getDiagnosticDocumentationPath() {
llvm::SmallString<128> path;
getToolchainPrefixPath(path);
llvm::sys::path::append(path, "share", "doc", "swift", "diagnostics");
return path.str().str();
}
static dispatch_queue_t msgHandlingQueue;
static dispatch_queue_t requestQueue;
@@ -415,7 +408,6 @@ int main(int argc, const char *argv[]) {
return xpcUIdentFromSKDUID(uid).c_str();
});
sourcekitd::initializeService(getSwiftExecutablePath(), getRuntimeLibPath(),
getDiagnosticDocumentationPath(),
postNotification);
// Increase the file descriptor limit.

View File

@@ -27,11 +27,9 @@ using SourceKit::SourceKitCancellationToken;
/// \param swiftExecutablePath The path of the swift-frontend executable.
/// Used to find clang relative to it.
/// \param runtimeLibPath The path to the toolchain's library directory.
/// \param diagnosticDocumentationPath The path to diagnostics documentation.
/// \param postNotification Callback to post a notification.
void initializeService(
llvm::StringRef swiftExecutablePath, llvm::StringRef runtimeLibPath,
llvm::StringRef diagnosticDocumentationPath,
std::function<void(sourcekitd_response_t)> postNotification);
/// Shutdown the service.
void shutdownService();

View File

@@ -18,7 +18,6 @@
namespace sourcekitdInProc {
std::string getRuntimeLibPath();
std::string getSwiftExecutablePath();
std::string getDiagnosticDocumentationPath();
} // namespace sourcekitdInProc
#endif

View File

@@ -162,16 +162,15 @@ static Statistic numSemaRequests(UIdentFromSKDUID(KindStatNumSemaRequests),
void sourcekitd::initializeService(
llvm::StringRef swiftExecutablePath, StringRef runtimeLibPath,
StringRef diagnosticDocumentationPath,
std::function<void(sourcekitd_response_t)> postNotification) {
INITIALIZE_LLVM();
initializeSwiftModules();
llvm::EnablePrettyStackTrace();
GlobalCtx = new SourceKit::Context(
swiftExecutablePath, runtimeLibPath, diagnosticDocumentationPath,
SourceKit::createSwiftLangSupport, [](SourceKit::Context &Ctx) {
return std::make_shared<PluginSupport>();
});
GlobalCtx = new SourceKit::Context(swiftExecutablePath, runtimeLibPath,
SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx) {
return std::make_shared<PluginSupport>();
});
auto noteCenter = GlobalCtx->getNotificationCenter();
noteCenter->addDocumentUpdateNotificationReceiver([postNotification](StringRef DocumentName) {

View File

@@ -82,8 +82,8 @@ public:
INITIALIZE_LLVM();
Ctx = std::make_shared<SourceKit::Context>(
getSwiftExecutablePath(), getRuntimeLibPath(),
/*diagnosticDocumentationPath*/ "", SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx){ return nullptr; },
SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx) { return nullptr; },
/*dispatchOnMain=*/false);
}

View File

@@ -68,12 +68,11 @@ public:
}
CursorInfoTest()
: Ctx(*new SourceKit::Context(getSwiftExecutablePath(),
getRuntimeLibPath(),
/*diagnosticDocumentationPath*/ "",
SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx){ return nullptr; },
/*dispatchOnMain=*/false)) {
: Ctx(*new SourceKit::Context(
getSwiftExecutablePath(), getRuntimeLibPath(),
SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx) { return nullptr; },
/*dispatchOnMain=*/false)) {
INITIALIZE_LLVM();
// This is avoiding destroying \p SourceKit::Context because another
// thread may be active trying to use it to post notifications.

View File

@@ -129,12 +129,11 @@ public:
// This is avoiding destroying \p SourceKit::Context because another
// thread may be active trying to use it to post notifications.
// FIXME: Use shared_ptr ownership to avoid such issues.
Ctx = new SourceKit::Context(getSwiftExecutablePath(),
getRuntimeLibPath(),
/*diagnosticDocumentationPath*/ "",
SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx){ return nullptr; },
/*dispatchOnMain=*/false);
Ctx = new SourceKit::Context(
getSwiftExecutablePath(), getRuntimeLibPath(),
SourceKit::createSwiftLangSupport,
[](SourceKit::Context &Ctx) { return nullptr; },
/*dispatchOnMain=*/false);
auto localDocUpdState = std::make_shared<DocUpdateMutexState>();
Ctx->getNotificationCenter()->addDocumentUpdateNotificationReceiver(
[localDocUpdState](StringRef docName) {