Skip to content

Commit ccae1c6

Browse files
committed
Update BSP connection build server config lookup path
Resolves #1695 Adopt `<workspace_root>/.bsp` search locations in addition to `<workspace_root>/`.
1 parent 9e2b1c9 commit ccae1c6

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Sources/BuildSystemIntegration/ExternalBuildSystemAdapter.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,34 @@ actor ExternalBuildSystemAdapter {
9494
private var lastRestart: Date?
9595

9696
static package func projectRoot(for workspaceFolder: AbsolutePath, options: SourceKitLSPOptions) -> AbsolutePath? {
97-
guard localFileSystem.isFile(workspaceFolder.appending(component: "buildServer.json")) else {
98-
return nil
97+
var buildServerConfigLocations = [String]()
98+
99+
#if os(Windows)
100+
let workspacePath = workspaceFolder.pathString + "\\.bsp"
101+
let localAppDataPath = ProcessInfo.processInfo.environment["LOCALAPPDATA"] ?? "C:\\Users\\Default\\AppData\\Local\\bsp"
102+
let programDataPath = ProcessInfo.processInfo.environment["PROGRAMDATA"] ?? "C:\\ProgramData\\bsp"
103+
104+
buildServerConfigLocations.append(contentsOf: [workspacePath, localAppDataPath, programDataPath])
105+
#elseif os(Linux)
106+
let workspacePath = workspaceFolder.pathString + "/bsp"
107+
let xdgDataHomePath = ProcessInfo.processInfo.environment["XDG_DATA_HOME"] ?? FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".local/share/bsp")
108+
let xdgDataDirsPath = ProcessInfo.processInfo.environment["XDG_DATA_DIRS"] ?? "/usr/local/share:/usr/share"
109+
110+
buildServerConfigLocations.append(contentsOf: [workspacePath, xdgDataHomePath, xdgDataDirsPath])
111+
#else
112+
let workspacePath = workspaceFolder.pathString + "/bsp"
113+
let libraryPath = FileManager.default.homeDirectoryForCurrentUser.appending(components: "Library", "Application Support", "bsp").absoluteString
114+
115+
buildServerConfigLocations.append(contentsOf: [workspacePath, libraryPath])
116+
#endif
117+
118+
for buildServerConfigLocation in buildServerConfigLocations {
119+
guard let buildServerConfigLocation = try? AbsolutePath(validating: buildServerConfigLocation) else { continue }
120+
if localFileSystem.isFile(buildServerConfigLocation) {
121+
return workspaceFolder
122+
}
99123
}
100-
return workspaceFolder
124+
return nil
101125
}
102126

103127
init(

0 commit comments

Comments
 (0)