Skip to content

Commit fac7440

Browse files
committed
[SourceKit] Remove dependency of SwiftLang on Core
1 parent 67edb44 commit fac7440

File tree

8 files changed

+43
-10
lines changed

8 files changed

+43
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "SourceKit/Core/LLVM.h"
1717
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/ADT/STLExtras.h"
1819
#include <memory>
1920
#include <string>
2021

@@ -32,7 +33,9 @@ class Context {
3233
std::unique_ptr<NotificationCenter> NotificationCtr;
3334

3435
public:
35-
explicit Context(StringRef RuntimeLibPath);
36+
Context(StringRef RuntimeLibPath,
37+
llvm::function_ref<
38+
std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn);
3639
~Context();
3740

3841
StringRef getRuntimeLibPath() const { return RuntimeLibPath; }

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace llvm {
2727
class MemoryBuffer;
2828
}
2929
namespace SourceKit {
30-
class Context;
3130

3231
struct EntityInfo {
3332
UIdent Kind;
@@ -472,9 +471,6 @@ class LangSupport {
472471
StringRef ModuleName,
473472
ArrayRef<const char *> Args,
474473
DocInfoConsumer &Consumer) = 0;
475-
476-
static std::unique_ptr<LangSupport> createSwiftLangSupport(
477-
SourceKit::Context &SKCtx);
478474
};
479475

480476
} // namespace SourceKit
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===--- Factory.h - --------------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_SOURCEKIT_SWIFTLANG_FACTORY_H
14+
#define LLVM_SOURCEKIT_SWIFTLANG_FACTORY_H
15+
16+
#include <memory>
17+
18+
namespace SourceKit {
19+
class LangSupport;
20+
class Context;
21+
22+
std::unique_ptr<LangSupport> createSwiftLangSupport(Context &SKCtx);
23+
24+
}
25+
26+
#endif

tools/SourceKit/lib/Core/Context.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
using namespace SourceKit;
1818

19-
SourceKit::Context::Context(StringRef RuntimeLibPath)
19+
SourceKit::Context::Context(StringRef RuntimeLibPath,
20+
llvm::function_ref<
21+
std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn)
2022
: RuntimeLibPath(RuntimeLibPath),
21-
SwiftLang(LangSupport::createSwiftLangSupport(*this)),
2223
NotificationCtr(new NotificationCenter()) {
24+
// Should be called last after everything is initialized.
25+
SwiftLang = LangSupportFactoryFn(*this);
2326
}
2427

2528
SourceKit::Context::~Context() {

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "SwiftLangSupport.h"
1414
#include "SwiftASTManager.h"
1515
#include "SourceKit/Core/Context.h"
16+
#include "SourceKit/SwiftLang/Factory.h"
1617
#include "SourceKit/Support/UIdent.h"
1718

1819
#include "swift/AST/AST.h"
@@ -151,7 +152,7 @@ static UIdent KindStructureElemTypeRef("source.lang.swift.structure.elem.typeref
151152

152153

153154
std::unique_ptr<LangSupport>
154-
LangSupport::createSwiftLangSupport(SourceKit::Context &SKCtx) {
155+
SourceKit::createSwiftLangSupport(SourceKit::Context &SKCtx) {
155156
return std::unique_ptr<LangSupport>(new SwiftLangSupport(SKCtx));
156157
}
157158

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace SourceKit {
5555
typedef RefPtr<ImmutableTextSnapshot> ImmutableTextSnapshotRef;
5656
class SwiftASTManager;
5757
class SwiftLangSupport;
58+
class Context;
5859

5960
class SwiftEditorDocument :
6061
public ThreadSafeRefCountedBase<SwiftEditorDocument> {

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "SourceKit/Support/Concurrency.h"
2222
#include "SourceKit/Support/Logging.h"
2323
#include "SourceKit/Support/UIdent.h"
24+
#include "SourceKit/SwiftLang/Factory.h"
2425

2526
#include "swift/Basic/DemangleWrappers.h"
2627

@@ -132,7 +133,8 @@ static void onDocumentUpdateNotification(StringRef DocumentName) {
132133
static SourceKit::Context *GlobalCtx = nullptr;
133134

134135
void sourcekitd::initialize() {
135-
GlobalCtx = new SourceKit::Context(sourcekitd::getRuntimeLibPath());
136+
GlobalCtx = new SourceKit::Context(sourcekitd::getRuntimeLibPath(),
137+
SourceKit::createSwiftLangSupport);
136138
GlobalCtx->getNotificationCenter().addDocumentUpdateNotificationReceiver(
137139
onDocumentUpdateNotification);
138140
}

unittests/SourceKit/SwiftLang/CursorInfoTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "SourceKit/Core/LangSupport.h"
1515
#include "SourceKit/Core/NotificationCenter.h"
1616
#include "SourceKit/Support/Concurrency.h"
17+
#include "SourceKit/SwiftLang/Factory.h"
1718
#include "llvm/Support/MemoryBuffer.h"
1819
#include "llvm/Support/Path.h"
1920
#include "gtest/gtest.h"
@@ -94,7 +95,7 @@ struct TestCursorInfo {
9495
};
9596

9697
class CursorInfoTest : public ::testing::Test {
97-
SourceKit::Context Ctx{ getRuntimeLibPath() };
98+
SourceKit::Context Ctx{ getRuntimeLibPath(), SourceKit::createSwiftLangSupport };
9899
std::atomic<int> NumTasks;
99100

100101
public:

0 commit comments

Comments
 (0)