File tree Expand file tree Collapse file tree 12 files changed +335
-189
lines changed
unittests/SourceKit/SwiftLang Expand file tree Collapse file tree 12 files changed +335
-189
lines changed Original file line number Diff line number Diff line change 5
5
key.filepath: rdar_18677108-2-a.swift,
6
6
key.severity: source.diagnostic.severity.error,
7
7
key.description: "expected ')' in expression list",
8
- key.diagnostic_stage: source.diagnostic.stage.swift.parse ,
8
+ key.diagnostic_stage: source.diagnostic.stage.swift.sema ,
9
9
key.diagnostics: [
10
10
{
11
11
key.line: 5,
22
22
key.filepath: rdar_18677108-2-a.swift,
23
23
key.severity: source.diagnostic.severity.error,
24
24
key.description: "expected '}' at end of brace statement",
25
- key.diagnostic_stage: source.diagnostic.stage.swift.parse ,
25
+ key.diagnostic_stage: source.diagnostic.stage.swift.sema ,
26
26
key.diagnostics: [
27
27
{
28
28
key.line: 4,
39
39
key.filepath: rdar_18677108-2-a.swift,
40
40
key.severity: source.diagnostic.severity.error,
41
41
key.description: "expected '}' in class",
42
- key.diagnostic_stage: source.diagnostic.stage.swift.parse ,
42
+ key.diagnostic_stage: source.diagnostic.stage.swift.sema ,
43
43
key.diagnostics: [
44
44
{
45
45
key.line: 2,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ let a = 0; let b = 0 }; unresolved
4
4
// Test that offsets of diagnostic ranges and fixits get updated correctly after the edit request
5
5
6
6
// RUN: %sourcekitd-test -req=open %s -- %s == -req=print-diags %s \
7
- // RUN: == -req=edit -pos=2:1 -replace="_" -length=5 %s - print-raw-response \
7
+ // RUN: == -req=edit -pos=2:1 -replace="_" -length=5 %s == -req= print-diags %s \
8
8
// RUN: | %FileCheck %s
9
9
10
10
// CHECK: key.line: 2,
Original file line number Diff line number Diff line change 12
12
key.filepath: sema_playground.swift,
13
13
key.severity: source.diagnostic.severity.error,
14
14
key.description: "expected numeric value following '$'",
15
- key.diagnostic_stage: source.diagnostic.stage.swift.parse
15
+ key.diagnostic_stage: source.diagnostic.stage.swift.sema
16
16
}
17
17
]
Original file line number Diff line number Diff line change 6
6
key.filepath: parse_error.swift,
7
7
key.severity: source.diagnostic.severity.error,
8
8
key.description: "expected '(' in argument list of function declaration",
9
- key.diagnostic_stage: source.diagnostic.stage.swift.parse ,
9
+ key.diagnostic_stage: source.diagnostic.stage.swift.sema ,
10
10
key.fixits: [
11
11
{
12
12
key.offset: 26,
37
37
key.filepath: parse_error.swift,
38
38
key.severity: source.diagnostic.severity.error,
39
39
key.description: "expected '(' in argument list of function declaration",
40
- key.diagnostic_stage: source.diagnostic.stage.swift.parse ,
40
+ key.diagnostic_stage: source.diagnostic.stage.swift.sema ,
41
41
key.fixits: [
42
42
{
43
43
key.offset: 29,
Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ class Context {
35
35
public:
36
36
Context (StringRef RuntimeLibPath,
37
37
llvm::function_ref<
38
- std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn);
38
+ std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn,
39
+ bool shouldDispatchNotificationsOnMain = true );
39
40
~Context ();
40
41
41
42
StringRef getRuntimeLibPath () const { return RuntimeLibPath; }
Original file line number Diff line number Diff line change 14
14
#define LLVM_SOURCEKIT_CORE_NOTIFICATIONCENTER_H
15
15
16
16
#include " SourceKit/Core/LLVM.h"
17
+ #include " llvm/Support/Mutex.h"
17
18
#include < functional>
18
19
#include < vector>
19
20
@@ -23,9 +24,14 @@ typedef std::function<void(StringRef DocumentName)>
23
24
DocumentUpdateNotificationReceiver;
24
25
25
26
class NotificationCenter {
27
+ bool DispatchToMain;
26
28
std::vector<DocumentUpdateNotificationReceiver> DocUpdReceivers;
29
+ mutable llvm::sys::Mutex Mtx;
27
30
28
31
public:
32
+ explicit NotificationCenter (bool dispatchToMain);
33
+ ~NotificationCenter ();
34
+
29
35
void addDocumentUpdateNotificationReceiver (
30
36
DocumentUpdateNotificationReceiver Receiver);
31
37
Original file line number Diff line number Diff line change @@ -18,8 +18,9 @@ using namespace SourceKit;
18
18
19
19
SourceKit::Context::Context (StringRef RuntimeLibPath,
20
20
llvm::function_ref<std::unique_ptr<LangSupport>(Context &)>
21
- LangSupportFactoryFn) : RuntimeLibPath(RuntimeLibPath),
22
- NotificationCtr(new NotificationCenter()) {
21
+ LangSupportFactoryFn,
22
+ bool shouldDispatchNotificationsOnMain) : RuntimeLibPath(RuntimeLibPath),
23
+ NotificationCtr(new NotificationCenter(shouldDispatchNotificationsOnMain)) {
23
24
// Should be called last after everything is initialized.
24
25
SwiftLang = LangSupportFactoryFn (*this );
25
26
}
Original file line number Diff line number Diff line change 15
15
16
16
using namespace SourceKit ;
17
17
18
+ NotificationCenter::NotificationCenter (bool dispatchToMain)
19
+ : DispatchToMain(dispatchToMain) {
20
+ }
21
+ NotificationCenter::~NotificationCenter () {}
22
+
18
23
void NotificationCenter::addDocumentUpdateNotificationReceiver (
19
24
DocumentUpdateNotificationReceiver Receiver) {
20
25
21
- WorkQueue::dispatchOnMain ([this , Receiver]{
22
- DocUpdReceivers.push_back (Receiver);
23
- });
26
+ llvm::sys::ScopedLock L (Mtx);
27
+ DocUpdReceivers.push_back (Receiver);
24
28
}
25
29
26
30
void NotificationCenter::postDocumentUpdateNotification (
27
31
StringRef DocumentName) const {
28
-
29
- std::string DocName = DocumentName;
30
- WorkQueue::dispatchOnMain ([this , DocName]{
31
- for (auto &Fn : DocUpdReceivers)
32
- Fn (DocName);
33
- });
32
+
33
+ std::vector<DocumentUpdateNotificationReceiver> recvs;
34
+ {
35
+ llvm::sys::ScopedLock L (Mtx);
36
+ recvs = DocUpdReceivers;
37
+ }
38
+ std::string docName = DocumentName;
39
+ auto sendNote = [recvs, docName]{
40
+ for (auto &Fn : recvs)
41
+ Fn (docName);
42
+ };
43
+ if (DispatchToMain)
44
+ WorkQueue::dispatchOnMain (sendNote);
45
+ else
46
+ sendNote ();
34
47
}
You can’t perform that action at this time.
0 commit comments