Skip to content

Commit 01dd5a5

Browse files
authored
Merge pull request swiftlang#37574 from rintaro/sourcekit-open-noop-rdar77693214
[SourceKit] Avoid unnecessary parsing in 'open' request
2 parents 53c1e15 + 4bf9682 commit 01dd5a5

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

test/SourceKit/Sema/edit_nowait.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: echo "" > %t/t.swift
2+
// RUN: echo "func f() { f() }" > %t/t.swift
33

44
// RUN: %sourcekitd-test \
5-
// RUN: -req=open %t/t.swift -- %t/t.swift == \
6-
// RUN: -req=edit -offset=0 -replace="func foo() { warn("") }" -length=0 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift -print-raw-response == \
5+
// RUN: -req=open -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift -print-raw-response -- %t/t.swift == \
6+
// RUN: -req=edit -offset=0 -replace="func foo() { warn("") }" -length=16 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift -print-raw-response == \
77
// RUN: -req=edit -offset=13 -replace="print" -length=5 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift -print-raw-response \
88
// RUN: | %FileCheck --check-prefix=EDIT_NOWAIT %s
99

1010
// EDIT_NOWAIT: {
1111
// EDIT_NOWAIT-NEXT: }
1212
// EDIT_NOWAIT-NEXT: {
1313
// EDIT_NOWAIT-NEXT: }
14+
// EDIT_NOWAIT-NEXT: {
15+
// EDIT_NOWAIT-NEXT: }
1416

1517
// RUN: %sourcekitd-test \
16-
// RUN: %sourcekitd-test \
17-
// RUN: -req=open %t/t.swift -- %t/t.swift == \
18-
// RUN: -req=edit -offset=0 -replace="func foo() { warn("") }" -length=0 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift == \
18+
// RUN: -req=open -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift -- %t/t.swift == \
19+
// RUN: -req=print-annotations %t/t.swift == \
20+
// RUN: -req=edit -offset=0 -replace="func foo() { warn("") }" -length=16 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift == \
1921
// RUN: -req=edit -offset=13 -replace="print" -length=4 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift == \
20-
// RUN: -req=print-annotations %s \
22+
// RUN: -req=print-annotations %t/t.swift \
2123
// RUN: | %FileCheck --check-prefix=ANNOTATION %s
2224

23-
// ANNOTATION: [
25+
// ANNOTATION-LABEL: [
26+
// ANNOTATION-NEXT: {
27+
// ANNOTATION-NEXT: key.kind: source.lang.swift.ref.function.free,
28+
// ANNOTATION-NEXT: key.offset: 11,
29+
// ANNOTATION-NEXT: key.length: 1
30+
// ANNOTATION-NEXT: }
31+
// ANNOTATION-NEXT: ]
32+
33+
// ANNOTATION-LABEL: [
2434
// ANNOTATION-NEXT: {
2535
// ANNOTATION-NEXT: key.kind: source.lang.swift.ref.function.free,
2636
// ANNOTATION-NEXT: key.offset: 13,

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,13 @@ void SwiftLangSupport::editorOpen(
23582358
EditorDoc->updateSemaInfo();
23592359
}
23602360

2361+
if (!Consumer.documentStructureEnabled() &&
2362+
!Consumer.syntaxMapEnabled() &&
2363+
!Consumer.diagnosticsEnabled() &&
2364+
!Consumer.syntaxTreeEnabled()) {
2365+
return;
2366+
}
2367+
23612368
EditorDoc->readSyntaxInfo(Consumer, /*ReportDiags=*/true);
23622369

23632370
if (Consumer.syntaxTreeEnabled()) {

0 commit comments

Comments
 (0)