Skip to content

Commit 88d0023

Browse files
committed
[SourceKit] Update requests to handle locations within generated buffers
Update requests to handle being passed a separate `key.primary_file` which specifies the file to use for building the AST. `key.sourcefile` is then the file to find in `SourceManager`, which could be a generated buffer. Resolves rdar://106863186.
1 parent cd52979 commit 88d0023

File tree

7 files changed

+353
-200
lines changed

7 files changed

+353
-200
lines changed

test/SourceKit/Macros/macro_basic.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
181181
// ATTACHED_EXPAND-NEXT: source.edit.kind.active:
182182
// ATTACHED_EXPAND-NEXT: 21:1-21:15 ""
183183

184+
//##-- Cursor info on the attribute expanded by @myTypeWrapper
185+
// RUN: %sourcekitd-test -req=cursor -cursor-action -req-opts=retrieve_symbol_graph=1 -offset=2 @__swiftmacro_9MacroUser1SV13myTypeWrapperfMA_.swift -primary-file %s -- ${COMPILER_ARGS[@]} | %FileCheck -check-prefix=NESTED_ATTACHED_CURSOR %s
186+
// NESTED_ATTACHED_CURSOR: source.lang.swift.ref.macro
187+
// NESTED_ATTACHED_CURSOR-SAME: macro_basic.swift:10:27-10:43
188+
// NESTED_ATTACHED_CURSOR-LABEL: SYMBOL GRAPH BEGIN
189+
// NESTED_ATTACHED_CURSOR: "identifier": {
190+
// NESTED_ATTACHED_CURSOR-NEXT: "interfaceLanguage": "swift",
191+
// NESTED_ATTACHED_CURSOR-NEXT: "precise": "s:9MacroUser16accessViaStorageyycfm"
192+
// NESTED_ATTACHED_CURSOR-NEXT: },
193+
// NESTED_ATTACHED_CURSOR-NEXT: "kind": {
194+
// NESTED_ATTACHED_CURSOR-NEXT: "displayName": "Macro",
195+
// NESTED_ATTACHED_CURSOR-NEXT: "identifier": "swift.macro"
196+
// NESTED_ATTACHED_CURSOR-NEXT: },
197+
// NESTED_ATTACHED_CURSOR: SYMBOL GRAPH END
198+
// NESTED_ATTACHED_CURSOR-LABEL: ACTIONS BEGIN
199+
// NESTED_ATTACHED_CURSOR: source.refactoring.kind.expand.macro
200+
// NESTED_ATTACHED_CURSOR-NEXT: Expand Macro
201+
// NESTED_ATTACHED_CURSOR:ACTIONS END
202+
184203
//##-- Refactoring on the attribute expanded by @myTypeWrapper
185204
// RUN: %sourcekitd-test -req=refactoring.expand.macro -pos=1:2 @__swiftmacro_9MacroUser1SV13myTypeWrapperfMA_.swift -primary-file %s -- ${COMPILER_ARGS[@]} | %FileCheck -check-prefix=NESTED_ATTACHED_EXPAND %s
186205
// NESTED_ATTACHED_EXPAND: source.edit.kind.active:

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,9 @@ enum class SemanticRefactoringKind {
640640

641641
struct SemanticRefactoringInfo {
642642
SemanticRefactoringKind Kind;
643-
// The name of the source file to start the refactoring in. Empty if it is
644-
// the primary file (in which case the primary file from the AST is used).
645-
// This must match the buffer identifier stored in the source manager.
643+
// The name of the source file to start the refactoring in. This must either
644+
// be empty (in which case the primary file for the AST is used), or exactly
645+
// match the buffer identifier stored in the source manager.
646646
StringRef SourceFile;
647647
unsigned Line;
648648
unsigned Column;
@@ -982,9 +982,10 @@ class LangSupport {
982982
EditorConsumer &Consumer) = 0;
983983

984984
virtual void getCursorInfo(
985-
StringRef Filename, unsigned Offset, unsigned Length, bool Actionables,
986-
bool SymbolGraph, bool CancelOnSubsequentRequest,
987-
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
985+
StringRef PrimaryFile, StringRef InputFile, unsigned Offset,
986+
unsigned Length, bool Actionables, bool SymbolGraph,
987+
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
988+
Optional<VFSOptions> vfsOptions,
988989
SourceKitCancellationToken CancellationToken,
989990
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;
990991

@@ -1003,25 +1004,27 @@ class LangSupport {
10031004
Receiver) = 0;
10041005

10051006
virtual void getRangeInfo(
1006-
StringRef Filename, unsigned Offset, unsigned Length,
1007-
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
1008-
SourceKitCancellationToken CancellationToken,
1007+
StringRef PrimaryFile, StringRef InputFile, unsigned Offset,
1008+
unsigned Length, bool CancelOnSubsequentRequest,
1009+
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
10091010
std::function<void(const RequestResult<RangeInfo> &)> Receiver) = 0;
10101011

10111012
virtual void getCursorInfoFromUSR(
1012-
StringRef Filename, StringRef USR, bool CancelOnSubsequentRequest,
1013-
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
1013+
StringRef PrimaryFile, StringRef InputFile, StringRef USR,
1014+
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
1015+
Optional<VFSOptions> vfsOptions,
10141016
SourceKitCancellationToken CancellationToken,
10151017
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;
10161018

10171019
virtual void findRelatedIdentifiersInFile(
1018-
StringRef Filename, unsigned Offset, bool CancelOnSubsequentRequest,
1019-
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
1020+
StringRef PrimaryFile, StringRef InputFile, unsigned Offset,
1021+
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
1022+
SourceKitCancellationToken CancellationToken,
10201023
std::function<void(const RequestResult<RelatedIdentsInfo> &)>
10211024
Receiver) = 0;
10221025

10231026
virtual void findActiveRegionsInFile(
1024-
StringRef Filename, ArrayRef<const char *> Args,
1027+
StringRef PrimaryFile, StringRef InputFile, ArrayRef<const char *> Args,
10251028
SourceKitCancellationToken CancellationToken,
10261029
std::function<void(const RequestResult<ActiveRegionsInfo> &)>
10271030
Receiver) = 0;
@@ -1059,7 +1062,7 @@ class LangSupport {
10591062
CategorizedEditsReceiver Receiver) = 0;
10601063

10611064
virtual void collectExpressionTypes(
1062-
StringRef FileName, ArrayRef<const char *> Args,
1065+
StringRef PrimaryFile, StringRef InputFile, ArrayRef<const char *> Args,
10631066
ArrayRef<const char *> ExpectedProtocols, bool FullyQualified,
10641067
bool CanonicalType, SourceKitCancellationToken CancellationToken,
10651068
std::function<void(const RequestResult<ExpressionTypesInFile> &)>
@@ -1069,7 +1072,7 @@ class LangSupport {
10691072
/// the source file. If `Offset` or `Length` are empty, variable types for
10701073
/// the entire document are collected.
10711074
virtual void collectVariableTypes(
1072-
StringRef FileName, ArrayRef<const char *> Args,
1075+
StringRef PrimaryFile, StringRef InputFile, ArrayRef<const char *> Args,
10731076
Optional<unsigned> Offset, Optional<unsigned> Length, bool FullyQualified,
10741077
SourceKitCancellationToken CancellationToken,
10751078
std::function<void(const RequestResult<VariableTypesInFile> &)>

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ class SwiftLangSupport : public LangSupport {
632632
void editorExpandPlaceholder(StringRef Name, unsigned Offset, unsigned Length,
633633
EditorConsumer &Consumer) override;
634634

635-
void getCursorInfo(StringRef Filename, unsigned Offset, unsigned Length,
636-
bool Actionables, bool SymbolGraph,
637-
bool CancelOnSubsequentRequest,
635+
void getCursorInfo(StringRef PrimaryFile, StringRef InputFile,
636+
unsigned Offset, unsigned Length, bool Actionables,
637+
bool SymbolGraph, bool CancelOnSubsequentRequest,
638638
ArrayRef<const char *> Args,
639639
Optional<VFSOptions> vfsOptions,
640640
SourceKitCancellationToken CancellationToken,
@@ -655,26 +655,28 @@ class SwiftLangSupport : public LangSupport {
655655
override;
656656

657657
void getRangeInfo(
658-
StringRef Filename, unsigned Offset, unsigned Length,
659-
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
660-
SourceKitCancellationToken CancellationToken,
658+
StringRef PrimaryFile, StringRef InputFile, unsigned Offset,
659+
unsigned Length, bool CancelOnSubsequentRequest,
660+
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
661661
std::function<void(const RequestResult<RangeInfo> &)> Receiver) override;
662662

663663
void getCursorInfoFromUSR(
664-
StringRef Filename, StringRef USR, bool CancelOnSubsequentRequest,
665-
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
664+
StringRef PrimaryFile, StringRef InputFile, StringRef USR,
665+
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
666+
Optional<VFSOptions> vfsOptions,
666667
SourceKitCancellationToken CancellationToken,
667668
std::function<void(const RequestResult<CursorInfoData> &)> Receiver)
668669
override;
669670

670671
void findRelatedIdentifiersInFile(
671-
StringRef Filename, unsigned Offset, bool CancelOnSubsequentRequest,
672-
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
672+
StringRef PrimaryFile, StringRef InputFile, unsigned Offset,
673+
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
674+
SourceKitCancellationToken CancellationToken,
673675
std::function<void(const RequestResult<RelatedIdentsInfo> &)> Receiver)
674676
override;
675677

676678
void findActiveRegionsInFile(
677-
StringRef Filename, ArrayRef<const char *> Args,
679+
StringRef PrimaryFile, StringRef InputFile, ArrayRef<const char *> Args,
678680
SourceKitCancellationToken CancellationToken,
679681
std::function<void(const RequestResult<ActiveRegionsInfo> &)> Receiver)
680682
override;
@@ -695,14 +697,14 @@ class SwiftLangSupport : public LangSupport {
695697
CategorizedRenameRangesReceiver Receiver) override;
696698

697699
void collectExpressionTypes(
698-
StringRef FileName, ArrayRef<const char *> Args,
700+
StringRef PrimaryFile, StringRef InputFile, ArrayRef<const char *> Args,
699701
ArrayRef<const char *> ExpectedProtocols, bool FullyQualified,
700702
bool CanonicalType, SourceKitCancellationToken CancellationToken,
701703
std::function<void(const RequestResult<ExpressionTypesInFile> &)>
702704
Receiver) override;
703705

704706
void collectVariableTypes(
705-
StringRef FileName, ArrayRef<const char *> Args,
707+
StringRef PrimaryFile, StringRef InputFile, ArrayRef<const char *> Args,
706708
Optional<unsigned> Offset, Optional<unsigned> Length, bool FullyQualified,
707709
SourceKitCancellationToken CancellationToken,
708710
std::function<void(const RequestResult<VariableTypesInFile> &)> Receiver)

0 commit comments

Comments
 (0)