Skip to content

Commit 20f0d3f

Browse files
authored
Merge pull request #2063 from ahoppen/hover-compile-flags
Fix issue that caused code completion to fail using compile_flags.txt
2 parents 3cc39df + b49b409 commit 20f0d3f

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

Sources/BuildSystemIntegration/FixedCompilationDatabaseBuildSystem.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,8 @@ package actor FixedCompilationDatabaseBuildSystem: BuiltInBuildSystem {
126126
package func sourceKitOptions(
127127
request: TextDocumentSourceKitOptionsRequest
128128
) async throws -> TextDocumentSourceKitOptionsResponse? {
129-
let compilerName: String
130-
switch request.language {
131-
case .swift: compilerName = "swiftc"
132-
case .c, .cpp, .objective_c, .objective_cpp: compilerName = "clang"
133-
default: return nil
134-
}
135129
return TextDocumentSourceKitOptionsResponse(
136-
compilerArguments: [compilerName] + compilerArgs + [request.textDocument.uri.pseudoPath],
130+
compilerArguments: compilerArgs + [request.textDocument.uri.pseudoPath],
137131
workingDirectory: try? configPath.deletingLastPathComponent().filePath
138132
)
139133
}

Tests/BuildSystemIntegrationTests/CompilationDatabaseTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ final class CompilationDatabaseTests: XCTestCase {
239239
XCTAssertEqual(
240240
buildSettings,
241241
TextDocumentSourceKitOptionsResponse(
242-
compilerArguments: ["clang", "-xc++", "-I", "libwidget/include/", try dummyFile.filePath],
242+
compilerArguments: ["-xc++", "-I", "libwidget/include/", try dummyFile.filePath],
243243
workingDirectory: try tempDir.filePath
244244
)
245245
)

Tests/SourceKitLSPTests/SwiftCompletionTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,29 @@ final class SwiftCompletionTests: XCTestCase {
11461146
)
11471147
XCTAssertEqual(completions.items.map(\.insertText), ["makeBool()", "makeBool(value: )"])
11481148
}
1149+
1150+
func testCompletionUsingCompileFlagsTxt() async throws {
1151+
let project = try await MultiFileTestProject(
1152+
files: [
1153+
"test.swift": """
1154+
func test() {
1155+
#if FOO
1156+
let myVar: String
1157+
#else
1158+
let myVar: Int
1159+
#endif
1160+
print(myVar1️⃣)
1161+
}
1162+
""",
1163+
"compile_flags.txt": "-DFOO",
1164+
]
1165+
)
1166+
let (uri, positions) = try project.openDocument("test.swift")
1167+
let completions = try await project.testClient.send(
1168+
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
1169+
)
1170+
XCTAssertEqual(completions.items.only?.detail, "String")
1171+
}
11491172
}
11501173

11511174
private func countFs(_ response: CompletionList) -> Int {

0 commit comments

Comments
 (0)