Allow configuring of SourceKit-LSP’s options using .sourcekit-lsp configuration files

The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options.

The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP.

For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files.

Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit.
This commit is contained in:
Alex Hoppen
2024-06-26 18:57:12 +02:00
parent 12142c024c
commit d1cddb8c41
45 changed files with 721 additions and 673 deletions

View File

@@ -45,7 +45,6 @@ func executable(_ name: String) -> String {
/// `buildServer.json` configuration file provided in the repo root.
public actor BuildServerBuildSystem: MessageHandler {
public let projectRoot: AbsolutePath
let buildFolder: AbsolutePath?
let serverConfig: BuildServerConfig
var buildServer: JSONRPCConnection?
@@ -82,7 +81,6 @@ public actor BuildServerBuildSystem: MessageHandler {
public init(
projectRoot: AbsolutePath,
buildFolder: AbsolutePath?,
fileSystem: FileSystem = localFileSystem
) async throws {
let configPath = projectRoot.appending(component: "buildServer.json")
@@ -100,7 +98,6 @@ public actor BuildServerBuildSystem: MessageHandler {
currentWorkingDirectory: fileSystem.currentWorkingDirectory
)
#endif
self.buildFolder = buildFolder
self.projectRoot = projectRoot
self.serverConfig = config
try await self.initializeBuildServer()
@@ -109,11 +106,11 @@ public actor BuildServerBuildSystem: MessageHandler {
/// Creates a build system using the Build Server Protocol config.
///
/// - Returns: nil if `projectRoot` has no config or there is an error parsing it.
public init?(projectRoot: AbsolutePath?, buildSetup: BuildSetup) async {
if projectRoot == nil { return nil }
public init?(projectRoot: AbsolutePath?) async {
guard let projectRoot else { return nil }
do {
try await self.init(projectRoot: projectRoot!, buildFolder: buildSetup.path)
try await self.init(projectRoot: projectRoot)
} catch is FileSystemError {
// config file was missing, no build server for this workspace
return nil