Skip to content

Commit 8625b3f

Browse files
committed
[SourceKit] Don't realpath the primary file path
If the file didn’t exist on disk, `fileSystem->getRealPath` returns an empty string, which means we can’t find the `InputBuffer` and thsu won’t run solver-based cursor info. There’s no reason to realpath `PrimaryInputPath`, `getMemoryBuffer` already does that. rdar://120737244
1 parent 24814c5 commit 8625b3f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: split-file --leading-lines %s %t
2+
3+
//--- input.swift
4+
5+
func foo() -> Int { 1 }
6+
func foo() -> String { "" }
7+
func test() {
8+
// RUN: %sourcekitd-test \
9+
// RUN: -req=open %t/memory-only.swift -text-input %t/input.swift -print-raw-response -- %t/memory-only.swift == \
10+
// RUN: -req=cursor -pos=%(line + 1):7 %t/memory-only.swift -text-input %t/input.swift -- %t/memory-only.swift | %FileCheck %s
11+
_ = foo()
12+
}
13+
14+
// CHECK: () -> Int
15+
// CHECK-LABEL: SECONDARY SYMBOLS BEGIN
16+
// CHECK: () -> String

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,11 +2119,9 @@ void SwiftLangSupport::getCursorInfo(
21192119
std::shared_ptr<llvm::MemoryBuffer> InputBuffer;
21202120
if (InputBufferName.empty() && Length == 0) {
21212121
std::string InputFileError;
2122-
llvm::SmallString<128> RealInputFilePath;
2123-
fileSystem->getRealPath(PrimaryFilePath, RealInputFilePath);
21242122
InputBuffer =
21252123
std::shared_ptr<llvm::MemoryBuffer>(getASTManager()->getMemoryBuffer(
2126-
RealInputFilePath, fileSystem, InputFileError));
2124+
PrimaryFilePath, fileSystem, InputFileError));
21272125
}
21282126

21292127
// Receiver is async, so be careful about captured values. This is all

0 commit comments

Comments
 (0)