Skip to content

Commit 41f8354

Browse files
authored
Merge pull request #1677 from ahoppen/require-6.0
Require a Swift 6 compiler to build SourceKit-LSP
2 parents bc17a9e + 7ab7c01 commit 41f8354

27 files changed

+114
-531
lines changed

Package.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22

33
import Foundation
44
import PackageDescription
@@ -405,8 +405,7 @@ let package = Package(
405405
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
406406
]
407407
),
408-
],
409-
swiftLanguageVersions: [.v5, .version("6")]
408+
]
410409
)
411410

412411
// MARK: - Parse build arguments

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,7 @@ package actor SwiftPMBuildSystem: BuiltInBuildSystem {
457457

458458
throw NonFileURIError(uri: file)
459459
}
460-
let compileArguments = try buildTarget.compileArguments(for: fileURL)
461-
462-
#if compiler(>=6.1)
463-
#warning("When we drop support for Swift 5.10 we no longer need to adjust compiler arguments for the Modules move")
464-
#endif
465-
// Fix up compiler arguments that point to a `/Modules` subdirectory if the Swift version in the toolchain is less
466-
// than 6.0 because it places the modules one level higher up.
467-
let toolchainVersion = await orLog("Getting Swift version") { try await toolchain.swiftVersion }
468-
guard let toolchainVersion, toolchainVersion < SwiftVersion(6, 0) else {
469-
return compileArguments
470-
}
471-
return compileArguments.map { argument in
472-
if argument.hasSuffix("/Modules"), argument.contains(self.swiftPMWorkspace.location.scratchDirectory.pathString) {
473-
return String(argument.dropLast(8))
474-
}
475-
return argument
476-
}
460+
return try buildTarget.compileArguments(for: fileURL)
477461
}
478462

479463
package func buildTargets(request: WorkspaceBuildTargetsRequest) async throws -> WorkspaceBuildTargetsResponse {

Sources/SKLogging/Logging.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ package typealias LogLevel = os.OSLogType
1919
package typealias Logger = os.Logger
2020
package typealias Signposter = OSSignposter
2121

22-
#if compiler(<5.11)
23-
extension OSSignposter: @unchecked Sendable {}
24-
extension OSSignpostID: @unchecked Sendable {}
25-
extension OSSignpostIntervalState: @unchecked Sendable {}
26-
#else
2722
extension OSSignposter: @retroactive @unchecked Sendable {}
2823
extension OSSignpostID: @retroactive @unchecked Sendable {}
2924
extension OSSignpostIntervalState: @retroactive @unchecked Sendable {}
30-
#endif
3125

3226
extension os.Logger {
3327
package func makeSignposter() -> Signposter {

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 0 additions & 329 deletions
Original file line numberDiff line numberDiff line change
@@ -106,304 +106,6 @@ package actor SkipUnless {
106106
}
107107
}
108108

109-
package static func sourcekitdHasSemanticTokensRequest(
110-
file: StaticString = #filePath,
111-
line: UInt = #line
112-
) async throws {
113-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
114-
let testClient = try await TestSourceKitLSPClient()
115-
let uri = DocumentURI(for: .swift)
116-
testClient.openDocument("0.bitPattern", uri: uri)
117-
let response = try unwrap(
118-
await testClient.send(DocumentSemanticTokensRequest(textDocument: TextDocumentIdentifier(uri)))
119-
)
120-
121-
let tokens = SyntaxHighlightingTokens(lspEncodedTokens: response.data)
122-
123-
// If we don't have semantic token support in sourcekitd, the second token is an identifier based on the syntax
124-
// tree, not a property.
125-
return tokens.tokens != [
126-
SyntaxHighlightingToken(
127-
range: Position(line: 0, utf16index: 0)..<Position(line: 0, utf16index: 1),
128-
kind: .number,
129-
modifiers: []
130-
),
131-
SourceKitLSP.SyntaxHighlightingToken(
132-
range: Position(line: 0, utf16index: 2)..<Position(line: 0, utf16index: 12),
133-
kind: .identifier,
134-
modifiers: []
135-
),
136-
]
137-
}
138-
}
139-
140-
package static func sourcekitdSupportsRename(
141-
file: StaticString = #filePath,
142-
line: UInt = #line
143-
) async throws {
144-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
145-
let testClient = try await TestSourceKitLSPClient()
146-
let uri = DocumentURI(for: .swift)
147-
let positions = testClient.openDocument("func 1️⃣test() {}", uri: uri)
148-
do {
149-
_ = try await testClient.send(
150-
RenameRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"], newName: "test2")
151-
)
152-
} catch let error as ResponseError {
153-
return error.message != "Running sourcekit-lsp with a version of sourcekitd that does not support rename"
154-
}
155-
return true
156-
}
157-
}
158-
159-
/// Checks whether the sourcekitd contains a fix to rename labels of enum cases correctly
160-
/// (https://github.com/apple/swift/pull/74241).
161-
package static func sourcekitdCanRenameEnumCaseLabels(
162-
file: StaticString = #filePath,
163-
line: UInt = #line
164-
) async throws {
165-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
166-
let testClient = try await TestSourceKitLSPClient()
167-
let uri = DocumentURI(for: .swift)
168-
let positions = testClient.openDocument(
169-
"""
170-
enum MyEnum {
171-
case 1️⃣myCase(2️⃣String)
172-
}
173-
""",
174-
uri: uri
175-
)
176-
177-
let renameResult = try await testClient.send(
178-
RenameRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"], newName: "myCase(label:)")
179-
)
180-
return renameResult?.changes == [uri: [TextEdit(range: Range(positions["2️⃣"]), newText: "label: ")]]
181-
}
182-
}
183-
184-
/// Whether clangd has support for the `workspace/indexedRename` request.
185-
package static func clangdSupportsIndexBasedRename(
186-
file: StaticString = #filePath,
187-
line: UInt = #line
188-
) async throws {
189-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
190-
let testClient = try await TestSourceKitLSPClient()
191-
let uri = DocumentURI(for: .c)
192-
let positions = testClient.openDocument("void 1️⃣test() {}", uri: uri)
193-
do {
194-
_ = try await testClient.send(
195-
IndexedRenameRequest(
196-
textDocument: TextDocumentIdentifier(uri),
197-
oldName: "test",
198-
newName: "test2",
199-
positions: [uri: [positions["1️⃣"]]]
200-
)
201-
)
202-
} catch let error as ResponseError {
203-
return error.message != "method not found"
204-
}
205-
return true
206-
}
207-
}
208-
209-
/// SwiftPM moved the location where it stores Swift modules to a subdirectory in
210-
/// https://github.com/swiftlang/swift-package-manager/pull/7103.
211-
package static func swiftpmStoresModulesInSubdirectory(
212-
file: StaticString = #filePath,
213-
line: UInt = #line
214-
) async throws {
215-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
216-
let workspace = try await SwiftPMTestProject(files: ["test.swift": ""])
217-
try await SwiftPMTestProject.build(at: workspace.scratchDirectory)
218-
let modulesDirectory = workspace.scratchDirectory
219-
.appendingPathComponent(".build")
220-
.appendingPathComponent("debug")
221-
.appendingPathComponent("Modules")
222-
.appendingPathComponent("MyLibrary.swiftmodule")
223-
return FileManager.default.fileExists(atPath: modulesDirectory.path)
224-
}
225-
}
226-
227-
package static func toolchainContainsSwiftFormat(
228-
file: StaticString = #filePath,
229-
line: UInt = #line
230-
) async throws {
231-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
232-
return await ToolchainRegistry.forTesting.default?.swiftFormat != nil
233-
}
234-
}
235-
236-
/// Checks if the toolchain contains https://github.com/apple/swift/pull/74080.
237-
package static func sourcekitdReportsOverridableFunctionDefinitionsAsDynamic(
238-
file: StaticString = #filePath,
239-
line: UInt = #line
240-
) async throws {
241-
struct ExpectedLocationsResponse: Error {}
242-
243-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
244-
let project = try await IndexedSingleSwiftFileTestProject(
245-
"""
246-
protocol TestProtocol {
247-
func 1️⃣doThing()
248-
}
249-
250-
struct TestImpl: TestProtocol {}
251-
extension TestImpl {
252-
func 2️⃣doThing() { }
253-
}
254-
"""
255-
)
256-
257-
let response = try await project.testClient.send(
258-
DefinitionRequest(textDocument: TextDocumentIdentifier(project.fileURI), position: project.positions["1️⃣"])
259-
)
260-
guard case .locations(let locations) = response else {
261-
throw ExpectedLocationsResponse()
262-
}
263-
return locations.contains { $0.range == Range(project.positions["2️⃣"]) }
264-
}
265-
}
266-
267-
package static func sourcekitdReturnsRawDocumentationResponse(
268-
file: StaticString = #filePath,
269-
line: UInt = #line
270-
) async throws {
271-
struct ExpectedMarkdownContentsError: Error {}
272-
273-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
274-
// The XML-based doc comment conversion did not preserve `Precondition`.
275-
let testClient = try await TestSourceKitLSPClient()
276-
let uri = DocumentURI(for: .swift)
277-
let positions = testClient.openDocument(
278-
"""
279-
/// - Precondition: Must have an apple
280-
func 1️⃣test() {}
281-
""",
282-
uri: uri
283-
)
284-
let response = try await testClient.send(
285-
HoverRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
286-
)
287-
let hover = try XCTUnwrap(response, file: file, line: line)
288-
XCTAssertNil(hover.range, file: file, line: line)
289-
guard case .markupContent(let content) = hover.contents else {
290-
throw ExpectedMarkdownContentsError()
291-
}
292-
return content.value.contains("Precondition")
293-
}
294-
}
295-
296-
/// Checks whether the index contains a fix that prevents it from adding relations to non-indexed locals
297-
/// (https://github.com/apple/swift/pull/72930).
298-
package static func indexOnlyHasContainedByRelationsToIndexedDecls(
299-
file: StaticString = #filePath,
300-
line: UInt = #line
301-
) async throws {
302-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
303-
let project = try await IndexedSingleSwiftFileTestProject(
304-
"""
305-
func foo() {}
306-
307-
func 1️⃣testFunc(x: String) {
308-
let myVar = foo
309-
}
310-
"""
311-
)
312-
let prepare = try await project.testClient.send(
313-
CallHierarchyPrepareRequest(
314-
textDocument: TextDocumentIdentifier(project.fileURI),
315-
position: project.positions["1️⃣"]
316-
)
317-
)
318-
let initialItem = try XCTUnwrap(prepare?.only)
319-
let calls = try await project.testClient.send(CallHierarchyOutgoingCallsRequest(item: initialItem))
320-
return calls != []
321-
}
322-
}
323-
324-
public static func swiftPMSupportsExperimentalPrepareForIndexing(
325-
file: StaticString = #filePath,
326-
line: UInt = #line
327-
) async throws {
328-
struct NoSwiftInToolchain: Error {}
329-
330-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
331-
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
332-
throw NoSwiftInToolchain()
333-
}
334-
335-
let result = try await Process.run(
336-
arguments: [swift.pathString, "build", "--help-hidden"],
337-
workingDirectory: nil
338-
)
339-
guard let output = String(bytes: try result.output.get(), encoding: .utf8) else {
340-
return false
341-
}
342-
return output.contains("--experimental-prepare-for-indexing")
343-
}
344-
}
345-
346-
package static func swiftPMStoresModulesForTargetAndHostInSeparateFolders(
347-
file: StaticString = #filePath,
348-
line: UInt = #line
349-
) async throws {
350-
struct NoSwiftInToolchain: Error {}
351-
352-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
353-
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
354-
throw NoSwiftInToolchain()
355-
}
356-
357-
let project = try await SwiftPMTestProject(
358-
files: [
359-
"Lib/MyFile.swift": """
360-
public func foo() {}
361-
""",
362-
"MyExec/MyExec.swift": """
363-
import Lib
364-
func bar() {
365-
foo()
366-
}
367-
""",
368-
"Plugins/MyPlugin/MyPlugin.swift": "",
369-
],
370-
manifest: """
371-
let package = Package(
372-
name: "MyLibrary",
373-
targets: [
374-
.target(name: "Lib"),
375-
.executableTarget(name: "MyExec", dependencies: ["Lib"]),
376-
.plugin(
377-
name: "MyPlugin",
378-
capability: .command(
379-
intent: .sourceCodeFormatting(),
380-
permissions: []
381-
),
382-
dependencies: ["MyExec"]
383-
)
384-
]
385-
)
386-
"""
387-
)
388-
do {
389-
// In older version of SwiftPM building `MyPlugin` followed by `Lib` resulted in an error about a redefinition
390-
// of Lib when building Lib.
391-
for target in ["MyPlugin", "Lib"] {
392-
var arguments = [
393-
swift.pathString, "build", "--package-path", project.scratchDirectory.path, "--target", target,
394-
]
395-
if let globalModuleCache {
396-
arguments += ["-Xswiftc", "-module-cache-path", "-Xswiftc", globalModuleCache.path]
397-
}
398-
try await Process.run(arguments: arguments, workingDirectory: nil)
399-
}
400-
return true
401-
} catch {
402-
return false
403-
}
404-
}
405-
}
406-
407109
/// A long test is a test that takes longer than 1-2s to execute.
408110
package static func longTestsEnabled() throws {
409111
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {
@@ -497,37 +199,6 @@ package actor SkipUnless {
497199
}
498200
}
499201
}
500-
501-
/// Checks if sourcekitd contains https://github.com/swiftlang/swift/pull/71049
502-
package static func solverBasedCursorInfoWorksForMemoryOnlyFiles(
503-
file: StaticString = #filePath,
504-
line: UInt = #line
505-
) async throws {
506-
struct ExpectedLocationsResponse: Error {}
507-
508-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
509-
let testClient = try await TestSourceKitLSPClient()
510-
let uri = DocumentURI(for: .swift)
511-
let positions = testClient.openDocument(
512-
"""
513-
func foo() -> Int { 1 }
514-
func foo() -> String { "" }
515-
func test() {
516-
_ = 3️⃣foo()
517-
}
518-
""",
519-
uri: uri
520-
)
521-
522-
let response = try await testClient.send(
523-
DefinitionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["3️⃣"])
524-
)
525-
guard case .locations(let locations) = response else {
526-
throw ExpectedLocationsResponse()
527-
}
528-
return locations.count > 0
529-
}
530-
}
531202
}
532203

533204
// MARK: - Parsing Swift compiler version

0 commit comments

Comments
 (0)