File tree Expand file tree Collapse file tree 8 files changed +43
-10
lines changed
unittests/SourceKit/SwiftLang Expand file tree Collapse file tree 8 files changed +43
-10
lines changed Original file line number Diff line number Diff line change 15
15
16
16
#include " SourceKit/Core/LLVM.h"
17
17
#include " llvm/ADT/StringRef.h"
18
+ #include " llvm/ADT/STLExtras.h"
18
19
#include < memory>
19
20
#include < string>
20
21
@@ -32,7 +33,9 @@ class Context {
32
33
std::unique_ptr<NotificationCenter> NotificationCtr;
33
34
34
35
public:
35
- explicit Context (StringRef RuntimeLibPath);
36
+ Context (StringRef RuntimeLibPath,
37
+ llvm::function_ref<
38
+ std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn);
36
39
~Context ();
37
40
38
41
StringRef getRuntimeLibPath () const { return RuntimeLibPath; }
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ namespace llvm {
27
27
class MemoryBuffer ;
28
28
}
29
29
namespace SourceKit {
30
- class Context ;
31
30
32
31
struct EntityInfo {
33
32
UIdent Kind;
@@ -472,9 +471,6 @@ class LangSupport {
472
471
StringRef ModuleName,
473
472
ArrayRef<const char *> Args,
474
473
DocInfoConsumer &Consumer) = 0;
475
-
476
- static std::unique_ptr<LangSupport> createSwiftLangSupport (
477
- SourceKit::Context &SKCtx);
478
474
};
479
475
480
476
} // namespace SourceKit
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 16
16
17
17
using namespace SourceKit ;
18
18
19
- SourceKit::Context::Context (StringRef RuntimeLibPath)
19
+ SourceKit::Context::Context (StringRef RuntimeLibPath,
20
+ llvm::function_ref<
21
+ std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn)
20
22
: RuntimeLibPath(RuntimeLibPath),
21
- SwiftLang(LangSupport::createSwiftLangSupport(*this )),
22
23
NotificationCtr(new NotificationCenter()) {
24
+ // Should be called last after everything is initialized.
25
+ SwiftLang = LangSupportFactoryFn (*this );
23
26
}
24
27
25
28
SourceKit::Context::~Context () {
Original file line number Diff line number Diff line change 13
13
#include " SwiftLangSupport.h"
14
14
#include " SwiftASTManager.h"
15
15
#include " SourceKit/Core/Context.h"
16
+ #include " SourceKit/SwiftLang/Factory.h"
16
17
#include " SourceKit/Support/UIdent.h"
17
18
18
19
#include " swift/AST/AST.h"
@@ -151,7 +152,7 @@ static UIdent KindStructureElemTypeRef("source.lang.swift.structure.elem.typeref
151
152
152
153
153
154
std::unique_ptr<LangSupport>
154
- LangSupport ::createSwiftLangSupport (SourceKit::Context &SKCtx) {
155
+ SourceKit ::createSwiftLangSupport (SourceKit::Context &SKCtx) {
155
156
return std::unique_ptr<LangSupport>(new SwiftLangSupport (SKCtx));
156
157
}
157
158
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ namespace SourceKit {
55
55
typedef RefPtr<ImmutableTextSnapshot> ImmutableTextSnapshotRef;
56
56
class SwiftASTManager ;
57
57
class SwiftLangSupport ;
58
+ class Context ;
58
59
59
60
class SwiftEditorDocument :
60
61
public ThreadSafeRefCountedBase<SwiftEditorDocument> {
Original file line number Diff line number Diff line change 21
21
#include " SourceKit/Support/Concurrency.h"
22
22
#include " SourceKit/Support/Logging.h"
23
23
#include " SourceKit/Support/UIdent.h"
24
+ #include " SourceKit/SwiftLang/Factory.h"
24
25
25
26
#include " swift/Basic/DemangleWrappers.h"
26
27
@@ -132,7 +133,8 @@ static void onDocumentUpdateNotification(StringRef DocumentName) {
132
133
static SourceKit::Context *GlobalCtx = nullptr ;
133
134
134
135
void sourcekitd::initialize () {
135
- GlobalCtx = new SourceKit::Context (sourcekitd::getRuntimeLibPath ());
136
+ GlobalCtx = new SourceKit::Context (sourcekitd::getRuntimeLibPath (),
137
+ SourceKit::createSwiftLangSupport);
136
138
GlobalCtx->getNotificationCenter ().addDocumentUpdateNotificationReceiver (
137
139
onDocumentUpdateNotification);
138
140
}
Original file line number Diff line number Diff line change 14
14
#include " SourceKit/Core/LangSupport.h"
15
15
#include " SourceKit/Core/NotificationCenter.h"
16
16
#include " SourceKit/Support/Concurrency.h"
17
+ #include " SourceKit/SwiftLang/Factory.h"
17
18
#include " llvm/Support/MemoryBuffer.h"
18
19
#include " llvm/Support/Path.h"
19
20
#include " gtest/gtest.h"
@@ -94,7 +95,7 @@ struct TestCursorInfo {
94
95
};
95
96
96
97
class CursorInfoTest : public ::testing::Test {
97
- SourceKit::Context Ctx{ getRuntimeLibPath () };
98
+ SourceKit::Context Ctx{ getRuntimeLibPath (), SourceKit::createSwiftLangSupport };
98
99
std::atomic<int > NumTasks;
99
100
100
101
public:
You can’t perform that action at this time.
0 commit comments