mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
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. # Conflicts: # Sources/SourceKitLSP/SourceKitLSPServer+Options.swift # Sources/SourceKitLSP/Swift/SwiftLanguageService.swift # Sources/sourcekit-lsp/SourceKitLSP.swift # Tests/SourceKitLSPTests/BackgroundIndexingTests.swift # Tests/SourceKitLSPTests/ExecuteCommandTests.swift
39 lines
1.4 KiB
Swift
39 lines
1.4 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Foundation
|
|
|
|
import struct TSCBasic.AbsolutePath
|
|
|
|
/// The home directory of the current user (same as returned by Foundation's `NSHomeDirectory` method).
|
|
public var homeDirectoryForCurrentUser: AbsolutePath {
|
|
try! AbsolutePath(validating: NSHomeDirectory())
|
|
}
|
|
|
|
extension AbsolutePath {
|
|
|
|
/// Inititializes an absolute path from a string, expanding a leading `~` to `homeDirectoryForCurrentUser` first.
|
|
public init(expandingTilde path: String) throws {
|
|
if path.first == "~" {
|
|
try self.init(homeDirectoryForCurrentUser, validating: String(path.dropFirst(2)))
|
|
} else {
|
|
try self.init(validating: path)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The default directory to write generated files
|
|
/// `<TEMPORARY_DIRECTORY>/sourcekit-lsp/`
|
|
public var defaultDirectoryForGeneratedFiles: AbsolutePath {
|
|
try! AbsolutePath(validating: NSTemporaryDirectory()).appending(component: "sourcekit-lsp")
|
|
}
|