Skip to content

Commit 22ec953

Browse files
authored
Merge pull request #1537 from ahoppen/6.0/configuration
[6.0] Add configuration files for SourceKit-LSP
2 parents c185099 + a84c253 commit 22ec953

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1021
-985
lines changed

Documentation/Configuration File.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Configuration File
2+
3+
`.sourcekit-lsp/config.json` configuration files can be used to modify the behavior of SourceKit-LSP in various ways. The following locations are checked. Settings in later configuration files override settings in earlier configuration files
4+
- `~/.sourcekit-lsp/config.json`
5+
- On macOS: `~/Library/Application Support/org.swift.sourcekit-lsp/config.json` from the various `Library` folders on the system
6+
- If the `XDG_CONFIG_HOME` environment variable is set: `$XDG_CONFIG_HOME/sourcekit-lsp/config.json`
7+
- Initialization options passed in the initialize request
8+
- A `.sourcekit-lsp/config.json` file in a workspace’s root
9+
10+
The structure of the file is currently not guaranteed to be stable. Options may be removed or renamed.
11+
12+
## Structure
13+
14+
`config.json` is a JSON file with the following structure. All keys are optional and unknown keys are ignored.
15+
16+
- `swiftPM`: Dictionary with the following keys, defining options for SwiftPM workspaces
17+
- `configuration: "debug"|"release"`: The configuration to build the project for during background indexing and the configuration whose build folder should be used for Swift modules if background indexing is disabled. Equivalent to SwiftPM's `--configuration` option.
18+
- `scratchPath: string`: Build artifacts directory path. If nil, the build system may choose a default value. Equivalent to SwiftPM's `--scratch-path` option.
19+
- `swiftSDKsDirectory: string`: Equivalent to SwiftPM's `--swift-sdks-path` option
20+
- `swiftSDK: string`: Equivalent to SwiftPM's `--swift-sdk` option
21+
- `triple: string`: Equivalent to SwiftPM's `--triple` option
22+
- `cCompilerFlags: string[]`: Extra arguments passed to the compiler for C files. Equivalent to SwiftPM's `-Xcc` option.
23+
- `cxxCompilerFlags: string[]`: Extra arguments passed to the compiler for C++ files. Equivalent to SwiftPM's `-Xcxx` option.
24+
- `swiftCompilerFlags: string[]`: Extra arguments passed to the compiler for Swift files. Equivalent to SwiftPM's `-Xswiftc` option.
25+
- `linkerFlags: string[]`: Extra arguments passed to the linker. Equivalent to SwiftPM's `-Xlinker` option.
26+
- `compilationDatabase`: Dictionary with the following keys, defining options for workspaces with a compilation database
27+
- `searchPaths: string[]`: Additional paths to search for a compilation database, relative to a workspace root.
28+
- `fallbackBuildSystem`: Dictionary with the following keys, defining options for files that aren't managed by any build system
29+
- `cCompilerFlags: string[]`: Extra arguments passed to the compiler for C files
30+
- `cxxCompilerFlags: string[]`: Extra arguments passed to the compiler for C++ files
31+
- `swiftCompilerFlags: string[]`: Extra arguments passed to the compiler for Swift files
32+
- `clangdOptions: string[]`: Extra command line arguments passed to `clangd` when launching it
33+
- `index`: Dictionary with the following keys, defining options related to indexing
34+
- `indexStorePath: string`: Directory in which a separate compilation stores the index store. By default, inferred from the build system.
35+
- `indexDatabasePath: string`: Directory in which the indexstore-db should be stored. By default, inferred from the build system.
36+
- `indexPrefixMap: [string: string]`: Path remappings for remapping index data for local use.
37+
- `maxCoresPercentageToUseForBackgroundIndexing: double`: A hint indicating how many cores background indexing should use at most (value between 0 and 1). Background indexing is not required to honor this setting
38+
- `updateIndexStoreTimeout: int`: Number of seconds to wait for an update index store task to finish before killing it.
39+
- `defaultWorkspaceType: "buildserver"|"compdb"|"swiftpm"`: Overrides workspace type selection logic.
40+
- `generatedFilesPath: string`: Directory in which generated interfaces and macro expansions should be stored.
41+
- `experimentalFeatures: string[]`: Experimental features to enable
42+
- `swiftPublishDiagnosticsDebounce`: The time that `SwiftLanguageService` should wait after an edit before starting to compute diagnostics and sending a `PublishDiagnosticsNotification`.

Documentation/LSP Extensions.md

-96
Original file line numberDiff line numberDiff line change
@@ -73,102 +73,6 @@ Added case
7373
identifier = 'identifier'
7474
```
7575
76-
## `WorkspaceFolder`
77-
78-
Added field:
79-
80-
```ts
81-
/**
82-
* Build settings that should be used for this workspace.
83-
*
84-
* For arguments that have a single value (like the build configuration), this takes precedence over the global
85-
* options set when launching sourcekit-lsp. For all other options, the values specified in the workspace-specific
86-
* build setup are appended to the global options.
87-
*/
88-
var buildSetup?: WorkspaceBuildSetup
89-
```
90-
91-
with
92-
93-
```ts
94-
/**
95-
* The configuration to build a workspace in.
96-
*/
97-
export enum BuildConfiguration {
98-
case debug = 'debug'
99-
case release = 'release'
100-
}
101-
102-
/**
103-
* The type of workspace; default workspace type selection logic can be overridden.
104-
*/
105-
export enum WorkspaceType {
106-
buildServer = 'buildServer'
107-
compilationDatabase = 'compilationDatabase'
108-
swiftPM = 'swiftPM'
109-
}
110-
111-
/// Build settings that should be used for a workspace.
112-
interface WorkspaceBuildSetup {
113-
/**
114-
* The configuration that the workspace should be built in.
115-
*/
116-
buildConfiguration?: BuildConfiguration
117-
118-
/**
119-
* The default workspace type to use for this workspace.
120-
*/
121-
defaultWorkspaceType?: WorkspaceType
122-
123-
/**
124-
* The build directory for the workspace.
125-
*/
126-
scratchPath?: DocumentURI
127-
128-
/**
129-
* Arguments to be passed to any C compiler invocations.
130-
*/
131-
cFlags?: string[]
132-
133-
/**
134-
* Arguments to be passed to any C++ compiler invocations.
135-
*/
136-
cxxFlags?: string[]
137-
138-
/**
139-
* Arguments to be passed to any linker invocations.
140-
*/
141-
linkerFlags?: string[]
142-
143-
/**
144-
* Arguments to be passed to any Swift compiler invocations.
145-
*/
146-
swiftFlags?: string[]
147-
}
148-
```
149-
150-
## `textDocument/completion`
151-
152-
Added field:
153-
154-
```ts
155-
/**
156-
* Options to control code completion behavior in Swift
157-
*/
158-
sourcekitlspOptions?: SKCompletionOptions
159-
```
160-
161-
with
162-
163-
```ts
164-
interface SKCompletionOptions {
165-
/**
166-
* The maximum number of completion results to return, or `null` for unlimited.
167-
*/
168-
maxResults?: int
169-
}
170-
```
171-
17276
## `textDocument/interface`
17377
17478
New request that request a textual interface of a module to display in the IDE. Used internally within SourceKit-LSP

Sources/Diagnose/IndexCommand.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public struct IndexCommand: AsyncParsableCommand {
8282
public init() {}
8383

8484
public func run() async throws {
85-
var serverOptions = SourceKitLSPServer.Options()
86-
serverOptions.experimentalFeatures = Set(experimentalFeatures)
87-
serverOptions.experimentalFeatures.insert(.backgroundIndexing)
85+
let options = SourceKitLSPOptions(
86+
backgroundIndexing: true,
87+
experimentalFeatures: Set(experimentalFeatures)
88+
)
8889

8990
let installPath =
9091
if let toolchainOverride, let toolchain = Toolchain(try AbsolutePath(validating: toolchainOverride)) {
@@ -96,7 +97,7 @@ public struct IndexCommand: AsyncParsableCommand {
9697
let messageHandler = IndexLogMessageHandler()
9798
let inProcessClient = try await InProcessSourceKitLSPClient(
9899
toolchainRegistry: ToolchainRegistry(installPath: installPath),
99-
serverOptions: serverOptions,
100+
options: options,
100101
workspaceFolders: [WorkspaceFolder(uri: DocumentURI(URL(fileURLWithPath: project)))],
101102
messageHandler: messageHandler
102103
)

Sources/InProcessClient/InProcessSourceKitLSPClient.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public final class InProcessSourceKitLSPClient: Sendable {
2626
/// `messageHandler` handles notifications and requests sent from the SourceKit-LSP server to the client.
2727
public init(
2828
toolchainRegistry: ToolchainRegistry,
29-
serverOptions: SourceKitLSPServer.Options = SourceKitLSPServer.Options(),
29+
options: SourceKitLSPOptions = SourceKitLSPOptions(),
30+
testHooks: TestHooks = TestHooks(),
3031
capabilities: ClientCapabilities = ClientCapabilities(),
3132
workspaceFolders: [WorkspaceFolder],
3233
messageHandler: any MessageHandler
@@ -35,7 +36,8 @@ public final class InProcessSourceKitLSPClient: Sendable {
3536
self.server = SourceKitLSPServer(
3637
client: serverToClientConnection,
3738
toolchainRegistry: toolchainRegistry,
38-
options: serverOptions,
39+
options: options,
40+
testHooks: testHooks,
3941
onExit: {
4042
serverToClientConnection.close()
4143
}

Sources/LanguageServerProtocol/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ add_library(LanguageServerProtocol STATIC
123123
SupportTypes/SemanticTokens.swift
124124
SupportTypes/SemanticTokenTypes.swift
125125
SupportTypes/ServerCapabilities.swift
126-
SupportTypes/SKCompletionOptions.swift
127126
SupportTypes/StringOrMarkupContent.swift
128127
SupportTypes/SymbolKind.swift
129128
SupportTypes/TestItem.swift

Sources/LanguageServerProtocol/Requests/CompletionRequest.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
/// - textDocument: The document to perform completion in.
2424
/// - position: The location to perform completion at.
2525
/// - context: Optional code-completion context.
26-
/// - sourcekitlspOptions: **(LSP Extension)** code-completion options for sourcekit-lsp.
2726
///
2827
/// - Returns: A list of completion items to complete the code at the given position.
2928
public struct CompletionRequest: TextDocumentRequest, Hashable {
@@ -36,18 +35,14 @@ public struct CompletionRequest: TextDocumentRequest, Hashable {
3635

3736
public var context: CompletionContext?
3837

39-
public var sourcekitlspOptions: SKCompletionOptions?
40-
4138
public init(
4239
textDocument: TextDocumentIdentifier,
4340
position: Position,
44-
context: CompletionContext? = nil,
45-
sourcekitlspOptions: SKCompletionOptions? = nil
41+
context: CompletionContext? = nil
4642
) {
4743
self.textDocument = textDocument
4844
self.position = position
4945
self.context = context
50-
self.sourcekitlspOptions = sourcekitlspOptions
5146
}
5247
}
5348

Sources/LanguageServerProtocol/Requests/PollIndexRequest.swift

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
/// Poll the index for unit changes and wait for them to be registered.
1414
/// **LSP Extension, For Testing**.
15-
///
16-
/// Users of PollIndex should set `"initializationOptions": { "listenToUnitEvents": false }` during
17-
/// the `initialize` request.
1815
public struct PollIndexRequest: RequestType {
1916
public static let method: String = "workspace/_pollIndex"
2017
public typealias Response = VoidResponse

Sources/LanguageServerProtocol/SupportTypes/SKCompletionOptions.swift

-31
This file was deleted.

Sources/LanguageServerProtocol/SupportTypes/WorkspaceFolder.swift

+1-74
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// The configuration to build a workspace in.
14-
///
15-
/// **(LSP Extension)**
16-
public enum BuildConfiguration: Hashable, Codable, Sendable {
17-
case debug
18-
case release
19-
}
20-
21-
/// The type of workspace; default workspace type selection logic can be overridden.
22-
///
23-
/// **(LSP Extension)**
24-
public enum WorkspaceType: Hashable, Codable, Sendable {
25-
case buildServer, compilationDatabase, swiftPM
26-
}
27-
28-
/// Build settings that should be used for a workspace.
29-
///
30-
/// **(LSP Extension)**
31-
public struct WorkspaceBuildSetup: Hashable, Codable, Sendable {
32-
/// The configuration that the workspace should be built in.
33-
public let buildConfiguration: BuildConfiguration?
34-
35-
/// The default workspace type to use for this workspace.
36-
public let defaultWorkspaceType: WorkspaceType?
37-
38-
/// The build directory for the workspace.
39-
public let scratchPath: DocumentURI?
40-
41-
/// Arguments to be passed to any C compiler invocations.
42-
public let cFlags: [String]?
43-
44-
/// Arguments to be passed to any C++ compiler invocations.
45-
public let cxxFlags: [String]?
46-
47-
/// Arguments to be passed to any linker invocations.
48-
public let linkerFlags: [String]?
49-
50-
/// Arguments to be passed to any Swift compiler invocations.
51-
public let swiftFlags: [String]?
52-
53-
public init(
54-
buildConfiguration: BuildConfiguration? = nil,
55-
defaultWorkspaceType: WorkspaceType? = nil,
56-
scratchPath: DocumentURI? = nil,
57-
cFlags: [String]? = nil,
58-
cxxFlags: [String]? = nil,
59-
linkerFlags: [String]? = nil,
60-
swiftFlags: [String]? = nil
61-
) {
62-
self.buildConfiguration = buildConfiguration
63-
self.defaultWorkspaceType = defaultWorkspaceType
64-
self.scratchPath = scratchPath
65-
self.cFlags = cFlags
66-
self.cxxFlags = cxxFlags
67-
self.linkerFlags = linkerFlags
68-
self.swiftFlags = swiftFlags
69-
}
70-
}
71-
7213
/// Unique identifier for a document.
7314
public struct WorkspaceFolder: ResponseType, Hashable, Codable, Sendable {
7415

@@ -78,27 +19,13 @@ public struct WorkspaceFolder: ResponseType, Hashable, Codable, Sendable {
7819
/// The name of the workspace (default: basename of url).
7920
public var name: String
8021

81-
/// Build settings that should be used for this workspace.
82-
///
83-
/// For arguments that have a single value (like the build configuration), this takes precedence over the global
84-
/// options set when launching sourcekit-lsp. For all other options, the values specified in the workspace-specific
85-
/// build setup are appended to the global options.
86-
///
87-
/// **(LSP Extension)**
88-
public var buildSetup: WorkspaceBuildSetup?
89-
90-
public init(
91-
uri: DocumentURI,
92-
name: String? = nil,
93-
buildSetup: WorkspaceBuildSetup? = nil
94-
) {
22+
public init(uri: DocumentURI, name: String? = nil) {
9523
self.uri = uri
9624

9725
self.name = name ?? uri.fileURL?.lastPathComponent ?? "unknown_workspace"
9826

9927
if self.name.isEmpty {
10028
self.name = "unknown_workspace"
10129
}
102-
self.buildSetup = buildSetup
10330
}
10431
}

0 commit comments

Comments
 (0)