Skip to content

Commit debeebb

Browse files
committed
[SourceKit] Don't build an AST if no semantic info is requested
Currently, we were building an AST on document open or edit even if - `key_enablesyntaxmap` = 0 - `key_enablesubstructure` = 0 - `key_enablediagnostics` = 0 and - syntax tree transfer mode is off In those cases we were just ignoring the result. If all of the options are 0, don’t build an AST. rdar://85847659
1 parent 3b4d131 commit debeebb

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

test/SourceKit/CodeExpand/code-expand-rdar77665805.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func test() {
66

77
// RUN: %sourcekitd-test \
88
// RUN: -req=open %s -- %s == \
9-
// RUN: -req=edit -offset=0 -length=53 -replace="" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %s -- %s == \
9+
// RUN: -req=edit -offset=0 -length=53 -replace="" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 -dont-print-response %s -- %s == \
1010
// RUN: -req=expand-placeholder -offset=23 -length=18 %s \
1111
// RUN: | %FileCheck %s
1212

test/SourceKit/CursorInfo/cursor_after_edit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
// buffer to calculate line and column (before rdar://78161348).
88
// RUN: %sourcekitd-test \
99
// RUN: -req=open -text-input %t/empty.swift %t/func.swift -- %t/func.swift == \
10-
// RUN: -req=edit -offset=0 -length=0 -replace="func foo() {}" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/func.swift -- %t/func.swift == \
10+
// RUN: -req=edit -offset=0 -length=0 -replace="func foo() {}" -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 -dont-print-response %t/func.swift -- %t/func.swift == \
1111
// RUN: -req=cursor -offset=5 %t/func.swift -- %t/func.swift

test/SourceKit/Sema/edit_nowait.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
// EDIT_NOWAIT-NEXT: }
1616

1717
// RUN: %sourcekitd-test \
18-
// RUN: -req=open -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift -- %t/t.swift == \
18+
// RUN: -req=open -req-opts=enablesyntaxmap=0,enablesubstructure=1,enablediagnostics=0 %t/t.swift -- %t/t.swift == \
1919
// 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 == \
21-
// RUN: -req=edit -offset=13 -replace="print" -length=4 -req-opts=enablesyntaxmap=0,enablesubstructure=0,enablediagnostics=0 %t/t.swift == \
20+
// RUN: -req=edit -offset=0 -replace="func foo() { warn("") }" -length=16 -req-opts=enablesyntaxmap=0,enablesubstructure=1,enablediagnostics=0 %t/t.swift == \
21+
// RUN: -req=edit -offset=13 -replace="print" -length=4 -req-opts=enablesyntaxmap=0,enablesubstructure=1,enablediagnostics=0 %t/t.swift == \
2222
// RUN: -req=print-annotations %t/t.swift \
2323
// RUN: | %FileCheck --check-prefix=ANNOTATION %s
2424

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,18 @@ class SKEditorConsumer : public EditorConsumer {
26632663
sourcekitd_response_t createResponse();
26642664

26652665
bool needsSemanticInfo() override {
2666-
return !Opts.SyntacticOnly && !isSemanticEditorDisabled();
2666+
if (Opts.SyntacticOnly) {
2667+
return false;
2668+
} else if (isSemanticEditorDisabled()) {
2669+
return false;
2670+
} else if (!documentStructureEnabled() &&
2671+
!syntaxMapEnabled() &&
2672+
!diagnosticsEnabled() &&
2673+
!syntaxTreeEnabled()) {
2674+
return false;
2675+
} else {
2676+
return true;
2677+
}
26672678
}
26682679

26692680
void handleRequestError(const char *Description) override;

0 commit comments

Comments
 (0)