Skip to content

Commit eabb561

Browse files
author
Nathan Hawes
committed
[code-completion] Give Modules a SemanticContextKind of None
This seems more correct than OtherModule, and means they're treated as low-priority results for the session-based completion APIs. With default options that means won't be shown in global completion results but will be once there's some matching filter text. It also sorts them below any symbols that actually come from other modules, which is desirable, since most symbols don't need to be module qualified. The SemanticContextKind change doesn't seem to affect Xcode's handling of the results.
1 parent b871454 commit eabb561

File tree

7 files changed

+23
-25
lines changed

7 files changed

+23
-25
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17281728
CodeCompletionResultBuilder Builder(Sink,
17291729
CodeCompletionResult::ResultKind::
17301730
Declaration,
1731-
SemanticContextKind::OtherModule,
1731+
SemanticContextKind::None,
17321732
expectedTypeContext);
17331733
auto MD = ModuleDecl::create(Ctx.getIdentifier(Pair.first), Ctx);
17341734
Builder.setAssociatedDecl(MD);
@@ -1771,7 +1771,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17711771
CodeCompletionResultBuilder Builder(
17721772
Sink,
17731773
CodeCompletionResult::ResultKind::Declaration,
1774-
SemanticContextKind::OtherModule,
1774+
SemanticContextKind::None,
17751775
expectedTypeContext);
17761776
Builder.setAssociatedDecl(MD);
17771777
Builder.addTextChunk(MD->getNameStr());

test/IDE/complete_from_clang_framework.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,10 @@ func testCompleteInstanceMembers1(fooObject: FooClassDerived) {
340340
func testExportedModuleCompletion() -> #^TYPE_MODULE_QUALIFIER^# {
341341
let x = #^EXPR_MODULE_QUALIFIER^#
342342
// MODULE_QUALIFIER: Begin completions
343-
// MODULE_QUALIFIER-DAG: Decl[Module]/OtherModule[swift_ide_test]: swift_ide_test[#Module#]; name=swift_ide_test
344-
// MODULE_QUALIFIER-DAG: Decl[Module]/OtherModule[Swift]: Swift[#Module#]; name=Swift
345-
// MODULE_QUALIFIER-DAG: Decl[Module]/OtherModule[Foo]: Foo[#Module#]; name=Foo
346-
// MODULE_QUALIFIER-DAG: Decl[Module]/OtherModule[FooHelper]: FooHelper[#Module#]; name=FooHelper
347-
// MODULE_QUALIFIER-DAG: Decl[Module]/OtherModule[Bar]: Bar[#Module#]; name=Bar
343+
// MODULE_QUALIFIER-DAG: Decl[Module]/None: swift_ide_test[#Module#]; name=swift_ide_test
344+
// MODULE_QUALIFIER-DAG: Decl[Module]/None: Swift[#Module#]; name=Swift
345+
// MODULE_QUALIFIER-DAG: Decl[Module]/None: Foo[#Module#]; name=Foo
346+
// MODULE_QUALIFIER-DAG: Decl[Module]/None: FooHelper[#Module#]; name=FooHelper
347+
// MODULE_QUALIFIER-DAG: Decl[Module]/None: Bar[#Module#]; name=Bar
348348
// MODULE_QUALIFIER: End completions
349349
}

test/IDE/complete_from_swift_module.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ import corrupted_module
6262
func testQualifyingModulesSuggested() -> #^QUALIFYING_MODULE^# {
6363
let x = #^QUALIFYING_MODULE_2^#
6464
// QUALIFYING_MODULE: Begin completions
65-
// QUALIFYING_MODULE-DAG: Decl[Module]/OtherModule[swift_ide_test]: swift_ide_test[#Module#]; name=swift_ide_test
66-
// QUALIFYING_MODULE-DAG: Decl[Module]/OtherModule[Swift]: Swift[#Module#]; name=Swift
67-
// QUALIFYING_MODULE-DAG: Decl[Module]/OtherModule[foo_swift_module]: foo_swift_module[#Module#]; name=foo_swift_module
65+
// QUALIFYING_MODULE-DAG: Decl[Module]/None: swift_ide_test[#Module#]; name=swift_ide_test
66+
// QUALIFYING_MODULE-DAG: Decl[Module]/None: Swift[#Module#]; name=Swift
67+
// QUALIFYING_MODULE-DAG: Decl[Module]/None: foo_swift_module[#Module#]; name=foo_swift_module
6868
// QUALIFYING_MODULE: End completions
6969
}
7070

test/IDE/complete_import.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@
1212
import #^CLANG_IMPORT1^#
1313

1414
// CLANG_IMPORT1: Begin completions
15-
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[Foo]: Foo[#Module#]; name=Foo
16-
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[FooHelper]: FooHelper[#Module#]; name=FooHelper
17-
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[Bar]: Bar[#Module#]; name=Bar
15+
// CLANG_IMPORT1-DAG: Decl[Module]/None: Foo[#Module#]; name=Foo
16+
// CLANG_IMPORT1-DAG: Decl[Module]/None: FooHelper[#Module#]; name=FooHelper
17+
// CLANG_IMPORT1-DAG: Decl[Module]/None: Bar[#Module#]; name=Bar
1818
// CLANG_IMPORT1-NOT: SwiftShims
1919

2020
import Foo
2121

2222
import #^CLANG_IMPORT2^#
2323

2424
// CLANG_IMPORT2: Begin completions
25-
// CLANG_IMPORT2-DAG: Decl[Module]/OtherModule[Foo]/NotRecommended: Foo[#Module#]; name=Foo
26-
// CLANG_IMPORT2-DAG: Decl[Module]/OtherModule[FooHelper]/NotRecommended: FooHelper[#Module#]; name=FooHelper
27-
// CLANG_IMPORT2-DAG: Decl[Module]/OtherModule[Bar]: Bar[#Module#]; name=Bar
28-
// CLANG_IMPORT2-NOT: SwiftShims
25+
// CLANG_IMPORT2-DAG: Decl[Module]/None/NotRecommended: Foo[#Module#]; name=Foo
26+
// CLANG_IMPORT2-DAG: Decl[Module]/None/NotRecommended: FooHelper[#Module#]; name=FooHelper
27+
// CLANG_IMPORT2-DAG: Decl[Module]/None: Bar[#Module#]; name=Bar
28+
// CLANG_IMPORT2-NOT: SwiftShims
2929

3030
import Foo.#^CLANG_IMPORT3^#
3131

3232
// CLANG_IMPORT3: Begin completions
33-
// CLANG_IMPORT3-NEXT: Decl[Module]/OtherModule[FooSub]: FooSub[#Module#]; name=FooSub
33+
// CLANG_IMPORT3-NEXT: Decl[Module]/None: FooSub[#Module#]; name=FooSub
3434

3535
import Foo.FooSub
3636

3737
import Foo.#^CLANG_IMPORT8^#
3838

3939
// FIXME: This should be marked as not recommended, holding for Swift's submodules support.
4040
// CLANG_IMPORT8: Begin completions
41-
// CLANG_IMPORT8-NEXT: Decl[Module]/OtherModule[FooSub]: FooSub[#Module#]; name=FooSub
41+
// CLANG_IMPORT8-NEXT: Decl[Module]/None: FooSub[#Module#]; name=FooSub
4242

4343
import Foo#^CLANG_IMPORT4^#
4444
// CLANG_IMPORT4-NOT: Begin completions

test/IDE/complete_import_multifile1.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import #^CLANG_IMPORT1^#
66

77
// CLANG_IMPORT1: Begin completions
8-
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[Foo]: Foo[#Module#]; name=Foo
9-
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[FooHelper]: FooHelper[#Module#]; name=FooHelper
10-
// CLANG_IMPORT1-DAG: Decl[Module]/OtherModule[Bar]: Bar[#Module#]; name=Bar
8+
// CLANG_IMPORT1-DAG: Decl[Module]/None: Foo[#Module#]; name=Foo
9+
// CLANG_IMPORT1-DAG: Decl[Module]/None: FooHelper[#Module#]; name=FooHelper
10+
// CLANG_IMPORT1-DAG: Decl[Module]/None: Bar[#Module#]; name=Bar
1111
// CLANG_IMPORT1-NOT: SwiftShims

test/SourceKit/CodeComplete/complete_requestlimit.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func test001() {
3232
// TOP_LEVEL_0_ALL-NEXT: z
3333
// TOP_LEVEL_0_ALL-NEXT: A
3434
// TOP_LEVEL_0_ALL-NEXT: B
35-
// TOP_LEVEL_0_ALL-NEXT: complete_requestlimit
3635
// TOP_LEVEL_0_ALL-NEXT: test
3736

3837
// TOP_LEVEL_0_3: let

test/SourceKit/CodeComplete/complete_sort_order.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ func test() {
3333
// CONTEXT: key.kind: source.lang.swift.decl
3434
// CONTEXT-NEXT: key.name: "x"
3535
// CONTEXT-NOT: key.name:
36-
// CONTEXT: key.name: "complete_sort_order",
37-
// CONTEXT-NOT: key.name:
3836
// CONTEXT: key.name: "foo(a:)"
3937
// CONTEXT-NOT: key.name:
4038
// CONTEXT: key.name: "foo(a:)"
@@ -43,6 +41,7 @@ func test() {
4341
// CONTEXT-NOT: key.name:
4442
// CONTEXT: key.name: "test()"
4543
// CONTEXT: key.name: "#column"
44+
// CONTEXT: key.name: "complete_sort_order"
4645

4746
// RUN: %complete-test -tok=STMT_0 %s | %FileCheck %s -check-prefix=STMT
4847
func test1() {

0 commit comments

Comments
 (0)