mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
Use BSP requests to get build settings of a source file
This commit is contained in:
@@ -490,7 +490,6 @@ extension SwiftPMBuildSystem {
|
||||
}
|
||||
|
||||
if let delegate = self.delegate {
|
||||
await delegate.fileBuildSettingsChanged(self.watchedFiles)
|
||||
await delegate.fileHandlingCapabilityChanged()
|
||||
await messageHandler?.sendNotificationToSourceKitLSP(DidChangeBuildTargetNotification(changes: nil))
|
||||
}
|
||||
@@ -548,26 +547,22 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
|
||||
}
|
||||
}
|
||||
|
||||
package func buildSettings(
|
||||
for uri: DocumentURI,
|
||||
in targetIdentifier: BuildTargetIdentifier,
|
||||
language: Language
|
||||
) async throws -> FileBuildSettings? {
|
||||
guard let url = uri.fileURL, let path = try? AbsolutePath(validating: url.path) else {
|
||||
package func sourceKitOptions(request: SourceKitOptionsRequest) async throws -> SourceKitOptionsResponse? {
|
||||
guard let url = request.textDocument.uri.fileURL, let path = try? AbsolutePath(validating: url.path) else {
|
||||
// We can't determine build settings for non-file URIs.
|
||||
return nil
|
||||
}
|
||||
|
||||
if targetIdentifier == .forPackageManifest {
|
||||
if request.target == .forPackageManifest {
|
||||
return try settings(forPackageManifest: path)
|
||||
}
|
||||
|
||||
guard let buildTarget = self.targets[targetIdentifier]?.buildTarget else {
|
||||
logger.fault("Did not find target \(targetIdentifier.forLogging)")
|
||||
guard let buildTarget = self.targets[request.target]?.buildTarget else {
|
||||
logger.fault("Did not find target \(request.target.forLogging)")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !buildTarget.sources.lazy.map(DocumentURI.init).contains(uri),
|
||||
if !buildTarget.sources.lazy.map(DocumentURI.init).contains(request.textDocument.uri),
|
||||
let substituteFile = buildTarget.sources.sorted(by: { $0.path < $1.path }).first
|
||||
{
|
||||
logger.info("Getting compiler arguments for \(url) using substitute file \(substituteFile)")
|
||||
@@ -578,14 +573,18 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
|
||||
// on the file's location on disk and generate compiler arguments for it by picking a source file in that target,
|
||||
// getting its compiler arguments and then patching up the compiler arguments by replacing the substitute file
|
||||
// with the `.cpp` file.
|
||||
return FileBuildSettings(
|
||||
let buildSettings = FileBuildSettings(
|
||||
compilerArguments: try await compilerArguments(for: DocumentURI(substituteFile), in: buildTarget),
|
||||
workingDirectory: projectRoot.pathString
|
||||
).patching(newFile: try resolveSymlinks(path).pathString, originalFile: substituteFile.absoluteString)
|
||||
return SourceKitOptionsResponse(
|
||||
compilerArguments: buildSettings.compilerArguments,
|
||||
workingDirectory: buildSettings.workingDirectory
|
||||
)
|
||||
}
|
||||
|
||||
return FileBuildSettings(
|
||||
compilerArguments: try await compilerArguments(for: uri, in: buildTarget),
|
||||
return SourceKitOptionsResponse(
|
||||
compilerArguments: try await compilerArguments(for: request.textDocument.uri, in: buildTarget),
|
||||
workingDirectory: projectRoot.pathString
|
||||
)
|
||||
}
|
||||
@@ -622,7 +621,7 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
|
||||
return []
|
||||
}
|
||||
|
||||
package func inverseSources(_ request: InverseSourcesRequest) -> InverseSourcesResponse {
|
||||
package func inverseSources(request: InverseSourcesRequest) -> InverseSourcesResponse {
|
||||
return InverseSourcesResponse(targets: targets(for: request.textDocument.uri))
|
||||
}
|
||||
|
||||
@@ -879,9 +878,9 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
|
||||
}
|
||||
|
||||
/// Retrieve settings for a package manifest (Package.swift).
|
||||
private func settings(forPackageManifest path: AbsolutePath) throws -> FileBuildSettings? {
|
||||
private func settings(forPackageManifest path: AbsolutePath) throws -> SourceKitOptionsResponse? {
|
||||
let compilerArgs = workspace.interpreterFlags(for: path.parentDirectory) + [path.pathString]
|
||||
return FileBuildSettings(compilerArguments: compilerArgs)
|
||||
return SourceKitOptionsResponse(compilerArguments: compilerArgs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user