Skip to content

[SourceKit] Update requests to handle locations within generated buffers #64456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/SourceKit/Macros/macro_basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
// ATTACHED_EXPAND-NEXT: source.edit.kind.active:
// ATTACHED_EXPAND-NEXT: 21:1-21:15 ""

//##-- Cursor info on the attribute expanded by @myTypeWrapper
// 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
// NESTED_ATTACHED_CURSOR: source.lang.swift.ref.macro
// NESTED_ATTACHED_CURSOR-SAME: macro_basic.swift:10:27-10:43
// NESTED_ATTACHED_CURSOR-LABEL: SYMBOL GRAPH BEGIN
// NESTED_ATTACHED_CURSOR: "identifier": {
// NESTED_ATTACHED_CURSOR-NEXT: "interfaceLanguage": "swift",
// NESTED_ATTACHED_CURSOR-NEXT: "precise": "s:9MacroUser16accessViaStorageyycfm"
// NESTED_ATTACHED_CURSOR-NEXT: },
// NESTED_ATTACHED_CURSOR-NEXT: "kind": {
// NESTED_ATTACHED_CURSOR-NEXT: "displayName": "Macro",
// NESTED_ATTACHED_CURSOR-NEXT: "identifier": "swift.macro"
// NESTED_ATTACHED_CURSOR-NEXT: },
// NESTED_ATTACHED_CURSOR: SYMBOL GRAPH END
// NESTED_ATTACHED_CURSOR-LABEL: ACTIONS BEGIN
// NESTED_ATTACHED_CURSOR: source.refactoring.kind.expand.macro
// NESTED_ATTACHED_CURSOR-NEXT: Expand Macro
// NESTED_ATTACHED_CURSOR:ACTIONS END

//##-- Refactoring on the attribute expanded by @myTypeWrapper
// 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
// NESTED_ATTACHED_EXPAND: source.edit.kind.active:
Expand Down
51 changes: 28 additions & 23 deletions tools/SourceKit/include/SourceKit/Core/LangSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ enum class SemanticRefactoringKind {

struct SemanticRefactoringInfo {
SemanticRefactoringKind Kind;
// The name of the source file to start the refactoring in. Empty if it is
// the primary file (in which case the primary file from the AST is used).
// This must match the buffer identifier stored in the source manager.
StringRef SourceFile;
// The name of the input buffer to start the refactoring in. This must either
// be empty (in which case the primary file for the AST is used), or exactly
// match the buffer identifier stored in the source manager.
StringRef InputBufferName;
unsigned Line;
unsigned Column;
unsigned Length;
Expand Down Expand Up @@ -982,14 +982,15 @@ class LangSupport {
EditorConsumer &Consumer) = 0;

virtual void getCursorInfo(
StringRef Filename, unsigned Offset, unsigned Length, bool Actionables,
bool SymbolGraph, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
StringRef PrimaryFilePath, StringRef InputBufferName, unsigned Offset,
unsigned Length, bool Actionables, bool SymbolGraph,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;

virtual void
getDiagnostics(StringRef InputFile, ArrayRef<const char *> Args,
getDiagnostics(StringRef PrimaryFilePath, ArrayRef<const char *> Args,
Optional<VFSOptions> VfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<DiagnosticsResult> &)>
Expand All @@ -1003,26 +1004,28 @@ class LangSupport {
Receiver) = 0;

virtual void getRangeInfo(
StringRef Filename, unsigned Offset, unsigned Length,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName, unsigned Offset,
unsigned Length, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<RangeInfo> &)> Receiver) = 0;

virtual void getCursorInfoFromUSR(
StringRef Filename, StringRef USR, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
StringRef PrimaryFilePath, StringRef InputBufferName, StringRef USR,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;

virtual void findRelatedIdentifiersInFile(
StringRef Filename, unsigned Offset, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName, unsigned Offset,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<RelatedIdentsInfo> &)>
Receiver) = 0;

virtual void findActiveRegionsInFile(
StringRef Filename, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<ActiveRegionsInfo> &)>
Receiver) = 0;

Expand Down Expand Up @@ -1052,25 +1055,27 @@ class LangSupport {
SourceKitCancellationToken CancellationToken,
CategorizedRenameRangesReceiver Receiver) = 0;

virtual void semanticRefactoring(StringRef PrimaryFile,
virtual void semanticRefactoring(StringRef PrimaryFilePath,
SemanticRefactoringInfo Info,
ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
CategorizedEditsReceiver Receiver) = 0;

virtual void collectExpressionTypes(
StringRef FileName, ArrayRef<const char *> Args,
ArrayRef<const char *> ExpectedProtocols, bool FullyQualified,
bool CanonicalType, SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, ArrayRef<const char *> ExpectedProtocols,
bool FullyQualified, bool CanonicalType,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<ExpressionTypesInFile> &)>
Receiver) = 0;

/// Collects variable types for a range defined by `Offset` and `Length` in
/// the source file. If `Offset` or `Length` are empty, variable types for
/// the entire document are collected.
virtual void collectVariableTypes(
StringRef FileName, ArrayRef<const char *> Args,
Optional<unsigned> Offset, Optional<unsigned> Length, bool FullyQualified,
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, Optional<unsigned> Offset,
Optional<unsigned> Length, bool FullyQualified,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<VariableTypesInFile> &)>
Receiver) = 0;
Expand Down
43 changes: 24 additions & 19 deletions tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,17 @@ class SwiftLangSupport : public LangSupport {
void editorExpandPlaceholder(StringRef Name, unsigned Offset, unsigned Length,
EditorConsumer &Consumer) override;

void getCursorInfo(StringRef Filename, unsigned Offset, unsigned Length,
bool Actionables, bool SymbolGraph,
bool CancelOnSubsequentRequest,
void getCursorInfo(StringRef PrimaryFilePath, StringRef InputBufferName,
unsigned Offset, unsigned Length, bool Actionables,
bool SymbolGraph, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<CursorInfoData> &)>
Receiver) override;

void
getDiagnostics(StringRef InputFile, ArrayRef<const char *> Args,
getDiagnostics(StringRef PrimaryFilePath, ArrayRef<const char *> Args,
Optional<VFSOptions> VfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<DiagnosticsResult> &)>
Expand All @@ -655,27 +655,29 @@ class SwiftLangSupport : public LangSupport {
override;

void getRangeInfo(
StringRef Filename, unsigned Offset, unsigned Length,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName, unsigned Offset,
unsigned Length, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<RangeInfo> &)> Receiver) override;

void getCursorInfoFromUSR(
StringRef Filename, StringRef USR, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, Optional<VFSOptions> vfsOptions,
StringRef PrimaryFilePath, StringRef InputBufferName, StringRef USR,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
Optional<VFSOptions> vfsOptions,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<CursorInfoData> &)> Receiver)
override;

void findRelatedIdentifiersInFile(
StringRef Filename, unsigned Offset, bool CancelOnSubsequentRequest,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName, unsigned Offset,
bool CancelOnSubsequentRequest, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<RelatedIdentsInfo> &)> Receiver)
override;

void findActiveRegionsInFile(
StringRef Filename, ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<ActiveRegionsInfo> &)> Receiver)
override;

Expand All @@ -695,20 +697,23 @@ class SwiftLangSupport : public LangSupport {
CategorizedRenameRangesReceiver Receiver) override;

void collectExpressionTypes(
StringRef FileName, ArrayRef<const char *> Args,
ArrayRef<const char *> ExpectedProtocols, bool FullyQualified,
bool CanonicalType, SourceKitCancellationToken CancellationToken,
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, ArrayRef<const char *> ExpectedProtocols,
bool FullyQualified, bool CanonicalType,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<ExpressionTypesInFile> &)>
Receiver) override;

void collectVariableTypes(
StringRef FileName, ArrayRef<const char *> Args,
Optional<unsigned> Offset, Optional<unsigned> Length, bool FullyQualified,
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, Optional<unsigned> Offset,
Optional<unsigned> Length, bool FullyQualified,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<VariableTypesInFile> &)> Receiver)
override;

void semanticRefactoring(StringRef PrimaryFile, SemanticRefactoringInfo Info,
void semanticRefactoring(StringRef PrimaryFilePath,
SemanticRefactoringInfo Info,
ArrayRef<const char *> Args,
SourceKitCancellationToken CancellationToken,
CategorizedEditsReceiver Receiver) override;
Expand Down
Loading