Skip to content

Commit d331206

Browse files
committed
Log the build system with which a workspace has been opened
I thought there was an issue with opening nested SwiftPM workspaces. Turns out there wasn’t but some logging and a test case don’t hurt. rdar://124727086
1 parent b3d2df7 commit d331206

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

Sources/SourceKitLSP/Workspace.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,18 @@ public final class Workspace {
145145
buildSystem = swiftpm
146146
} else if let compdb = buildCompDBWorkspace(rootPath: rootPath) {
147147
buildSystem = compdb
148+
} else {
149+
buildSystem = nil
150+
}
151+
if let buildSystem {
152+
let projectRoot = await buildSystem.projectRoot
153+
logger.log(
154+
"Opening workspace at \(rootUrl) as \(type(of: buildSystem)) with project root \(projectRoot.pathString)"
155+
)
148156
} else {
149157
logger.error(
150158
"Could not set up a build system for workspace at '\(rootUri.forLogging)'"
151159
)
152-
buildSystem = nil
153160
}
154161
} else {
155162
// We assume that workspaces are directories. This is only true for URLs not for URIs in general.

Tests/SourceKitLSPTests/SwiftPMIntegration.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,64 @@ final class SwiftPMIntegrationTests: XCTestCase {
181181
)
182182
XCTAssert(oldFileCompletions.items.contains(where: { $0.label == "baz(l: Lib)" }))
183183
}
184+
185+
func testNestedPackage() async throws {
186+
let ws = try await MultiFileTestWorkspace(files: [
187+
"pkg/Sources/lib/lib.swift": "",
188+
"pkg/Package.swift": """
189+
// swift-tools-version:4.2
190+
import PackageDescription
191+
let package = Package(name: "a", products: [], dependencies: [],
192+
targets: [.target(name: "lib", dependencies: [])])
193+
""",
194+
"nested/pkg/Sources/lib/a.swift.swift": """
195+
struct Foo {
196+
func bar() {}
197+
}
198+
""",
199+
"nested/pkg/Sources/lib/b.swift": """
200+
func test(foo: Foo) {
201+
foo.1️⃣
202+
}
203+
""",
204+
"nested/pkg/Package.swift": """
205+
// swift-tools-version:4.2
206+
import PackageDescription
207+
let package = Package(name: "a", products: [], dependencies: [],
208+
targets: [.target(name: "lib", dependencies: [])])
209+
""",
210+
])
211+
212+
let (uri, positions) = try ws.openDocument("b.swift")
213+
214+
let result = try await ws.testClient.send(
215+
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
216+
)
217+
218+
XCTAssertEqual(
219+
result.items,
220+
[
221+
CompletionItem(
222+
label: "bar()",
223+
kind: .method,
224+
detail: "Void",
225+
deprecated: false,
226+
filterText: "bar()",
227+
insertText: "bar()",
228+
insertTextFormat: .plain,
229+
textEdit: .textEdit(TextEdit(range: positions["1️⃣"]..<positions["1️⃣"], newText: "bar()"))
230+
),
231+
CompletionItem(
232+
label: "self",
233+
kind: .keyword,
234+
detail: "Foo",
235+
deprecated: false,
236+
filterText: "self",
237+
insertText: "self",
238+
insertTextFormat: .plain,
239+
textEdit: .textEdit(TextEdit(range: positions["1️⃣"]..<positions["1️⃣"], newText: "self"))
240+
),
241+
]
242+
)
243+
}
184244
}

0 commit comments

Comments
 (0)