Skip to content

Commit eaabf79

Browse files
committed
Fixed generated macro expansion file extension not recognised, by switching to file names which don't contain fragments
1 parent c798ed7 commit eaabf79

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

Sources/SourceKitLSP/Swift/MacroExpansion.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,14 @@ extension SwiftLanguageService {
8888
)
8989
}
9090

91-
let macroExpansionFileName = sourceFileURL.lastPathComponent // name of the source file
92-
let macroExpansionPositionRangeFragment =
91+
let macroExpansionFileName = sourceFileURL.deletingPathExtension().lastPathComponent // name of the source file
92+
let macroExpansionPositionRangeIndicator =
9393
"L\(macroEdit.range.lowerBound.line)C\(macroEdit.range.lowerBound.utf16index)-L\(macroEdit.range.upperBound.line)C\(macroEdit.range.upperBound.utf16index)" // github permalink notation for position range
9494

95-
var macroExpansionFilePath = macroExpansionBufferDirectoryURL.appendingPathComponent(
96-
"\(macroExpansionFileName)"
95+
let macroExpansionFilePath = macroExpansionBufferDirectoryURL.appendingPathComponent(
96+
"\(macroExpansionFileName)_\(macroExpansionPositionRangeIndicator).\(sourceFileURL.pathExtension)"
9797
)
9898

99-
var urlComponents = URLComponents(url: macroExpansionFilePath, resolvingAgainstBaseURL: false)
100-
urlComponents?.fragment = macroExpansionPositionRangeFragment
101-
102-
macroExpansionFilePath = urlComponents?.url ?? macroExpansionFilePath
103-
10499
let macroExpansionDocURI = DocumentURI(macroExpansionFilePath)
105100

106101
do {

Tests/SourceKitLSPTests/ExecuteCommandTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,7 @@ final class ExecuteCommandTests: XCTestCase {
248248

249249
XCTAssertEqual(
250250
url.lastPathComponent,
251-
"MyMacroClient.swift",
252-
"Failed for position range between \(positionMarker.start) and \(positionMarker.end)"
253-
)
254-
XCTAssertEqual(
255-
url.fragment,
256-
"L4C2-L4C19",
251+
"MyMacroClient_L4C2-L4C19.swift",
257252
"Failed for position range between \(positionMarker.start) and \(positionMarker.end)"
258253
)
259254
}

0 commit comments

Comments
 (0)