Skip to content

Commit c47a322

Browse files
committed
[SourceKit] Retrieve swiftsourcedocinfo for code completion request
We need swiftsourcedocinfo for cursor info and to be able to reuse the ASTContext from code completion for cursor info, we need to also retrieve the sourcedocinfo for code completion requests.
1 parent 5fb001c commit c47a322

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

include/swift/IDETool/IDEInspectionInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class IDEInspectionInstance {
161161
swift::CompilerInvocation &Invocation, llvm::ArrayRef<const char *> Args,
162162
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
163163
llvm::MemoryBuffer *ideInspectionTargetBuffer, unsigned int Offset,
164-
DiagnosticConsumer *DiagC, bool IgnoreSwiftSourceInfo,
164+
DiagnosticConsumer *DiagC,
165165
std::shared_ptr<std::atomic<bool>> CancellationFlag,
166166
llvm::function_ref<void(CancellableResult<IDEInspectionInstanceResult>)>
167167
Callback);

lib/IDETool/IDEInspectionInstance.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ void swift::ide::IDEInspectionInstance::performOperation(
541541
swift::CompilerInvocation &Invocation, llvm::ArrayRef<const char *> Args,
542542
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
543543
llvm::MemoryBuffer *ideInspectionTargetBuffer, unsigned int Offset,
544-
DiagnosticConsumer *DiagC, bool IgnoreSwiftSourceInfo,
544+
DiagnosticConsumer *DiagC,
545545
std::shared_ptr<std::atomic<bool>> CancellationFlag,
546546
llvm::function_ref<void(CancellableResult<IDEInspectionInstanceResult>)>
547547
Callback) {
@@ -563,8 +563,6 @@ void swift::ide::IDEInspectionInstance::performOperation(
563563
return;
564564
}
565565

566-
Invocation.getFrontendOptions().IgnoreSwiftSourceInfo = IgnoreSwiftSourceInfo;
567-
568566
// We don't need token list.
569567
Invocation.getLangOptions().CollectParsedToken = false;
570568

@@ -620,7 +618,7 @@ void swift::ide::IDEInspectionInstance::codeComplete(
620618
// they're somewhat heavy operations and aren't needed for completion.
621619
performOperation(
622620
Invocation, Args, FileSystem, ideInspectionTargetBuffer, Offset, DiagC,
623-
/*IgnoreSwiftSourceInfo=*/true, CancellationFlag,
621+
CancellationFlag,
624622
[&](CancellableResult<IDEInspectionInstanceResult> CIResult) {
625623
CIResult.mapAsync<CodeCompleteResult>(
626624
[&CompletionContext, &CancellationFlag](auto &Result,
@@ -697,7 +695,7 @@ void swift::ide::IDEInspectionInstance::typeContextInfo(
697695

698696
performOperation(
699697
Invocation, Args, FileSystem, ideInspectionTargetBuffer, Offset, DiagC,
700-
/*IgnoreSwiftSourceInfo=*/true, CancellationFlag,
698+
CancellationFlag,
701699
[&](CancellableResult<IDEInspectionInstanceResult> CIResult) {
702700
CIResult.mapAsync<TypeContextInfoResult>(
703701
[&CancellationFlag](auto &Result, auto DeliverTransformed) {
@@ -765,7 +763,7 @@ void swift::ide::IDEInspectionInstance::conformingMethodList(
765763

766764
performOperation(
767765
Invocation, Args, FileSystem, ideInspectionTargetBuffer, Offset, DiagC,
768-
/*IgnoreSwiftSourceInfo=*/true, CancellationFlag,
766+
CancellationFlag,
769767
[&](CancellableResult<IDEInspectionInstanceResult> CIResult) {
770768
CIResult.mapAsync<ConformingMethodListResults>(
771769
[&ExpectedTypeNames, &CancellationFlag](auto &Result,
@@ -831,7 +829,7 @@ void swift::ide::IDEInspectionInstance::cursorInfo(
831829

832830
performOperation(
833831
Invocation, Args, FileSystem, ideInspectionTargetBuffer, Offset, DiagC,
834-
/*IgnoreSwiftSourceInfo=*/false, CancellationFlag,
832+
CancellationFlag,
835833
[&](CancellableResult<IDEInspectionInstanceResult> CIResult) {
836834
CIResult.mapAsync<CursorInfoResults>(
837835
[&CancellationFlag, Offset](auto &Result, auto DeliverTransformed) {

test/SourceKit/CursorInfo/cursor_uses_swiftsourceinfo.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
// RUN: %target-swift-frontend -emit-module -module-name MyModule -emit-module-path %t/build/MyModule.swiftmodule -emit-module-source-info-path %t/build/MyModule.swiftsourceinfo %t/split/Action.swift
55
// RUN: %sourcekitd-test -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=5:14 %t/split/test.swift -- %t/split/test.swift -I %t/build -target %target-triple | %FileCheck %s
66

7+
// We should also get source doc info if we execute a code completion request (which doesn't need source doc info) first
8+
// RUN: %sourcekitd-test \
9+
// RUN: -req=complete %t/split/test.swift -pos=5:14 -- %t/split/test.swift -I %t/build -target %target-triple == \
10+
// RUN: -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=5:14 %t/split/test.swift -- %t/split/test.swift -I %t/build -target %target-triple
11+
712
// BEGIN Action.swift
813
public protocol Action {}
914

0 commit comments

Comments
 (0)