Skip to content

Commit 12142c0

Browse files
committed
Remove configuration options from WorkspaceFolder
This extension was added for VS Code but never used. Let’s remove it in favor of workspace-specific configuration files.
1 parent 9c6a91d commit 12142c0

File tree

5 files changed

+2
-276
lines changed

5 files changed

+2
-276
lines changed

Documentation/LSP Extensions.md

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -73,80 +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-
15076
## `textDocument/completion`
15177
15278
Added field:

Sources/LanguageServerProtocol/SupportTypes/WorkspaceFolder.swift

Lines changed: 1 addition & 74 deletions
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
}

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -838,27 +838,6 @@ extension SourceKitLSPServer: BuildSystemDelegate {
838838
}
839839
}
840840

841-
extension LanguageServerProtocol.BuildConfiguration {
842-
/// Convert `LanguageServerProtocol.BuildConfiguration` to `SKSupport.BuildConfiguration`.
843-
var configuration: SKCore.BuildConfiguration {
844-
switch self {
845-
case .debug: return .debug
846-
case .release: return .release
847-
}
848-
}
849-
}
850-
851-
private extension LanguageServerProtocol.WorkspaceType {
852-
/// Convert `LanguageServerProtocol.WorkspaceType` to `SkSupport.WorkspaceType`.
853-
var workspaceType: SKCore.WorkspaceType {
854-
switch self {
855-
case .buildServer: return .buildServer
856-
case .compilationDatabase: return .compilationDatabase
857-
case .swiftPM: return .swiftPM
858-
}
859-
}
860-
}
861-
862841
extension SourceKitLSPServer {
863842
nonisolated func logMessageToIndexLog(taskID: IndexTaskID, message: String) {
864843
var message: Substring = message[...]
@@ -884,29 +863,6 @@ extension SourceKitLSPServer {
884863

885864
// MARK: - General
886865

887-
/// Returns the build setup for the parameters specified for the given `WorkspaceFolder`.
888-
private func buildSetup(for workspaceFolder: WorkspaceFolder) -> BuildSetup {
889-
let buildParams = workspaceFolder.buildSetup
890-
let scratchPath: AbsolutePath?
891-
if let scratchPathParam = buildParams?.scratchPath {
892-
scratchPath = try? AbsolutePath(validating: scratchPathParam.pseudoPath)
893-
} else {
894-
scratchPath = nil
895-
}
896-
return SKCore.BuildSetup(
897-
configuration: buildParams?.buildConfiguration?.configuration,
898-
defaultWorkspaceType: buildParams?.defaultWorkspaceType?.workspaceType,
899-
path: scratchPath,
900-
flags: BuildFlags(
901-
cCompilerFlags: buildParams?.cFlags ?? [],
902-
cxxCompilerFlags: buildParams?.cxxFlags ?? [],
903-
swiftCompilerFlags: buildParams?.swiftFlags ?? [],
904-
linkerFlags: buildParams?.linkerFlags ?? [],
905-
xcbuildFlags: []
906-
)
907-
)
908-
}
909-
910866
private func reloadPackageStatusCallback(_ status: ReloadPackageStatus) async {
911867
switch status {
912868
case .start:
@@ -927,8 +883,7 @@ extension SourceKitLSPServer {
927883
logger.log("Cannot open workspace before server is initialized")
928884
return nil
929885
}
930-
var options = self.options
931-
options.buildSetup = self.options.buildSetup.merging(buildSetup(for: workspaceFolder))
886+
let options = self.options
932887
let buildSystem = await createBuildSystem(
933888
rootUri: workspaceFolder.uri,
934889
options: options,

Sources/SourceKitLSP/Workspace.swift

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -255,45 +255,3 @@ struct WeakWorkspace {
255255
self.value = value
256256
}
257257
}
258-
259-
public struct IndexOptions: Sendable {
260-
261-
/// Override the index-store-path provided by the build system.
262-
public var indexStorePath: AbsolutePath?
263-
264-
/// Override the index-database-path provided by the build system.
265-
public var indexDatabasePath: AbsolutePath?
266-
267-
/// Override the index prefix mappings provided by the build system.
268-
public var indexPrefixMappings: [PathPrefixMapping]?
269-
270-
/// *For Testing* Whether the index should listen to unit events, or wait for
271-
/// explicit calls to pollForUnitChangesAndWait().
272-
public var listenToUnitEvents: Bool
273-
274-
/// The percentage of the machine's cores that should at most be used for background indexing.
275-
///
276-
/// Setting this to a value < 1 ensures that background indexing doesn't use all CPU resources.
277-
public var maxCoresPercentageToUseForBackgroundIndexing: Double
278-
279-
/// How long to wait until we cancel an update indexstore task. This timeout should be long enough that all
280-
/// `swift-frontend` tasks finish within it. It prevents us from blocking the index if the type checker gets stuck on
281-
/// an expression for a long time.
282-
public var updateIndexStoreTimeout: Duration
283-
284-
public init(
285-
indexStorePath: AbsolutePath? = nil,
286-
indexDatabasePath: AbsolutePath? = nil,
287-
indexPrefixMappings: [PathPrefixMapping]? = nil,
288-
listenToUnitEvents: Bool = true,
289-
maxCoresPercentageToUseForBackgroundIndexing: Double = 1,
290-
updateIndexStoreTimeout: Duration = .seconds(120)
291-
) {
292-
self.indexStorePath = indexStorePath
293-
self.indexDatabasePath = indexDatabasePath
294-
self.indexPrefixMappings = indexPrefixMappings
295-
self.listenToUnitEvents = listenToUnitEvents
296-
self.maxCoresPercentageToUseForBackgroundIndexing = maxCoresPercentageToUseForBackgroundIndexing
297-
self.updateIndexStoreTimeout = updateIndexStoreTimeout
298-
}
299-
}

Tests/SourceKitLSPTests/WorkspaceTests.swift

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -723,46 +723,6 @@ final class WorkspaceTests: XCTestCase {
723723
]
724724
)
725725
}
726-
727-
public func testWorkspaceSpecificBuildSettings() async throws {
728-
let project = try await SwiftPMTestProject(
729-
files: [
730-
"test.swift": """
731-
#if MY_FLAG
732-
let a: Int = ""
733-
#endif
734-
"""
735-
],
736-
workspaces: {
737-
[
738-
WorkspaceFolder(
739-
uri: DocumentURI($0),
740-
buildSetup: WorkspaceBuildSetup(
741-
buildConfiguration: nil,
742-
scratchPath: nil,
743-
cFlags: nil,
744-
cxxFlags: nil,
745-
linkerFlags: nil,
746-
swiftFlags: ["-DMY_FLAG"]
747-
)
748-
)
749-
]
750-
}
751-
)
752-
753-
_ = try project.openDocument("test.swift")
754-
let report = try await project.testClient.send(
755-
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(project.uri(for: "test.swift")))
756-
)
757-
guard case .full(let fullReport) = report else {
758-
XCTFail("Expected full diagnostics report")
759-
return
760-
}
761-
XCTAssertEqual(fullReport.items.count, 1)
762-
let diag = try XCTUnwrap(fullReport.items.first)
763-
XCTAssertEqual(diag.message, "Cannot convert value of type 'String' to specified type 'Int'")
764-
}
765-
766726
func testIntegrationTest() async throws {
767727
// This test is doing the same as `test-sourcekit-lsp` in the `swift-integration-tests` repo.
768728

0 commit comments

Comments
 (0)