Skip to content

Commit 828d127

Browse files
committed
[SourceKit/CursorInfo] Add locations for external files to result
.swiftsourceinfo files contain the serialized location for declarations. Use this when outputting locations in cursor info so that clients need not perform an extra index lookup for external modules.
1 parent e9dcc67 commit 828d127

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

lib/IDE/CommentConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ visitDocComment(const DocComment *DC, TypeOrExtensionDecl SynthesizedTarget) {
315315

316316
{
317317
// Print line and column number.
318-
auto Loc = D->getLoc();
318+
auto Loc = D->getLoc(/*SerializedOK=*/true);
319319
if (Loc.isValid()) {
320320
const auto &SM = D->getASTContext().SourceMgr;
321321
StringRef FileName = SM.getDisplayNameForLoc(Loc);

test/SourceKit/CursorInfo/cursor_info.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ func checkAnyIsAKeyword(x: Any) {}
283283
// CHECK5-NEXT: source.lang.swift
284284
// CHECK5-NEXT: (Int) -> (){{$}}
285285

286-
// RUN: %sourcekitd-test -req=cursor -pos=9:32 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %s | %FileCheck -check-prefix=CHECK6 %s
287-
// CHECK6: source.lang.swift.ref.function.free ()
286+
// RUN: %sourcekitd-test -req=global-config -req-opts=optimize_for_ide=0 == -req=cursor -pos=9:32 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %s | %FileCheck -check-prefix=CHECK6 %s
287+
// CHECK6: source.lang.swift.ref.function.free ({{.*}}/FooSwiftModule.swift:2:13-2:25)
288288
// CHECK6-NEXT: fooSwiftFunc
289289
// CHECK6-NEXT: s:14FooSwiftModule03fooB4FuncSiyF
290290
// CHECK6-NEXT: source.lang.swift
@@ -293,7 +293,7 @@ func checkAnyIsAKeyword(x: Any) {}
293293
// CHECK6-NEXT: FooSwiftModule
294294
// CHECK6-NEXT: <Declaration>func fooSwiftFunc() -&gt; <Type usr="s:Si">Int</Type></Declaration>
295295
// CHECK6-NEXT: <decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fooSwiftFunc</decl.name>() -&gt; <decl.function.returntype><ref.struct usr="s:Si">Int</ref.struct></decl.function.returntype></decl.function.free>
296-
// CHECK6-NEXT: {{^}}<Function><Name>fooSwiftFunc()</Name><USR>s:14FooSwiftModule03fooB4FuncSiyF</USR><Declaration>func fooSwiftFunc() -&gt; Int</Declaration><CommentParts><Abstract><Para>This is ‘fooSwiftFunc’ from ‘FooSwiftModule’.</Para></Abstract></CommentParts></Function>{{$}}
296+
// CHECK6-NEXT: {{^}}<Function file="{{.*}}/FooSwiftModule.swift" line="2" column="13"><Name>fooSwiftFunc()</Name><USR>s:14FooSwiftModule03fooB4FuncSiyF</USR><Declaration>func fooSwiftFunc() -&gt; Int</Declaration><CommentParts><Abstract><Para>This is ‘fooSwiftFunc’ from ‘FooSwiftModule’.</Para></Abstract></CommentParts></Function>{{$}}
297297

298298
// RUN: %sourcekitd-test -req=cursor -pos=14:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %s | %FileCheck -check-prefix=CHECK7 %s
299299
// CHECK7: source.lang.swift.ref.struct (13:8-13:10)

test/SourceKit/CursorInfo/cursor_symbol_graph_referenced.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Parent {
1919

2020
// RUN: %empty-directory(%t)
2121
// RUN: echo 'public struct FromSomeModule {} ' > %t/SomeModule.swift
22-
// RUN: %target-build-swift %t/SomeModule.swift -module-name SomeModule -emit-module -emit-module-path %t/
22+
// RUN: %target-build-swift %t/SomeModule.swift -emit-module -module-name SomeModule -o %t/SomeModule.swiftmodule
2323

2424
// References should cover symbols from the symbol graph declaration fragments, even if not present in the original source.
2525
// RUN: %sourcekitd-test -req=cursor -pos=3:5 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple -I %t | %FileCheck -check-prefixes=GLOBAL %s
@@ -133,7 +133,7 @@ extension Parent {
133133

134134

135135
// References to unsupported types (like generic parameters) should be ignored.
136-
// RUN: %sourcekitd-test -req=cursor -pos=11:14 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple -I %t | %FileCheck -check-prefixes=NESTED %s
136+
// RUN: %sourcekitd-test -req=global-config -req-opts=optimize_for_ide=0 == -req=cursor -pos=11:14 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple -I %t | %FileCheck -check-prefixes=NESTED %s
137137
//
138138
// NESTED: SYMBOL GRAPH BEGIN
139139
// NESTED: "declarationFragments": [
@@ -225,8 +225,7 @@ extension Parent {
225225
// NESTED-NEXT: [[ExtInner_USR]] | internal | {{.*}}cursor_symbol_graph_referenced.swift | cursor_symbol_graph_referenced | User | NonSPI | source.lang.swift
226226
// NESTED-NEXT: Parent swift.struct s:30cursor_symbol_graph_referenced6ParentV
227227
// NESTED-NEXT: ExtInner swift.struct [[ExtInner_USR]]
228-
// FIXME: We should get the file path via the swiftsourceinfo file for user modules (rdar://75582627)
229-
// NESTED-NEXT: [[FromSomeModule_USR]] | public | <empty> | SomeModule | User | NonSPI | source.lang.swift
228+
// NESTED-NEXT: [[FromSomeModule_USR]] | public | {{.*}}/SomeModule.swift | SomeModule | User | NonSPI | source.lang.swift
230229
// NESTED-NEXT: FromSomeModule swift.struct [[FromSomeModule_USR]]
231230
// NESTED-NEXT: REFERENCED DECLS END
232231

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ struct CursorSymbolInfo {
444444
/// Stores the Symbol Graph title, kind, and USR of the parent contexts of the
445445
/// symbol under the cursor.
446446
ArrayRef<ParentInfo> ParentContexts;
447-
/// The set of decls referenced in the symbol graph delcaration fragments.
447+
/// The set of decls referenced in the symbol graph declaration fragments.
448448
ArrayRef<ReferencedDeclInfo> ReferencedSymbols;
449449
/// For calls this lists the USRs of the receiver types (multiple only in the
450450
/// case that the base is a protocol composition).

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,8 @@ getLocationInfo(const ValueDecl *VD,
850850

851851
auto ClangNode = VD->getClangNode();
852852

853-
if (VD->getLoc().isValid()) {
853+
auto Loc = VD->getLoc(/*SerializedOK=*/true);
854+
if (Loc.isValid()) {
854855
auto getSignatureRange = [&](const ValueDecl *VD) -> Optional<unsigned> {
855856
if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {
856857
SourceRange R = FD->getSignatureSourceRange();
@@ -865,14 +866,13 @@ getLocationInfo(const ValueDecl *VD,
865866
} else if (VD->hasName()) {
866867
NameLen = VD->getBaseName().userFacingName().size();
867868
} else {
868-
NameLen = getCharLength(SM, VD->getLoc());
869+
NameLen = getCharLength(SM, Loc);
869870
}
870871

871-
unsigned DeclBufID = SM.findBufferContainingLoc(VD->getLoc());
872-
DeclarationLoc = {SM.getLocOffsetInBuffer(VD->getLoc(), DeclBufID),
872+
unsigned DeclBufID = SM.findBufferContainingLoc(Loc);
873+
DeclarationLoc = {SM.getLocOffsetInBuffer(Loc, DeclBufID),
873874
NameLen};
874875
Filename = SM.getIdentifierForBuffer(DeclBufID);
875-
876876
} else if (ClangNode) {
877877
ClangImporter *Importer =
878878
static_cast<ClangImporter *>(Ctx.getClangModuleLoader());

0 commit comments

Comments
 (0)