Skip to content

Commit b6c94ae

Browse files
committed
[SourceKit] Add mechanism to load plugins for request handling into SourceKit
This allows us to load plugins into the sourcekitd service to handle requests (currently only used for code completion). This allows us to implement parts of sourcekitd in Swift and outside of the compiler repository, making it easier to iterated on them because the compiler doesn’t need to be rebuilt.
1 parent ed2f43e commit b6c94ae

37 files changed

+3100
-142
lines changed

tools/SourceKit/include/SourceKit/Core/Context.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace llvm {
3131
namespace SourceKit {
3232
class LangSupport;
3333
class NotificationCenter;
34+
class PluginSupport;
3435

3536
class GlobalConfig {
3637
public:
@@ -169,13 +170,16 @@ class Context {
169170
std::shared_ptr<NotificationCenter> NotificationCtr;
170171
std::shared_ptr<GlobalConfig> Config;
171172
std::shared_ptr<RequestTracker> ReqTracker;
173+
std::shared_ptr<PluginSupport> Plugins;
172174
std::shared_ptr<SlowRequestSimulator> SlowRequestSim;
173175

174176
public:
175177
Context(StringRef SwiftExecutablePath, StringRef RuntimeLibPath,
176178
StringRef DiagnosticDocumentationPath,
177179
llvm::function_ref<std::unique_ptr<LangSupport>(Context &)>
178180
LangSupportFactoryFn,
181+
llvm::function_ref<std::shared_ptr<PluginSupport>(Context &)>
182+
PluginSupportFactoryFn,
179183
bool shouldDispatchNotificationsOnMain = true);
180184
~Context();
181185

@@ -192,6 +196,8 @@ class Context {
192196

193197
std::shared_ptr<GlobalConfig> getGlobalConfiguration() { return Config; }
194198

199+
std::shared_ptr<PluginSupport> getPlugins() { return Plugins; }
200+
195201
std::shared_ptr<SlowRequestSimulator> getSlowRequestSimulator() {
196202
return SlowRequestSim;
197203
}

tools/SourceKit/include/SourceKit/Core/LangSupport.h

+2
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ class LangSupport {
10241024

10251025
virtual ~LangSupport() { }
10261026

1027+
virtual void *getOpaqueSwiftIDEInspectionInstance() { return nullptr; }
1028+
10271029
virtual void globalConfigurationUpdated(std::shared_ptr<GlobalConfig> Config) {};
10281030

10291031
virtual void dependencyUpdated() {}

tools/SourceKit/lib/Core/Context.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ SourceKit::Context::Context(
4040
StringRef DiagnosticDocumentationPath,
4141
llvm::function_ref<std::unique_ptr<LangSupport>(Context &)>
4242
LangSupportFactoryFn,
43+
llvm::function_ref<std::shared_ptr<PluginSupport>(Context &)>
44+
PluginSupportFactoryFn,
4345
bool shouldDispatchNotificationsOnMain)
4446
: SwiftExecutablePath(SwiftExecutablePath), RuntimeLibPath(RuntimeLibPath),
4547
DiagnosticDocumentationPath(DiagnosticDocumentationPath),
@@ -49,6 +51,7 @@ SourceKit::Context::Context(
4951
SlowRequestSim(new SlowRequestSimulator(ReqTracker)) {
5052
// Should be called last after everything is initialized.
5153
SwiftLang = LangSupportFactoryFn(*this);
54+
Plugins = PluginSupportFactoryFn(*this);
5255
}
5356

5457
SourceKit::Context::~Context() {

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

+4
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ class SwiftLangSupport : public LangSupport {
534534
// LangSupport Interface
535535
//==========================================================================//
536536

537+
void *getOpaqueSwiftIDEInspectionInstance() override {
538+
return IDEInspectionInst.get();
539+
}
540+
537541
void globalConfigurationUpdated(std::shared_ptr<GlobalConfig> Config) override;
538542

539543
void dependencyUpdated() override;

tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ swift_is_installing_component(sourcekit-inproc SOURCEKIT_INSTALLING_INPROC)
1111

1212
set(sourcekitdInProc_args
1313
sourcekitdInProc.cpp
14+
CodeCompletionSwiftInterop.cpp
1415
LLVM_LINK_COMPONENTS support coverage
1516
)
1617

1718
if (SOURCEKIT_INSTALLING_INPROC)
1819
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
1920
add_sourcekit_framework(sourcekitdInProc
2021
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/sourcekitd.h
22+
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/plugin.h
23+
${CMAKE_CURRENT_SOURCE_DIR}/CodeCompletionSwiftInterop.h
2124
${sourcekitdInProc_args}
2225
MODULEMAP module.modulemap
2326
INSTALL_IN_COMPONENT sourcekit-inproc

0 commit comments

Comments
 (0)