Adopt swift-tools-protocols

This commit is contained in:
Owen Voorhees
2025-10-14 17:36:43 -07:00
parent a0c6c6ed91
commit f04b971726
457 changed files with 786 additions and 22198 deletions
+1
View File
@@ -31,6 +31,7 @@ find_package(SwiftCollections QUIET)
find_package(SwiftSyntax CONFIG REQUIRED)
find_package(SwiftASN1 CONFIG REQUIRED)
find_package(SwiftCrypto CONFIG REQUIRED)
find_package(SwiftToolsProtocols CONFIG REQUIRED)
include(SwiftSupport)
+96 -166
View File
@@ -20,8 +20,6 @@ var globalSwiftSettings: [SwiftSetting] {
var products: [Product] = [
.executable(name: "sourcekit-lsp", targets: ["sourcekit-lsp"]),
.library(name: "_SourceKitLSP", targets: ["SourceKitLSP"]),
.library(name: "BuildServerProtocol", targets: ["BuildServerProtocol"]),
.library(name: "LSPBindings", targets: ["LanguageServerProtocol", "LanguageServerProtocolJSONRPC"]),
.library(name: "InProcessClient", targets: ["InProcessClient"]),
.library(name: "SwiftSourceKitPlugin", type: .dynamic, targets: ["SwiftSourceKitPlugin"]),
.library(name: "SwiftSourceKitClientPlugin", type: .dynamic, targets: ["SwiftSourceKitClientPlugin"]),
@@ -42,13 +40,13 @@ var targets: [Target] = [
"BuildServerIntegration",
"Diagnose",
"InProcessClient",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"LanguageServerProtocolJSONRPC",
"SKOptions",
"SourceKitLSP",
"ToolchainRegistry",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
@@ -56,44 +54,24 @@ var targets: [Target] = [
linkerSettings: sourcekitLSPLinkSettings
),
// MARK: BuildServerProtocol
.target(
name: "BuildServerProtocol",
dependencies: [
"LanguageServerProtocol"
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "BuildServerProtocolTests",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: BuildServerIntegration
.target(
name: "BuildServerIntegration",
dependencies: [
"BuildServerProtocol",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SKOptions",
"SKUtilities",
"SourceKitD",
"SwiftExtensions",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "BuildServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
]
+ swiftPMDependency([
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
@@ -107,23 +85,16 @@ var targets: [Target] = [
name: "BuildServerIntegrationTests",
dependencies: [
"BuildServerIntegration",
"LanguageServerProtocol",
"SKOptions",
"SKTestSupport",
"SourceKitLSP",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
],
swiftSettings: globalSwiftSettings
),
// MARK: CAtomics
.target(
name: "CAtomics",
dependencies: []
),
.target(
name: "CCompletionScoring",
dependencies: []
@@ -135,15 +106,16 @@ var targets: [Target] = [
name: "ClangLanguageService",
dependencies: [
"BuildServerIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SKOptions",
"SourceKitLSP",
"SwiftExtensions",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
] + swiftSyntaxDependencies(["SwiftSyntax"]),
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -181,7 +153,11 @@ var targets: [Target] = [
.target(
name: "CompletionScoringTestSupport",
dependencies: ["CompletionScoring", "SwiftExtensions"],
dependencies: [
"CompletionScoring",
"SwiftExtensions",
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
resources: [.copy("INPUTS")],
swiftSettings: globalSwiftSettings
),
@@ -209,7 +185,6 @@ var targets: [Target] = [
"BuildServerIntegration",
"InProcessClient",
"LanguageServerProtocolExtensions",
"SKLogging",
"SKOptions",
"SKUtilities",
"SourceKitD",
@@ -218,7 +193,9 @@ var targets: [Target] = [
"ToolchainRegistry",
"TSCExtensions",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
] + swiftSyntaxDependencies(["SwiftIDEUtils", "SwiftSyntax", "SwiftParser"]),
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -229,10 +206,10 @@ var targets: [Target] = [
dependencies: [
"BuildServerIntegration",
"Diagnose",
"SKLogging",
"SKTestSupport",
"SourceKitD",
"ToolchainRegistry",
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
swiftSettings: globalSwiftSettings
@@ -244,15 +221,15 @@ var targets: [Target] = [
name: "DocumentationLanguageService",
dependencies: [
"BuildServerIntegration",
"BuildServerProtocol",
"LanguageServerProtocol",
"SemanticIndex",
"SKLogging",
"SKUtilities",
"SourceKitLSP",
"SwiftExtensions",
.product(name: "BuildServerProtocol", package: "swift-tools-protocols"),
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftDocC", package: "swift-docc"),
.product(name: "SymbolKit", package: "swift-docc-symbolkit"),
],
@@ -268,88 +245,51 @@ var targets: [Target] = [
"BuildServerIntegration",
"ClangLanguageService",
"DocumentationLanguageService",
"LanguageServerProtocol",
"SKLogging",
"SKOptions",
"SourceKitLSP",
"SwiftLanguageService",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
// MARK: LanguageServerProtocol
.target(
name: "LanguageServerProtocol",
dependencies: [],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "LanguageServerProtocolTests",
dependencies: [
"LanguageServerProtocol",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: LanguageServerProtocolExtensions
.target(
name: "LanguageServerProtocolExtensions",
dependencies: [
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SourceKitD",
"SwiftExtensions",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
// MARK: LanguageServerProtocolJSONRPC
.target(
name: "LanguageServerProtocolJSONRPC",
dependencies: [
"LanguageServerProtocol",
"SKLogging",
"SwiftExtensions",
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "LanguageServerProtocolJSONRPCTests",
dependencies: [
"LanguageServerProtocolJSONRPC",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: SemanticIndex
.target(
name: "SemanticIndex",
dependencies: [
"BuildServerProtocol",
"BuildServerIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"SKLogging",
"SwiftExtensions",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "BuildServerProtocol", package: "swift-tools-protocols"),
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -359,45 +299,9 @@ var targets: [Target] = [
name: "SemanticIndexTests",
dependencies: [
"SemanticIndex",
"SKLogging",
"SKTestSupport",
],
swiftSettings: globalSwiftSettings
),
// MARK: SKLogging
.target(
name: "SKLogging",
dependencies: [
"SwiftExtensions",
.product(name: "Crypto", package: "swift-crypto"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings + lspLoggingSwiftSettings
),
.target(
name: "SKLoggingForPlugin",
dependencies: [
"SwiftExtensionsForPlugin"
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings + lspLoggingSwiftSettings + [
// We can't depend on swift-crypto in the plugin because we can't module-alias it due to https://github.com/swiftlang/swift-package-manager/issues/8119
.define("NO_CRYPTO_DEPENDENCY"),
.define("SKLOGGING_FOR_PLUGIN"),
.unsafeFlags([
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
]),
]
),
.testTarget(
name: "SKLoggingTests",
dependencies: [
"SKLogging",
"SKTestSupport",
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
swiftSettings: globalSwiftSettings
),
@@ -407,9 +311,9 @@ var targets: [Target] = [
.target(
name: "SKOptions",
dependencies: [
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"SKLogging",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"],
@@ -421,8 +325,8 @@ var targets: [Target] = [
.target(
name: "SKUtilities",
dependencies: [
"SKLogging",
"SwiftExtensions",
.product(name: "SKLogging", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -431,14 +335,15 @@ var targets: [Target] = [
.target(
name: "SKUtilitiesForPlugin",
dependencies: [
"SKLoggingForPlugin",
"SwiftExtensionsForPlugin",
.product(name: "_SKLoggingForPlugin", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings + [
.unsafeFlags([
"-module-alias", "SKLogging=SKLoggingForPlugin",
"-module-alias", "SKLogging=_SKLoggingForPlugin",
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
])
]
),
@@ -461,10 +366,7 @@ var targets: [Target] = [
"CSKTestSupport",
"Csourcekitd",
"InProcessClient",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"LanguageServerProtocolJSONRPC",
"SKLogging",
"SKOptions",
"SKUtilities",
"SourceKitD",
@@ -473,7 +375,11 @@ var targets: [Target] = [
"SwiftLanguageService",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
resources: [.copy("INPUTS")],
swiftSettings: globalSwiftSettings
@@ -485,8 +391,9 @@ var targets: [Target] = [
name: "SourceKitD",
dependencies: [
"Csourcekitd",
"SKLogging",
"SwiftExtensions",
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
swiftSettings: globalSwiftSettings
@@ -496,14 +403,16 @@ var targets: [Target] = [
name: "SourceKitDForPlugin",
dependencies: [
"Csourcekitd",
"SKLoggingForPlugin",
"SwiftExtensionsForPlugin",
.product(name: "_SKLoggingForPlugin", package: "swift-tools-protocols"),
.product(name: "_ToolsProtocolsSwiftExtensionsForPlugin", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
swiftSettings: globalSwiftSettings + [
.unsafeFlags([
"-module-alias", "SKLogging=SKLoggingForPlugin",
"-module-alias", "SKLogging=_SKLoggingForPlugin",
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
])
]
),
@@ -516,6 +425,7 @@ var targets: [Target] = [
"SKTestSupport",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
swiftSettings: globalSwiftSettings
),
@@ -525,21 +435,22 @@ var targets: [Target] = [
.target(
name: "SourceKitLSP",
dependencies: [
"BuildServerProtocol",
"BuildServerIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"LanguageServerProtocolJSONRPC",
"SemanticIndex",
"SKLogging",
"SKOptions",
"SKUtilities",
"SourceKitD",
"SwiftExtensions",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "BuildServerProtocol", package: "swift-tools-protocols"),
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
] + swiftSyntaxDependencies(["SwiftSyntax"]),
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -548,12 +459,9 @@ var targets: [Target] = [
.testTarget(
name: "SourceKitLSPTests",
dependencies: [
"BuildServerProtocol",
"BuildServerIntegration",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"SemanticIndex",
"SKLogging",
"SKOptions",
"SKTestSupport",
"SKUtilities",
@@ -561,8 +469,12 @@ var targets: [Target] = [
"SourceKitLSP",
"SwiftLanguageService",
"ToolchainRegistry",
.product(name: "BuildServerProtocol", package: "swift-tools-protocols"),
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
// Depend on `SwiftCompilerPlugin` and `SwiftSyntaxMacros` so the modules are built before running tests and can
// be used by test cases that test macros (see `SwiftPMTestProject.macroPackageManifest`)
]
@@ -576,24 +488,33 @@ var targets: [Target] = [
.target(
name: "SwiftExtensions",
dependencies: ["CAtomics"],
dependencies: [
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols")
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
),
.target(
name: "SwiftExtensionsForPlugin",
dependencies: ["CAtomics"],
dependencies: [
.product(name: "_ToolsProtocolsSwiftExtensionsForPlugin", package: "swift-tools-protocols")
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
swiftSettings: globalSwiftSettings + [
.unsafeFlags([
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
])
]
),
.testTarget(
name: "SwiftExtensionsTests",
dependencies: [
"SKLogging",
"SKTestSupport",
"SwiftExtensions",
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
swiftSettings: globalSwiftSettings
),
@@ -603,14 +524,10 @@ var targets: [Target] = [
.target(
name: "SwiftLanguageService",
dependencies: [
"BuildServerProtocol",
"BuildServerIntegration",
"Csourcekitd",
"LanguageServerProtocol",
"LanguageServerProtocolExtensions",
"LanguageServerProtocolJSONRPC",
"SemanticIndex",
"SKLogging",
"SKOptions",
"SKUtilities",
"SourceKitD",
@@ -618,9 +535,14 @@ var targets: [Target] = [
"SwiftExtensions",
"ToolchainRegistry",
"TSCExtensions",
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "BuildServerProtocol", package: "swift-tools-protocols"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "IndexStoreDB", package: "indexstore-db"),
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
.product(name: "LanguageServerProtocolTransport", package: "swift-tools-protocols"),
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
]
+ swiftSyntaxDependencies([
"SwiftBasicFormat",
@@ -651,6 +573,7 @@ var targets: [Target] = [
.unsafeFlags([
"-module-alias", "SourceKitD=SourceKitDForPlugin",
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
])
],
linkerSettings: sourcekitLSPLinkSettings
@@ -664,14 +587,15 @@ var targets: [Target] = [
"Csourcekitd",
"SourceKitDForPlugin",
"SwiftExtensionsForPlugin",
"SKLoggingForPlugin",
.product(name: "_SKLoggingForPlugin", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings + [
.unsafeFlags([
"-module-alias", "SourceKitD=SourceKitDForPlugin",
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
"-module-alias", "SKLogging=SKLoggingForPlugin",
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
"-module-alias", "SKLogging=_SKLoggingForPlugin",
])
]
),
@@ -684,10 +608,11 @@ var targets: [Target] = [
"Csourcekitd",
"CompletionScoringForPlugin",
"SKUtilitiesForPlugin",
"SKLoggingForPlugin",
"SourceKitDForPlugin",
"SwiftSourceKitPluginCommon",
"SwiftExtensionsForPlugin",
.product(name: "_SKLoggingForPlugin", package: "swift-tools-protocols"),
.product(name: "_ToolsProtocolsSwiftExtensionsForPlugin", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings + [
@@ -695,8 +620,9 @@ var targets: [Target] = [
"-module-alias", "CompletionScoring=CompletionScoringForPlugin",
"-module-alias", "SKUtilities=SKUtilitiesForPlugin",
"-module-alias", "SourceKitD=SourceKitDForPlugin",
"-module-alias", "SKLogging=SKLoggingForPlugin",
"-module-alias", "SKLogging=_SKLoggingForPlugin",
"-module-alias", "SwiftExtensions=SwiftExtensionsForPlugin",
"-module-alias", "ToolsProtocolsSwiftExtensions=_ToolsProtocolsSwiftExtensionsForPlugin",
])
],
linkerSettings: sourcekitLSPLinkSettings
@@ -708,11 +634,11 @@ var targets: [Target] = [
"BuildServerIntegration",
"CompletionScoring",
"Csourcekitd",
"LanguageServerProtocol",
"SKTestSupport",
"SourceKitD",
"SwiftExtensions",
"ToolchainRegistry",
.product(name: "LanguageServerProtocol", package: "swift-tools-protocols"),
],
swiftSettings: globalSwiftSettings
),
@@ -722,10 +648,10 @@ var targets: [Target] = [
.target(
name: "ToolchainRegistry",
dependencies: [
"SKLogging",
"SKUtilities",
"SwiftExtensions",
"TSCExtensions",
.product(name: "SKLogging", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -745,9 +671,10 @@ var targets: [Target] = [
.target(
name: "TSCExtensions",
dependencies: [
"SKLogging",
"SwiftExtensions",
.product(name: "SKLogging", package: "swift-tools-protocols"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: globalSwiftSettings
@@ -759,6 +686,7 @@ var targets: [Target] = [
"SKTestSupport",
"SwiftExtensions",
"TSCExtensions",
.product(name: "ToolsProtocolsSwiftExtensions", package: "swift-tools-protocols"),
],
swiftSettings: globalSwiftSettings
),
@@ -858,6 +786,7 @@ var dependencies: [Package.Dependency] {
.package(path: "../swift-docc"),
.package(path: "../swift-docc-symbolkit"),
.package(path: "../swift-markdown"),
.package(path: "../swift-tools-protocols"),
.package(path: "../swift-tools-support-core"),
.package(path: "../swift-argument-parser"),
.package(path: "../swift-syntax"),
@@ -871,6 +800,7 @@ var dependencies: [Package.Dependency] {
.package(url: "https://github.com/swiftlang/swift-docc.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-markdown.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/swiftlang/swift-tools-protocols.git", exact: "0.0.8"),
.package(url: "https://github.com/swiftlang/swift-tools-support-core.git", branch: relatedDependenciesBranch),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.1"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", branch: relatedDependenciesBranch),
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
package import Foundation
package import LanguageServerProtocol
@_spi(SourceKitLSP) package import LanguageServerProtocol
package struct SwiftPMTestHooks: Sendable {
package var reloadPackageDidStart: (@Sendable () async -> Void)?
@@ -10,17 +10,19 @@
//
//===----------------------------------------------------------------------===//
package import BuildServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
import Dispatch
package import Foundation
package import LanguageServerProtocol
package import LanguageServerProtocolExtensions
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) package import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
package import SKOptions
import SKUtilities
package import SwiftExtensions
import SwiftExtensions
import TSCExtensions
package import ToolchainRegistry
@_spi(SourceKitLSP) package import ToolsProtocolsSwiftExtensions
import struct TSCBasic.RelativePath
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
package import BuildServerProtocol
package import LanguageServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
@_spi(SourceKitLSP) package import LanguageServerProtocol
/// Handles build server events, such as file build settings changes.
package protocol BuildServerManagerDelegate: AnyObject, Sendable {
@@ -10,10 +10,11 @@
//
//===----------------------------------------------------------------------===//
import BuildServerProtocol
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
@_spi(SourceKitLSP) import BuildServerProtocol
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
import SwiftExtensions
/// A lightweight way of describing tasks that are created from handling BSP
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
package import LanguageServerProtocol
package import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) package import SKLogging
import SwiftExtensions
// MARK: - Build settings logger
@@ -10,10 +10,10 @@
//
//===----------------------------------------------------------------------===//
package import BuildServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
import Foundation
import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) public import SKLogging
extension BuildTargetIdentifier {
package static let dummy: BuildTargetIdentifier = BuildTargetIdentifier(uri: try! URI(string: "dummy://dummy"))
@@ -146,7 +146,7 @@ extension BuildTargetIdentifier {
}
}
extension BuildTargetIdentifier: CustomLogStringConvertible {
@_spi(SourceKitLSP) extension BuildTargetIdentifier: @retroactive CustomLogStringConvertible {
package var description: String {
return uri.stringValue
}
@@ -10,10 +10,10 @@
//
//===----------------------------------------------------------------------===//
package import BuildServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
package import Foundation
package import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
import SKOptions
import ToolchainRegistry
@@ -10,14 +10,16 @@
//
//===----------------------------------------------------------------------===//
import BuildServerProtocol
@_spi(SourceKitLSP) import BuildServerProtocol
package import Foundation
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
import SKOptions
import SwiftExtensions
import ToolchainRegistry
import ToolsProtocolsSwiftExtensions
/// The details necessary to create a `BuildServerAdapter`.
package struct BuildServerSpec {
@@ -25,14 +25,15 @@ add_library(BuildServerIntegration STATIC
set_target_properties(BuildServerIntegration PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(BuildServerIntegration PUBLIC
BuildServerProtocol
LanguageServerProtocol
LanguageServerProtocolJSONRPC
SKLogging
SwiftToolsProtocols::BuildServerProtocol
SwiftToolsProtocols::LanguageServerProtocol
SwiftToolsProtocols::LanguageServerProtocolTransport
SwiftToolsProtocols::SKLogging
SKOptions
LanguageServerProtocolExtensions
SourceKitD
SwiftExtensions
SwiftToolsProtocols::ToolsProtocolsSwiftExtensions
ToolchainRegistry
PackageModel
TSCBasic
@@ -11,9 +11,9 @@
//===----------------------------------------------------------------------===//
package import Foundation
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import SKLogging
import SwiftExtensions
import TSCExtensions
@@ -11,8 +11,8 @@
//===----------------------------------------------------------------------===//
import Foundation
package import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
package import SKOptions
import SwiftExtensions
import TSCExtensions
@@ -10,12 +10,12 @@
//
//===----------------------------------------------------------------------===//
import BuildServerProtocol
@_spi(SourceKitLSP) import BuildServerProtocol
import Foundation
import LanguageServerProtocol
import LanguageServerProtocolExtensions
import LanguageServerProtocolJSONRPC
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
import SKOptions
import SwiftExtensions
import TSCExtensions
@@ -182,7 +182,7 @@ actor ExternalBuildServerAdapter {
executable: serverPath,
arguments: serverArgs,
name: "BSP-Server",
protocol: bspRegistry,
protocol: MessageRegistry.bspProtocol,
stderrLoggingCategory: "bsp-server-stderr",
client: messagesToSourceKitLSPHandler,
terminationHandler: { [weak self] terminationReason in
@@ -11,8 +11,8 @@
//===----------------------------------------------------------------------===//
import Foundation
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
package import SKOptions
import SwiftExtensions
import TSCExtensions
@@ -11,8 +11,8 @@
//===----------------------------------------------------------------------===//
import Foundation
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
/// Build settings for a single file.
///
@@ -10,10 +10,10 @@
//
//===----------------------------------------------------------------------===//
package import BuildServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
package import Foundation
package import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
import SwiftExtensions
func lastIndexStorePathArgument(in compilerArgs: [String]) -> String? {
@@ -10,10 +10,10 @@
//
//===----------------------------------------------------------------------===//
package import BuildServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
package import Foundation
package import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
import SwiftExtensions
package import ToolchainRegistry
@@ -10,15 +10,16 @@
//
//===----------------------------------------------------------------------===//
import BuildServerProtocol
@_spi(SourceKitLSP) import BuildServerProtocol
import Foundation
import LanguageServerProtocol
import LanguageServerProtocolExtensions
import LanguageServerProtocolJSONRPC
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
import SKOptions
import SwiftExtensions
import ToolchainRegistry
import ToolsProtocolsSwiftExtensions
#if compiler(>=6.5)
#warning("We have had a two year transition period to the pull based build server. Consider removing this build server")
@@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//
package import LanguageServerProtocol
@_spi(SourceKitLSP) package import LanguageServerProtocol
/// A type that can provide the set of main files that include a particular file.
package protocol MainFilesProvider: Sendable {
@@ -13,20 +13,21 @@
#if !NO_SWIFTPM_DEPENDENCY
import Basics
@preconcurrency import Build
package import BuildServerProtocol
@_spi(SourceKitLSP) package import BuildServerProtocol
import Dispatch
package import Foundation
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@preconcurrency import PackageGraph
import PackageLoading
@preconcurrency import PackageModel
import SKLogging
@_spi(SourceKitLSP) import SKLogging
package import SKOptions
@preconcurrency package import SPMBuildCore
import SourceControl
@preconcurrency package import SourceKitLSPAPI
import SwiftExtensions
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions
import TSCExtensions
package import ToolchainRegistry
@preconcurrency import Workspace
@@ -1,31 +0,0 @@
add_library(BuildServerProtocol STATIC
Messages.swift
Messages/BuildShutdownRequest.swift
Messages/BuildTargetPrepareRequest.swift
Messages/BuildTargetSourcesRequest.swift
Messages/CancelRequestNotification.swift
Messages/InitializeBuildRequest.swift
Messages/OnBuildExitNotification.swift
Messages/OnBuildInitializedNotification.swift
Messages/OnBuildLogMessageNotification.swift
Messages/OnBuildTargetDidChangeNotification.swift
Messages/OnWatchedFilesDidChangeNotification.swift
Messages/RegisterForChangeNotifications.swift
Messages/TaskFinishNotification.swift
Messages/TaskProgressNotification.swift
Messages/TaskStartNotification.swift
Messages/TextDocumentSourceKitOptionsRequest.swift
Messages/WorkspaceBuildTargetsRequest.swift
Messages/WorkspaceWaitForBuildSystemUpdates.swift
SupportTypes/BuildTarget.swift
SupportTypes/MessageType.swift
SupportTypes/MillisecondsSince1970Date.swift
SupportTypes/StatusCode.swift
SupportTypes/TaskId.swift
SupportTypes/TextDocumentIdentifier.swift)
set_target_properties(BuildServerProtocol PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(BuildServerProtocol PRIVATE
LanguageServerProtocol)
@@ -1,43 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
public protocol BSPRequest: RequestType {}
public protocol BSPNotification: NotificationType {}
private let requestTypes: [_RequestType.Type] = [
BuildShutdownRequest.self,
BuildTargetPrepareRequest.self,
BuildTargetSourcesRequest.self,
CreateWorkDoneProgressRequest.self,
InitializeBuildRequest.self,
RegisterForChanges.self,
TextDocumentSourceKitOptionsRequest.self,
WorkspaceBuildTargetsRequest.self,
WorkspaceWaitForBuildSystemUpdatesRequest.self,
]
private let notificationTypes: [NotificationType.Type] = [
CancelRequestNotification.self,
FileOptionsChangedNotification.self,
OnBuildExitNotification.self,
OnBuildInitializedNotification.self,
OnBuildLogMessageNotification.self,
OnBuildTargetDidChangeNotification.self,
OnWatchedFilesDidChangeNotification.self,
TaskFinishNotification.self,
TaskProgressNotification.self,
TaskStartNotification.self,
]
public let bspRegistry = MessageRegistry(requests: requestTypes, notifications: notificationTypes)
@@ -1,25 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// Like the language server protocol, the shutdown build request is
/// sent from the client to the server. It asks the server to shut down,
/// but to not exit (otherwise the response might not be delivered
/// correctly to the client). There is a separate exit notification
/// that asks the server to exit.
public struct BuildShutdownRequest: BSPRequest {
public static let method: String = "build/shutdown"
public typealias Response = VoidResponse
public init() {}
}
@@ -1,43 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
public typealias OriginId = String
/// The prepare build target request is sent from the client to the server to prepare the given list of build targets
/// for editor functionality.
///
/// To do so, the build server should perform any work that is necessary to typecheck the files in the given target.
/// This includes, but is not limited to: Building Swift modules for all dependencies and running code generation scripts.
/// Compared to a full build, the build server may skip actions that are not necessary for type checking, such as object
/// file generation but the exact steps necessary are dependent on the build system. SwiftPM implements this step using
/// the `swift build --experimental-prepare-for-indexing` command.
///
/// The server communicates during the initialize handshake whether this method is supported or not by setting
/// `prepareProvider: true` in `SourceKitInitializeBuildResponseData`.
public struct BuildTargetPrepareRequest: BSPRequest, Hashable {
public static let method: String = "buildTarget/prepare"
public typealias Response = VoidResponse
/// A list of build targets to prepare.
public var targets: [BuildTargetIdentifier]
/// A unique identifier generated by the client to identify this request.
/// The server may include this id in triggered notifications or responses.
public var originId: OriginId?
public init(targets: [BuildTargetIdentifier], originId: OriginId? = nil) {
self.targets = targets
self.originId = originId
}
}
@@ -1,219 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// The build target sources request is sent from the client to the server to
/// query for the list of text documents and directories that belong to a
/// build target. The sources response must not include sources that are
/// external to the workspace.
public struct BuildTargetSourcesRequest: BSPRequest, Hashable {
public static let method: String = "buildTarget/sources"
public typealias Response = BuildTargetSourcesResponse
public var targets: [BuildTargetIdentifier]
public init(targets: [BuildTargetIdentifier]) {
self.targets = targets
}
}
public struct BuildTargetSourcesResponse: ResponseType, Hashable {
public var items: [SourcesItem]
public init(items: [SourcesItem]) {
self.items = items
}
}
public struct SourcesItem: Codable, Hashable, Sendable {
public var target: BuildTargetIdentifier
/// The text documents and directories that belong to this build target.
public var sources: [SourceItem]
/// The root directories from where source files should be relativized.
/// Example: ["file://Users/name/dev/metals/src/main/scala"]
public var roots: [URI]?
public init(target: BuildTargetIdentifier, sources: [SourceItem], roots: [URI]? = nil) {
self.target = target
self.sources = sources
self.roots = roots
}
}
public struct SourceItem: Codable, Hashable, Sendable {
/// Either a text document or a directory. A directory entry must end with a
/// forward slash "/" and a directory entry implies that every nested text
/// document within the directory belongs to this source item.
public var uri: URI
/// Type of file of the source item, such as whether it is file or directory.
public var kind: SourceItemKind
/// Indicates if this source is automatically generated by the build and is
/// not intended to be manually edited by the user.
public var generated: Bool
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: SourceItemDataKind?
/// Language-specific metadata about this source item.
public var data: LSPAny?
/// If `dataKind` is `sourceKit`, the `data` interpreted as `SourceKitSourceItemData`, otherwise `nil`.
public var sourceKitData: SourceKitSourceItemData? {
guard dataKind == .sourceKit else {
return nil
}
return SourceKitSourceItemData(fromLSPAny: data)
}
public init(
uri: URI,
kind: SourceItemKind,
generated: Bool,
dataKind: SourceItemDataKind? = nil,
data: LSPAny? = nil
) {
self.uri = uri
self.kind = kind
self.generated = generated
self.dataKind = dataKind
self.data = data
}
}
public enum SourceItemKind: Int, Codable, Hashable, Sendable {
/// The source item references a normal file.
case file = 1
/// The source item references a directory.
case directory = 2
}
public struct SourceItemDataKind: RawRepresentable, Codable, Hashable, Sendable {
public var rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// `data` field must contain a JvmSourceItemData object.
public static let jvm = SourceItemDataKind(rawValue: "jvm")
/// `data` field must contain a `SourceKitSourceItemData` object.
///
/// **(BSP Extension)**
public static let sourceKit = SourceItemDataKind(rawValue: "sourceKit")
}
/// **(BSP Extension)**
public enum SourceKitSourceItemKind: String, Codable {
/// A source file that belongs to the target
case source = "source"
/// A header file that is clearly associated with one target.
///
/// For example header files in SwiftPM projects are always associated to one target and SwiftPM can provide build
/// settings for that header file.
///
/// In general, build servers don't need to list all header files in the `buildTarget/sources` request: Semantic
/// functionality for header files is usually provided by finding a main file that includes the header file and
/// inferring build settings from it. Listing header files in `buildTarget/sources` allows SourceKit-LSP to provide
/// semantic functionality for header files if they haven't been included by any main file.
case header = "header"
/// A SwiftDocC documentation catalog usually ending in the ".docc" extension.
case doccCatalog = "doccCatalog"
}
public struct SourceKitSourceItemData: LSPAnyCodable, Codable {
/// The language of the source file. If `nil`, the language is inferred from the file extension.
public var language: Language?
/// The kind of source file that this source item represents. If omitted, the item is assumed to be a normal source file,
/// ie. omitting this key is equivalent to specifying it as `source`.
public var kind: SourceKitSourceItemKind?
/// The output path that is used during indexing for this file, ie. the `-index-unit-output-path`, if it is specified
/// in the compiler arguments or the file that is passed as `-o`, if `-index-unit-output-path` is not specified.
///
/// This allows SourceKit-LSP to remove index entries for source files that are removed from a target but remain
/// present on disk.
///
/// The server communicates during the initialize handshake whether it populates this property by setting
/// `outputPathsProvider: true` in `SourceKitInitializeBuildResponseData`.
public var outputPath: String?
/// If this source item gets copied to a different destination during preparation, the destinations it will be copied
/// to.
///
/// If a user action would jump to one of these copied files, this allows SourceKit-LSP to redirect the navigation to
/// the original source file instead of jumping to a file in the build directory.
public var copyDestinations: [DocumentURI]?
public init(
language: Language? = nil,
kind: SourceKitSourceItemKind? = nil,
outputPath: String? = nil,
copyDestinations: [DocumentURI]? = nil
) {
self.language = language
self.kind = kind
self.outputPath = outputPath
self.copyDestinations = copyDestinations
}
public init?(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
if case .string(let language) = dictionary[CodingKeys.language.stringValue] {
self.language = Language(rawValue: language)
}
if case .string(let rawKind) = dictionary[CodingKeys.kind.stringValue] {
self.kind = SourceKitSourceItemKind(rawValue: rawKind)
}
// Backwards compatibility for isHeader
if case .bool(let isHeader) = dictionary["isHeader"], isHeader {
self.kind = .header
}
if case .string(let outputFilePath) = dictionary[CodingKeys.outputPath.stringValue] {
self.outputPath = outputFilePath
}
if case .array(let copyDestinations) = dictionary[CodingKeys.copyDestinations.stringValue] {
self.copyDestinations = copyDestinations.compactMap { entry in
guard case .string(let copyDestination) = entry else {
return nil
}
return try? DocumentURI(string: copyDestination)
}
}
}
public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
var result: [String: LSPAny] = [:]
if let language {
result[CodingKeys.language.stringValue] = .string(language.rawValue)
}
if let kind {
result[CodingKeys.kind.stringValue] = .string(kind.rawValue)
}
if let outputPath {
result[CodingKeys.outputPath.stringValue] = .string(outputPath)
}
if let copyDestinations {
result[CodingKeys.copyDestinations.stringValue] = .array(copyDestinations.map { .string($0.stringValue) })
}
return .dictionary(result)
}
}
@@ -1,15 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
extension CancelRequestNotification: BSPNotification {}
@@ -1,359 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// Like the language server protocol, the initialize request is sent
/// as the first request from the client to the server. If the server
/// receives a request or notification before the initialize request
/// it should act as follows:
///
/// - For a request the response should be an error with code: -32002.
/// The message can be picked by the server.
///
/// - Notifications should be dropped, except for the exit notification.
/// This will allow the exit of a server without an initialize request.
///
/// Until the server has responded to the initialize request with an
/// InitializeBuildResult, the client must not send any additional
/// requests or notifications to the server.
public struct InitializeBuildRequest: BSPRequest, Hashable {
public static let method: String = "build/initialize"
public typealias Response = InitializeBuildResponse
/// Name of the client
public var displayName: String
/// The version of the client
public var version: String
/// The BSP version that the client speaks=
public var bspVersion: String
/// The rootUri of the workspace
public var rootUri: URI
/// The capabilities of the client
public var capabilities: BuildClientCapabilities
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified. */
public var dataKind: InitializeBuildRequestDataKind?
/// Additional metadata about the client
public var data: LSPAny?
public init(
displayName: String,
version: String,
bspVersion: String,
rootUri: URI,
capabilities: BuildClientCapabilities,
dataKind: InitializeBuildRequestDataKind? = nil,
data: LSPAny? = nil
) {
self.displayName = displayName
self.version = version
self.bspVersion = bspVersion
self.rootUri = rootUri
self.capabilities = capabilities
self.dataKind = dataKind
self.data = data
}
}
public struct BuildClientCapabilities: Codable, Hashable, Sendable {
/// The languages that this client supports.
/// The ID strings for each language is defined in the LSP.
/// The server must never respond with build targets for other
/// languages than those that appear in this list.
public var languageIds: [Language]
/// Mirror capability to BuildServerCapabilities.jvmCompileClasspathProvider
/// The client will request classpath via `buildTarget/jvmCompileClasspath` so
/// it's safe to return classpath in ScalacOptionsItem empty. */
public var jvmCompileClasspathReceiver: Bool?
public init(languageIds: [Language], jvmCompileClasspathReceiver: Bool? = nil) {
self.languageIds = languageIds
self.jvmCompileClasspathReceiver = jvmCompileClasspathReceiver
}
}
public struct InitializeBuildRequestDataKind: RawRepresentable, Hashable, Codable, Sendable {
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
}
public struct InitializeBuildResponse: ResponseType, Hashable {
/// Name of the server
public var displayName: String
/// The version of the server
public var version: String
/// The BSP version that the server speaks
public var bspVersion: String
/// The capabilities of the build server
public var capabilities: BuildServerCapabilities
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: InitializeBuildResponseDataKind?
/// Optional metadata about the server
public var data: LSPAny?
public init(
displayName: String,
version: String,
bspVersion: String,
capabilities: BuildServerCapabilities,
dataKind: InitializeBuildResponseDataKind? = nil,
data: LSPAny? = nil
) {
self.displayName = displayName
self.version = version
self.bspVersion = bspVersion
self.capabilities = capabilities
self.dataKind = dataKind
self.data = data
}
}
public struct BuildServerCapabilities: Codable, Hashable, Sendable {
/// The languages the server supports compilation via method buildTarget/compile.
public var compileProvider: CompileProvider?
/// The languages the server supports test execution via method buildTarget/test
public var testProvider: TestProvider?
/// The languages the server supports run via method buildTarget/run
public var runProvider: RunProvider?
/// The languages the server supports debugging via method debugSession/start.
public var debugProvider: DebugProvider?
/// The server can provide a list of targets that contain a
/// single text document via the method buildTarget/inverseSources
public var inverseSourcesProvider: Bool?
/// The server provides sources for library dependencies
/// via method buildTarget/dependencySources
public var dependencySourcesProvider: Bool?
/// The server provides all the resource dependencies
/// via method buildTarget/resources
public var resourcesProvider: Bool?
/// The server provides all output paths
/// via method buildTarget/outputPaths
public var outputPathsProvider: Bool?
/// The server sends notifications to the client on build
/// target change events via `buildTarget/didChange`
public var buildTargetChangedProvider: Bool?
/// The server can respond to `buildTarget/jvmRunEnvironment` requests with the
/// necessary information required to launch a Java process to run a main class.
public var jvmRunEnvironmentProvider: Bool?
/// The server can respond to `buildTarget/jvmTestEnvironment` requests with the
/// necessary information required to launch a Java process for testing or
/// debugging.
public var jvmTestEnvironmentProvider: Bool?
/// The server can respond to `workspace/cargoFeaturesState` and
/// `setCargoFeatures` requests. In other words, supports Cargo Features extension.
public var cargoFeaturesProvider: Bool?
/// Reloading the build state through workspace/reload is supported
public var canReload: Bool?
/// The server can respond to `buildTarget/jvmCompileClasspath` requests with the
/// necessary information about the target's classpath.
public var jvmCompileClasspathProvider: Bool?
public init(
compileProvider: CompileProvider? = nil,
testProvider: TestProvider? = nil,
runProvider: RunProvider? = nil,
debugProvider: DebugProvider? = nil,
inverseSourcesProvider: Bool? = nil,
dependencySourcesProvider: Bool? = nil,
resourcesProvider: Bool? = nil,
outputPathsProvider: Bool? = nil,
buildTargetChangedProvider: Bool? = nil,
jvmRunEnvironmentProvider: Bool? = nil,
jvmTestEnvironmentProvider: Bool? = nil,
cargoFeaturesProvider: Bool? = nil,
canReload: Bool? = nil,
jvmCompileClasspathProvider: Bool? = nil
) {
self.compileProvider = compileProvider
self.testProvider = testProvider
self.runProvider = runProvider
self.debugProvider = debugProvider
self.inverseSourcesProvider = inverseSourcesProvider
self.dependencySourcesProvider = dependencySourcesProvider
self.resourcesProvider = resourcesProvider
self.outputPathsProvider = outputPathsProvider
self.buildTargetChangedProvider = buildTargetChangedProvider
self.jvmRunEnvironmentProvider = jvmRunEnvironmentProvider
self.jvmTestEnvironmentProvider = jvmTestEnvironmentProvider
self.cargoFeaturesProvider = cargoFeaturesProvider
self.canReload = canReload
self.jvmCompileClasspathProvider = jvmCompileClasspathProvider
}
}
public struct CompileProvider: Codable, Hashable, Sendable {
public var languageIds: [Language]
public init(languageIds: [Language]) {
self.languageIds = languageIds
}
}
public struct TestProvider: Codable, Hashable, Sendable {
public var languageIds: [Language]
public init(languageIds: [Language]) {
self.languageIds = languageIds
}
}
public struct RunProvider: Codable, Hashable, Sendable {
public var languageIds: [Language]
public init(languageIds: [Language]) {
self.languageIds = languageIds
}
}
public struct DebugProvider: Codable, Hashable, Sendable {
public var languageIds: [Language]
public init(languageIds: [Language]) {
self.languageIds = languageIds
}
}
public struct InitializeBuildResponseDataKind: RawRepresentable, Hashable, Codable, Sendable {
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// `data` field must contain a `SourceKitInitializeBuildResponseData` object.
public static let sourceKit = InitializeBuildResponseDataKind(rawValue: "sourceKit")
}
public struct SourceKitInitializeBuildResponseData: LSPAnyCodable, Codable, Sendable {
/// The directory to which the index store is written during compilation, ie. the path passed to `-index-store-path`
/// for `swiftc` or `clang` invocations
public var indexDatabasePath: String?
/// The path at which SourceKit-LSP can store its index database, aggregating data from `indexStorePath`
public var indexStorePath: String?
/// Whether the server implements the `buildTarget/outputPaths` request.
public var outputPathsProvider: Bool?
/// Whether the build server supports the `buildTarget/prepare` request.
public var prepareProvider: Bool?
/// Whether the server implements the `textDocument/sourceKitOptions` request.
public var sourceKitOptionsProvider: Bool?
/// The files to watch for changes.
public var watchers: [FileSystemWatcher]?
@available(*, deprecated, message: "Use initializer with alphabetical order of parameters")
@_disfavoredOverload
public init(
indexDatabasePath: String? = nil,
indexStorePath: String? = nil,
watchers: [FileSystemWatcher]? = nil,
prepareProvider: Bool? = nil,
sourceKitOptionsProvider: Bool? = nil
) {
self.indexDatabasePath = indexDatabasePath
self.indexStorePath = indexStorePath
self.watchers = watchers
self.prepareProvider = prepareProvider
self.sourceKitOptionsProvider = sourceKitOptionsProvider
}
public init(
indexDatabasePath: String? = nil,
indexStorePath: String? = nil,
outputPathsProvider: Bool? = nil,
prepareProvider: Bool? = nil,
sourceKitOptionsProvider: Bool? = nil,
watchers: [FileSystemWatcher]? = nil
) {
self.indexDatabasePath = indexDatabasePath
self.indexStorePath = indexStorePath
self.outputPathsProvider = outputPathsProvider
self.prepareProvider = prepareProvider
self.sourceKitOptionsProvider = sourceKitOptionsProvider
self.watchers = watchers
}
public init?(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
if case .string(let indexDatabasePath) = dictionary[CodingKeys.indexDatabasePath.stringValue] {
self.indexDatabasePath = indexDatabasePath
}
if case .string(let indexStorePath) = dictionary[CodingKeys.indexStorePath.stringValue] {
self.indexStorePath = indexStorePath
}
if case .bool(let outputPathsProvider) = dictionary[CodingKeys.outputPathsProvider.stringValue] {
self.outputPathsProvider = outputPathsProvider
}
if case .bool(let prepareProvider) = dictionary[CodingKeys.prepareProvider.stringValue] {
self.prepareProvider = prepareProvider
}
if case .bool(let sourceKitOptionsProvider) = dictionary[CodingKeys.sourceKitOptionsProvider.stringValue] {
self.sourceKitOptionsProvider = sourceKitOptionsProvider
}
if let watchers = dictionary[CodingKeys.watchers.stringValue] {
self.watchers = [FileSystemWatcher](fromLSPArray: watchers)
}
}
public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
var result: [String: LSPAny] = [:]
if let indexDatabasePath {
result[CodingKeys.indexDatabasePath.stringValue] = .string(indexDatabasePath)
}
if let indexStorePath {
result[CodingKeys.indexStorePath.stringValue] = .string(indexStorePath)
}
if let outputPathsProvider {
result[CodingKeys.outputPathsProvider.stringValue] = .bool(outputPathsProvider)
}
if let prepareProvider {
result[CodingKeys.prepareProvider.stringValue] = .bool(prepareProvider)
}
if let sourceKitOptionsProvider {
result[CodingKeys.sourceKitOptionsProvider.stringValue] = .bool(sourceKitOptionsProvider)
}
if let watchers {
result[CodingKeys.watchers.stringValue] = watchers.encodeToLSPAny()
}
return .dictionary(result)
}
}
@@ -1,21 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
/// Like the language server protocol, a notification to ask the
/// server to exit its process. The server should exit with success
/// code 0 if the shutdown request has been received before;
/// otherwise with error code 1.
public struct OnBuildExitNotification: BSPNotification {
public static let method: String = "build/exit"
public init() {}
}
@@ -1,18 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
/// Like the language server protocol, the initialized notification is sent from the client to the server after the client received the result of the initialize request but before the client is sending any other request or notification to the server. The server can use the initialized notification for example to initialize intensive computation such as dependency resolution or compilation. The initialized notification may only be sent once.
public struct OnBuildInitializedNotification: BSPNotification {
public static let method: String = "build/initialized"
public init() {}
}
@@ -1,172 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
/// The log message notification is sent from a server to a client to ask the client to log a particular message in its console.
///
/// A `build/logMessage`` notification is similar to LSP's `window/logMessage``, except for a few additions like id and originId.
public struct OnBuildLogMessageNotification: BSPNotification {
public static let method: String = "build/logMessage"
/// The message type.
public var type: MessageType
/// The task id if any.
public var task: TaskId?
/// The request id that originated this notification.
/// The originId field helps clients know which request originated a notification in case several requests are handled by the
/// client at the same time. It will only be populated if the client defined it in the request that triggered this notification.
public var originId: OriginId?
/// The actual message.
public var message: String
/// Extends BSPs log message grouping by explicitly starting and ending the log for a specific task ID.
///
/// **(BSP Extension)***
public var structure: StructuredLogKind?
public init(
type: MessageType,
task: TaskId? = nil,
originId: OriginId? = nil,
message: String,
structure: StructuredLogKind? = nil
) {
self.type = type
self.task = task
self.originId = originId
self.message = message
self.structure = structure
}
}
public enum StructuredLogKind: Codable, Hashable, Sendable {
case begin(StructuredLogBegin)
case report(StructuredLogReport)
case end(StructuredLogEnd)
public init(from decoder: Decoder) throws {
if let begin = try? StructuredLogBegin(from: decoder) {
self = .begin(begin)
} else if let report = try? StructuredLogReport(from: decoder) {
self = .report(report)
} else if let end = try? StructuredLogEnd(from: decoder) {
self = .end(end)
} else {
let context = DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Expected StructuredLogBegin, StructuredLogReport, or StructuredLogEnd"
)
throw DecodingError.dataCorrupted(context)
}
}
public func encode(to encoder: Encoder) throws {
switch self {
case .begin(let begin):
try begin.encode(to: encoder)
case .report(let report):
try report.encode(to: encoder)
case .end(let end):
try end.encode(to: encoder)
}
}
}
/// Indicates the beginning of a new task that may receive updates with `StructuredLogReport` or `StructuredLogEnd`
/// payloads.
public struct StructuredLogBegin: Codable, Hashable, Sendable {
/// A succinct title that can be used to describe the task that started this structured.
public var title: String
private enum CodingKeys: CodingKey {
case kind
case title
}
public init(title: String) {
self.title = title
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard try container.decode(String.self, forKey: .kind) == "begin" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of StructuredLogBegin is not 'begin'"
)
}
self.title = try container.decode(String.self, forKey: .title)
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("begin", forKey: .kind)
try container.encode(self.title, forKey: .title)
}
}
/// Adds a new log message to a structured log without ending it.
public struct StructuredLogReport: Codable, Hashable, Sendable {
private enum CodingKeys: CodingKey {
case kind
}
public init() {}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard try container.decode(String.self, forKey: .kind) == "report" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of StructuredLogReport is not 'report'"
)
}
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("report", forKey: .kind)
}
}
/// Ends a structured log. No more `StructuredLogReport` updates should be sent for this task ID.
///
/// The task ID may be re-used for new structured logs by beginning a new structured log for that task.
public struct StructuredLogEnd: Codable, Hashable, Sendable {
private enum CodingKeys: CodingKey {
case kind
}
public init() {}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard try container.decode(String.self, forKey: .kind) == "end" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of StructuredLogEnd is not 'end'"
)
}
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("end", forKey: .kind)
}
}
@@ -1,73 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// The build target changed notification is sent from the server to the client
/// to signal a change in a build target. The server communicates during the
/// initialize handshake whether this method is supported or not.
public struct OnBuildTargetDidChangeNotification: BSPNotification, Equatable {
public static let method: String = "buildTarget/didChange"
/// **(BSP Extension)**
/// `changes` can be `nil` to indicate that all targets might have changed.
public var changes: [BuildTargetEvent]?
public init(changes: [BuildTargetEvent]?) {
self.changes = changes
}
}
public struct BuildTargetEvent: Codable, Hashable, Sendable {
/// The identifier for the changed build target.
public var target: BuildTargetIdentifier
/// The kind of change for this build target.
public var kind: BuildTargetEventKind?
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: BuildTargetEventDataKind?
/// Any additional metadata about what information changed.
public var data: LSPAny?
public init(
target: BuildTargetIdentifier,
kind: BuildTargetEventKind?,
dataKind: BuildTargetEventDataKind?,
data: LSPAny?
) {
self.target = target
self.kind = kind
self.dataKind = dataKind
self.data = data
}
}
public enum BuildTargetEventKind: Int, Codable, Hashable, Sendable {
/// The build target is new.
case created = 1
/// The build target has changed.
case changed = 2
/// The build target has been deleted.
case deleted = 3
}
public struct BuildTargetEventDataKind: RawRepresentable, Codable, Hashable, Sendable {
public var rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
}
@@ -1,18 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// Notification sent from SourceKit-LSP to the build server to indicate that files within the project have been modified.
public typealias OnWatchedFilesDidChangeNotification = LanguageServerProtocol.DidChangeWatchedFilesNotification
extension OnWatchedFilesDidChangeNotification: BSPNotification {}
@@ -1,67 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// The register for changes request is sent from the language
/// server to the build server to register or unregister for
/// changes in file options or dependencies. On changes a
/// FileOptionsChangedNotification is sent.
///
/// - Important: This request has been deprecated. Build servers should instead implement the
/// `textDocument/sourceKitOptions` request.
/// See https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400
public struct RegisterForChanges: BSPRequest {
public static let method: String = "textDocument/registerForChanges"
public typealias Response = VoidResponse
/// The URI of the document to get options for.
public var uri: URI
/// Whether to register or unregister for the file.
public var action: RegisterAction
public init(uri: URI, action: RegisterAction) {
self.uri = uri
self.action = action
}
}
public enum RegisterAction: String, Hashable, Codable, Sendable {
case register = "register"
case unregister = "unregister"
}
/// The FileOptionsChangedNotification is sent from the
/// build server to the language server when it detects
/// changes to a registered files build settings.
///
/// - Important: This request has been deprecated. Build servers should instead implement the
/// `textDocument/sourceKitOptions` request.
/// See https://forums.swift.org/t/extending-functionality-of-build-server-protocol-with-sourcekit-lsp/74400
public struct FileOptionsChangedNotification: BSPNotification {
public struct Options: ResponseType, Hashable {
/// The compiler options required for the requested file.
public var options: [String]
/// The working directory for the compile command.
public var workingDirectory: String?
}
public static let method: String = "build/sourceKitOptionsChanged"
/// The URI of the document that has changed settings.
public var uri: URI
/// The updated options for the registered file.
public var updatedOptions: Options
}
@@ -1,240 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import Foundation
public import LanguageServerProtocol
/// A `build/taskFinish` notification must always be sent after a `build/taskStart`` with the same `taskId` was sent.
public struct TaskFinishNotification: BSPNotification {
public static let method: String = "build/taskFinish"
/// Unique id of the task with optional reference to parent task id.
public var taskId: TaskId
/// A unique identifier generated by the client to identify this request.
public var originId: String?
/// Timestamp of when the event started in milliseconds since Epoch.
@CustomCodable<MillisecondsSince1970Date?>
public var eventTime: Date?
/// Message describing the task.
public var message: String?
/// Task completion status.
public var status: StatusCode
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: TaskFinishDataKind?
/// Optional metadata about the task.
///
/// Objects for specific tasks like compile, test, etc are specified in the protocol.
public var data: LSPAny?
public init(
taskId: TaskId,
originId: String? = nil,
eventTime: Date? = nil,
message: String? = nil,
status: StatusCode,
dataKind: TaskFinishDataKind? = nil,
data: LSPAny? = nil
) {
self.taskId = taskId
self.originId = originId
self.eventTime = eventTime
self.message = message
self.status = status
self.dataKind = dataKind
self.data = data
}
}
/// Task finish notifications may contain an arbitrary interface in their `data` field.
///
/// The kind of interface that is contained in a notification must be specified in the `dataKind` field.
public struct TaskFinishDataKind: RawRepresentable, Codable, Hashable, Sendable {
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// `data` field must contain a `CompileReport` object.
public static let compileReport = TaskStartDataKind(rawValue: "compile-report")
/// `data` field must contain a `TestFinish` object.
public static let testFinish = TaskStartDataKind(rawValue: "test-finish")
/// `data` field must contain a `TestReport` object.
public static let testReport = TaskStartDataKind(rawValue: "test-report")
}
/// This structure is embedded in the `TaskFinishNotification.data` field, when the `dataKind` field contains
/// `"compile-report"`.
///
/// The completion of a compilation task should be signalled with a `build/taskFinish` notification. When the
/// compilation unit is a build target, the notification's `dataKind` field must be `compile-report` and the `data`
/// field must include a `CompileReportData` object.
public struct CompileReportData: Codable, Hashable, Sendable {
/// The build target that was compiled.
public var target: BuildTargetIdentifier
/// An optional request id to know the origin of this report.
///
/// Deprecated: Use the field in TaskFinishParams instead .
public var originId: String?
/// The total number of reported errors compiling this target.
public var errors: Int
/// The total number of reported warnings compiling the target.
public var warnings: Int
/// The total number of milliseconds it took to compile the target.
@CustomCodable<MillisecondsSince1970Date?>
public var time: Date?
/// The compilation was a noOp compilation.
public var noOp: Bool?
public init(
target: BuildTargetIdentifier,
originId: String? = nil,
errors: Int,
warnings: Int,
time: Date? = nil,
noOp: Bool? = nil
) {
self.target = target
self.originId = originId
self.errors = errors
self.warnings = warnings
self.time = time
self.noOp = noOp
}
}
/// This structure is embedded in the `TaskFinishNotification.data` field, when the `dataKind` field contains
/// `"test-finish"`.
public struct TestFinishData: Codable, Hashable, Sendable {
/// Name or description of the test.
public var displayName: String?
/// Information about completion of the test, for example an error message.
public var message: String?
/// Completion status of the test.
public var status: TestStatus
/// Source location of the test, as LSP location.
public var location: Location?
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: TestFinishDataKind?
/// Optionally, structured metadata about the test completion.
/// For example: stack traces, expected/actual values.
public var data: LSPAny?
public init(
displayName: String? = nil,
message: String? = nil,
status: TestStatus,
location: Location? = nil,
dataKind: TestFinishDataKind? = nil,
data: LSPAny? = nil
) {
self.displayName = displayName
self.message = message
self.status = status
self.location = location
self.dataKind = dataKind
self.data = data
}
}
public enum TestStatus: Int, Codable, Hashable, Sendable {
/// The test passed successfully.
case passed = 1
/// The test failed.
case failed = 2
/// The test was marked as ignored.
case ignored = 3
/// The test execution was cancelled.
case cancelled = 4
/// The was not included in execution.
case skipped = 5
}
public struct TestFinishDataKind: RawRepresentable, Codable, Hashable, Sendable {
public var rawValue: String
public init?(rawValue: String) {
self.rawValue = rawValue
}
}
/// This structure is embedded in the `TaskFinishNotification.data` field, when the `dataKind` field contains
/// `"test-report"`.
public struct TestReportData: Codable, Hashable, Sendable {
/// Deprecated: Use the field in TaskFinishParams instead
public var originId: String?
/// The build target that was compiled.
public var target: BuildTargetIdentifier
/// The total number of successful tests.
public var passed: Int
/// The total number of failed tests.
public var failed: Int
/// The total number of ignored tests.
public var ignored: Int
/// The total number of cancelled tests.
public var cancelled: Int
/// The total number of skipped tests.
public var skipped: Int
/// The total number of milliseconds tests take to run (e.g. doesn't include compile times).
public var time: Int64?
public init(
originId: String? = nil,
target: BuildTargetIdentifier,
passed: Int,
failed: Int,
ignored: Int,
cancelled: Int,
skipped: Int,
time: Int64? = nil
) {
self.originId = originId
self.target = target
self.passed = passed
self.failed = failed
self.ignored = ignored
self.cancelled = cancelled
self.skipped = skipped
self.time = time
}
}
@@ -1,82 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import Foundation
public import LanguageServerProtocol
/// After a `taskStart` and before `taskFinish` for a `taskId`, the server may send any number of progress
/// notifications.
public struct TaskProgressNotification: BSPNotification {
public static let method: String = "build/taskProgress"
/// Unique id of the task with optional reference to parent task id
public var taskId: TaskId
/// A unique identifier generated by the client to identify this request.
public var originId: String?
/// Timestamp of when the event started in milliseconds since Epoch.
@CustomCodable<MillisecondsSince1970Date?>
public var eventTime: Date?
/// Message describing the task.
public var message: String?
/// If known, total amount of work units in this task.
public var total: Int?
/// If known, completed amount of work units in this task.
public var progress: Int?
/// Name of a work unit. For example, "files" or "tests". May be empty.
public var unit: String?
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: TaskProgressDataKind?
/// Optional metadata about the task.
///
/// Objects for specific tasks like compile, test, etc are specified in the protocol.
public var data: LSPAny?
public init(
taskId: TaskId,
originId: String? = nil,
eventTime: Date? = nil,
message: String? = nil,
total: Int? = nil,
progress: Int? = nil,
unit: String? = nil,
dataKind: TaskProgressDataKind? = nil,
data: LSPAny? = nil
) {
self.taskId = taskId
self.originId = originId
self.eventTime = eventTime
self.message = message
self.total = total
self.progress = progress
self.unit = unit
self.dataKind = dataKind
self.data = data
}
}
/// Task progress notifications may contain an arbitrary interface in their `data` field.
///
/// The kind of interface that is contained in a notification must be specified in the `dataKind` field.
public struct TaskProgressDataKind: RawRepresentable, Codable, Hashable, Sendable {
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
}
@@ -1,158 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import Foundation
public import LanguageServerProtocol
/// The BSP server can inform the client on the execution state of any task in the build tool.
/// The execution of some tasks, such as compilation or tests, must always be reported by the server.
///
/// The server may also send additional task notifications for actions not covered by the protocol, such as resolution
/// or packaging. BSP clients can then display this information to their users at their discretion.
///
/// When beginning a task, the server may send `build/taskStart`, intermediate updates may be sent in
/// `build/taskProgress`.
///
/// If a `build/taskStart` notification has been sent, the server must send build/taskFinish on completion of the same
/// task.
///
/// `build/taskStart`, `build/taskProgress` and `build/taskFinish` notifications for the same task must use the same
/// `taskId`.
///
/// Tasks that are spawned by another task should reference the originating task's `taskId` in their own `taskId`'s
/// `parent` field. Tasks spawned directly by a request should reference the request's `originId` parent.
public struct TaskStartNotification: BSPNotification {
public static let method: String = "build/taskStart"
/// Unique id of the task with optional reference to parent task id
public var taskId: TaskId
/// A unique identifier generated by the client to identify this request.
public var originId: String?
/// Timestamp of when the event started in milliseconds since Epoch.
@CustomCodable<MillisecondsSince1970Date?>
public var eventTime: Date?
/// Message describing the task.
public var message: String?
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: TaskStartDataKind?
/// Optional metadata about the task.
// Objects for specific tasks like compile, test, etc are specified in the protocol.
public var data: LSPAny?
public init(
taskId: TaskId,
originId: String? = nil,
eventTime: Date? = nil,
message: String? = nil,
dataKind: TaskStartDataKind? = nil,
data: LSPAny? = nil
) {
self.taskId = taskId
self.originId = originId
self.eventTime = eventTime
self.message = message
self.dataKind = dataKind
self.data = data
}
}
/// Task start notifications may contain an arbitrary interface in their `data` field.
///
/// The kind of interface that is contained in a notification must be specified in the `dataKind` field.
public struct TaskStartDataKind: RawRepresentable, Codable, Hashable, Sendable {
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// `data` field must contain a `CompileTaskData` object.
public static let compileTask = TaskStartDataKind(rawValue: "compile-task")
/// `data` field must contain a `TestStart` object.
public static let testStart = TaskStartDataKind(rawValue: "test-start")
/// `data` field must contain a `TestTask` object.
public static let testTask = TaskStartDataKind(rawValue: "test-task")
}
/// This structure is embedded in the `TaskStartNotification.data` field, when the `dataKind` field contains
/// "compile-task".
///
/// The beginning of a compilation unit may be signalled to the client with a `build/taskStart` notification.
///
/// When the compilation unit is a build target, the notification's `dataKind` field must be "compile-task" and the
/// `data` field must include a `CompileTaskData` object
public struct CompileTaskData: Codable, Hashable, Sendable {
public var target: BuildTargetIdentifier
public init(target: BuildTargetIdentifier) {
self.target = target
}
}
/// This structure is embedded in the `TaskStartNotification.data` field, when the `dataKind` field contains
/// "test-start".
public struct TestStartData: Codable, Hashable, Sendable {
/// Name or description of the test.
public var displayName: String
/// Source location of the test, as LSP location.
public var location: Location?
public init(displayName: String, location: Location? = nil) {
self.displayName = displayName
self.location = location
}
}
/// This structure is embedded in the `TaskStartNotification.data` field, when the `dataKind` field contains
/// "test-task".
///
/// The beginning of a testing unit may be signalled to the client with a `build/taskStart`` notification.
/// When the testing unit is a build target, the notification's `dataKind` field must be `test-task` and the `data`
/// field must include a `TestTaskData` object.
public struct TestTaskData: Codable, Hashable, Sendable {
public var target: BuildTargetIdentifier
public init(target: BuildTargetIdentifier) {
self.target = target
}
}
/// If `data` contains a string value for the `workDoneProgressTitle` key, then the task's message will be displayed in
/// the client as a work done progress with that title.
public struct WorkDoneProgressTask: LSPAnyCodable {
/// The title with which the work done progress should be created in the client.
public let title: String
public init(title: String) {
self.title = title
}
public init?(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
guard case .string(let title) = dictionary["workDoneProgressTitle"] else {
return nil
}
self.title = title
}
public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
return .dictionary([
"workDoneProgressTitle": .string(title)
])
}
}
@@ -1,61 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// The `TextDocumentSourceKitOptionsRequest` request is sent from the client to the server to query for the list of
/// compiler options necessary to compile this file in the given target.
///
/// The build settings are considered up-to-date and can be cached by SourceKit-LSP until a
/// `DidChangeBuildTargetNotification` is sent for the requested target.
///
/// The request may return `nil` if it doesn't have any build settings for this file in the given target.
public struct TextDocumentSourceKitOptionsRequest: BSPRequest, Hashable {
public static let method: String = "textDocument/sourceKitOptions"
public typealias Response = TextDocumentSourceKitOptionsResponse?
/// The URI of the document to get options for
public var textDocument: TextDocumentIdentifier
/// The target for which the build setting should be returned.
///
/// A source file might be part of multiple targets and might have different compiler arguments in those two targets,
/// thus the target is necessary in this request.
public var target: BuildTargetIdentifier
/// The language with which the document was opened in the editor.
public var language: Language
public init(textDocument: TextDocumentIdentifier, target: BuildTargetIdentifier, language: Language) {
self.textDocument = textDocument
self.target = target
self.language = language
}
}
public struct TextDocumentSourceKitOptionsResponse: ResponseType, Hashable {
/// The compiler options required for the requested file.
public var compilerArguments: [String]
/// The working directory for the compile command.
public var workingDirectory: String?
/// Additional data that will not be interpreted by SourceKit-LSP but made available to clients in the
/// `workspace/_sourceKitOptions` LSP requests.
public var data: LSPAny?
public init(compilerArguments: [String], workingDirectory: String? = nil, data: LSPAny? = nil) {
self.compilerArguments = compilerArguments
self.workingDirectory = workingDirectory
self.data = data
}
}
@@ -1,31 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// The workspace build targets request is sent from the client to the server to
/// ask for the list of all available build targets in the workspace.
public struct WorkspaceBuildTargetsRequest: BSPRequest, Hashable {
public static let method: String = "workspace/buildTargets"
public typealias Response = WorkspaceBuildTargetsResponse
public init() {}
}
public struct WorkspaceBuildTargetsResponse: ResponseType, Hashable {
/// The build targets in this workspace that contain sources with the given language ids.
public var targets: [BuildTarget]
public init(targets: [BuildTarget]) {
self.targets = targets
}
}
@@ -1,25 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// This request is a no-op and doesn't have any effects.
///
/// If the build server is currently updating the build graph, this request should return after those updates have
/// finished processing.
public struct WorkspaceWaitForBuildSystemUpdatesRequest: BSPRequest, Hashable {
public typealias Response = VoidResponse
public static let method: String = "workspace/waitForBuildSystemUpdates"
public init() {}
}
@@ -1,237 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
/// Build target contains metadata about an artifact (for example library, test, or binary artifact).
/// Using vocabulary of other build tools:
/// - sbt: a build target is a combined project + config. Example:
/// - a regular JVM project with main and test configurations will have 2 build targets, one for main and one for test.
/// - a single configuration in a single project that contains both Java and Scala sources maps to one BuildTarget.
/// - a project with crossScalaVersions 2.11 and 2.12 containing main and test configuration in each will have 4 build targets.
/// - a Scala 2.11 and 2.12 cross-built project for Scala.js and the JVM with main and test configurations will have 8 build targets.
/// - Pants: a pants target corresponds one-to-one with a BuildTarget
/// - Bazel: a bazel target corresponds one-to-one with a BuildTarget
///
/// The general idea is that the BuildTarget data structure should contain only information that is fast or cheap to compute
public struct BuildTarget: Codable, Hashable, Sendable {
/// The targets unique identifier
public var id: BuildTargetIdentifier
/// A human readable name for this target.
/// May be presented in the user interface.
/// Should be unique if possible.
/// The id.uri is used if `nil`.
public var displayName: String?
/// The directory where this target belongs to. Multiple build targets are
/// allowed to map to the same base directory, and a build target is not
/// required to have a base directory. A base directory does not determine the
/// sources of a target, see `buildTarget/sources`.
public var baseDirectory: URI?
/// Free-form string tags to categorize or label this build target.
/// For example, can be used by the client to:
/// - customize how the target should be translated into the client's project
/// model.
/// - group together different but related targets in the user interface.
/// - display icons or colors in the user interface.
/// Pre-defined tags are listed in `BuildTargetTag` but clients and servers
/// are free to define new tags for custom purposes.
public var tags: [BuildTargetTag]
/// The set of languages that this target contains.
/// The ID string for each language is defined in the LSP.
public var languageIds: [Language]
/// The direct upstream build target dependencies of this build target
public var dependencies: [BuildTargetIdentifier]
/// The capabilities of this build target.
public var capabilities: BuildTargetCapabilities
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
public var dataKind: BuildTargetDataKind?
/// Language-specific metadata about this target.
/// See ScalaBuildTarget as an example.
public var data: LSPAny?
public init(
id: BuildTargetIdentifier,
displayName: String? = nil,
baseDirectory: URI? = nil,
tags: [BuildTargetTag] = [],
capabilities: BuildTargetCapabilities = BuildTargetCapabilities(),
languageIds: [Language],
dependencies: [BuildTargetIdentifier],
dataKind: BuildTargetDataKind? = nil,
data: LSPAny? = nil
) {
self.id = id
self.displayName = displayName
self.baseDirectory = baseDirectory
self.tags = tags
self.capabilities = capabilities
self.languageIds = languageIds
self.dependencies = dependencies
self.dataKind = dataKind
self.data = data
}
}
/// A unique identifier for a target, can use any URI-compatible encoding as long as it is unique within the workspace.
/// Clients should not infer metadata out of the URI structure such as the path or query parameters, use `BuildTarget`
/// instead.
public struct BuildTargetIdentifier: Codable, Hashable, Sendable {
/// The target's Uri
public var uri: URI
public init(uri: URI) {
self.uri = uri
}
}
public typealias URI = DocumentURI
/// A list of predefined tags that can be used to categorize build targets.
public struct BuildTargetTag: Codable, Hashable, RawRepresentable, Sendable {
public var rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// Target contains source code for producing any kind of application, may
/// have but does not require the `canRun` capability.
public static let application: Self = Self(rawValue: "application")
/// Target contains source code to measure performance of a program, may have
/// but does not require the `canRun` build target capability.
public static let benchmark: Self = Self(rawValue: "benchmark")
/// Target contains source code for integration testing purposes, may have
/// but does not require the `canTest` capability. The difference between
/// "test" and "integration-test" is that integration tests traditionally run
/// slower compared to normal tests and require more computing resources to
/// execute.
public static let integrationTest: Self = Self(rawValue: "integration-test")
/// Target contains re-usable functionality for downstream targets. May have
/// any combination of capabilities.
public static let library: Self = Self(rawValue: "library")
/// Actions on the target such as build and test should only be invoked manually
/// and explicitly. For example, triggering a build on all targets in the workspace
/// should by default not include this target.
/// The original motivation to add the "manual" tag comes from a similar functionality
/// that exists in Bazel, where targets with this tag have to be specified explicitly
/// on the command line.
public static let manual: Self = Self(rawValue: "manual")
/// Target should be ignored by IDEs.
public static let noIDE: Self = Self(rawValue: "no-ide")
/// Target contains source code for testing purposes, may have but does not
/// require the `canTest` capability.
public static let test: Self = Self(rawValue: "test")
/// This is a target of a dependency from the project the user opened, eg. a target that builds a SwiftPM dependency.
///
/// **(BSP Extension)**
public static let dependency: Self = Self(rawValue: "dependency")
/// This target only exists to provide compiler arguments for SourceKit-LSP can't be built standalone.
///
/// For example, a SwiftPM package manifest is in a non-buildable target.
///
/// **(BSP Extension)**
public static let notBuildable: Self = Self(rawValue: "not-buildable")
}
/// Clients can use these capabilities to notify users what BSP endpoints can and cannot be used and why.
public struct BuildTargetCapabilities: Codable, Hashable, Sendable {
/// This target can be compiled by the BSP server.
public var canCompile: Bool?
/// This target can be tested by the BSP server.
public var canTest: Bool?
/// This target can be run by the BSP server.
public var canRun: Bool?
/// This target can be debugged by the BSP server.
public var canDebug: Bool?
public init(canCompile: Bool? = nil, canTest: Bool? = nil, canRun: Bool? = nil, canDebug: Bool? = nil) {
self.canCompile = canCompile
self.canTest = canTest
self.canRun = canRun
self.canDebug = canDebug
}
}
public struct BuildTargetDataKind: RawRepresentable, Codable, Hashable, Sendable {
public var rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
/// `data` field must contain a CargoBuildTarget object.
public static let cargo = BuildTargetDataKind(rawValue: "cargo")
/// `data` field must contain a CppBuildTarget object.
public static let cpp = BuildTargetDataKind(rawValue: "cpp")
/// `data` field must contain a JvmBuildTarget object.
public static let jvm = BuildTargetDataKind(rawValue: "jvm")
/// `data` field must contain a PythonBuildTarget object.
public static let python = BuildTargetDataKind(rawValue: "python")
/// `data` field must contain a SbtBuildTarget object.
public static let sbt = BuildTargetDataKind(rawValue: "sbt")
/// `data` field must contain a ScalaBuildTarget object.
public static let scala = BuildTargetDataKind(rawValue: "scala")
/// `data` field must contain a SourceKitBuildTarget object.
public static let sourceKit = BuildTargetDataKind(rawValue: "sourceKit")
}
public struct SourceKitBuildTarget: LSPAnyCodable, Codable {
/// The toolchain that should be used to build this target. The URI should point to the directory that contains the
/// `usr` directory. On macOS, this is typically a bundle ending in `.xctoolchain`. If the toolchain is installed to
/// `/` on Linux, the toolchain URI would point to `/`.
///
/// If no toolchain is given, SourceKit-LSP will pick a toolchain to use for this target.
public var toolchain: URI?
public init(toolchain: URI? = nil) {
self.toolchain = toolchain
}
public init(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
if case .string(let toolchain) = dictionary[CodingKeys.toolchain.stringValue] {
self.toolchain = try? URI(string: toolchain)
}
}
public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
var result: [String: LSPAny] = [:]
if let toolchain {
result[CodingKeys.toolchain.stringValue] = .string(toolchain.stringValue)
}
return .dictionary(result)
}
}
@@ -1,27 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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 LanguageServerProtocol
public enum MessageType: Int, Sendable, Codable {
/// An error message.
case error = 1
/// A warning message.
case warning = 2
/// An information message.
case info = 3
/// A log message.
case log = 4
}
@@ -1,33 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import Foundation
public import LanguageServerProtocol
public struct MillisecondsSince1970Date: CustomCodableWrapper {
public var wrappedValue: Date
public init(wrappedValue: Date) {
self.wrappedValue = wrappedValue
}
public init(from decoder: any Decoder) throws {
let millisecondsSince1970 = try decoder.singleValueContainer().decode(Int64.self)
self.wrappedValue = Date(timeIntervalSince1970: Double(millisecondsSince1970) / 1_000)
}
public func encode(to encoder: any Encoder) throws {
let millisecondsSince1970 = Int64((wrappedValue.timeIntervalSince1970 * 1_000).rounded())
var container = encoder.singleValueContainer()
try container.encode(millisecondsSince1970)
}
}
@@ -1,22 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public enum StatusCode: Int, Codable, Hashable, Sendable {
/// Execution was successful.
case ok = 1
/// Execution failed.
case error = 2
/// Execution was cancelled.
case cancelled = 3
}
@@ -1,34 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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 LanguageServerProtocol
public typealias TaskIdentifier = String
public struct TaskId: Sendable, Codable, Hashable {
/// A unique identifier
public var id: TaskIdentifier
/// The parent task ids, if any. A non-empty parents field means
/// this task is a sub-task of every parent task id. The child-parent
/// relationship of tasks makes it possible to render tasks in
/// a tree-like user interface or inspect what caused a certain task
/// execution.
/// OriginId should not be included in the parents field, there is a separate
/// field for that.
public var parents: [TaskIdentifier]?
public init(id: TaskIdentifier, parents: [TaskIdentifier]? = nil) {
self.id = id
self.parents = parents
}
}
@@ -1,22 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
public import LanguageServerProtocol
public struct TextDocumentIdentifier: Codable, Sendable, Hashable {
/// The text document's URI.
public var uri: URI
public init(_ uri: URI) {
self.uri = uri
}
}
-11
View File
@@ -1,11 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 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
//
//===----------------------------------------------------------------------===//
-2
View File
@@ -1,2 +0,0 @@
add_library(CAtomics INTERFACE)
target_include_directories(CAtomics INTERFACE "include")
-73
View File
@@ -1,73 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
#ifndef SOURCEKITLSP_CATOMICS_H
#define SOURCEKITLSP_CATOMICS_H
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <stdlib.h>
typedef struct {
_Atomic(uint32_t) value;
} CAtomicUInt32;
static inline CAtomicUInt32 *_Nonnull atomic_uint32_create(uint32_t initialValue) {
CAtomicUInt32 *atomic = malloc(sizeof(CAtomicUInt32));
atomic->value = initialValue;
return atomic;
}
static inline uint32_t atomic_uint32_get(CAtomicUInt32 *_Nonnull atomic) {
return atomic->value;
}
static inline void atomic_uint32_set(CAtomicUInt32 *_Nonnull atomic, uint32_t newValue) {
atomic->value = newValue;
}
static inline uint32_t atomic_uint32_fetch_and_increment(CAtomicUInt32 *_Nonnull atomic) {
return atomic->value++;
}
static inline void atomic_uint32_destroy(CAtomicUInt32 *_Nonnull atomic) {
free(atomic);
}
typedef struct {
_Atomic(int32_t) value;
} CAtomicInt32;
static inline CAtomicInt32 *_Nonnull atomic_int32_create(int32_t initialValue) {
CAtomicInt32 *atomic = malloc(sizeof(CAtomicInt32));
atomic->value = initialValue;
return atomic;
}
static inline int32_t atomic_int32_get(CAtomicInt32 *_Nonnull atomic) {
return atomic->value;
}
static inline void atomic_int32_set(CAtomicInt32 *_Nonnull atomic, int32_t newValue) {
atomic->value = newValue;
}
static inline int32_t atomic_int32_fetch_and_increment(CAtomicInt32 *_Nonnull atomic) {
return atomic->value++;
}
static inline void atomic_int32_destroy(CAtomicInt32 *_Nonnull atomic) {
free(atomic);
}
#endif // SOURCEKITLSP_CATOMICS_H
@@ -1,4 +0,0 @@
module CAtomics {
header "CAtomics.h"
export *
}
-5
View File
@@ -2,19 +2,14 @@ add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name sourcekit_l
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-DRESILIENT_LIBRARIES>")
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-swift-version 6>")
add_subdirectory(BuildServerIntegration)
add_subdirectory(BuildServerProtocol)
add_subdirectory(CAtomics)
add_subdirectory(CCompletionScoring)
add_subdirectory(ClangLanguageService)
add_subdirectory(CompletionScoring)
add_subdirectory(Csourcekitd)
add_subdirectory(Diagnose)
add_subdirectory(InProcessClient)
add_subdirectory(LanguageServerProtocol)
add_subdirectory(LanguageServerProtocolExtensions)
add_subdirectory(LanguageServerProtocolJSONRPC)
add_subdirectory(SemanticIndex)
add_subdirectory(SKLogging)
add_subdirectory(SKOptions)
add_subdirectory(SKUtilities)
add_subdirectory(sourcekit-lsp)
+4 -3
View File
@@ -8,10 +8,11 @@ set_target_properties(ClangLanguageService PROPERTIES
)
target_link_libraries(ClangLanguageService PUBLIC
LanguageServerProtocol
SwiftToolsProtocols::LanguageServerProtocol
SKOptions
SourceKitLSP
SwiftExtensions
SwiftToolsProtocols::ToolsProtocolsSwiftExtensions
ToolchainRegistry
SwiftSyntax::SwiftSyntax
)
@@ -19,7 +20,7 @@ target_link_libraries(ClangLanguageService PUBLIC
target_link_libraries(ClangLanguageService PRIVATE
BuildServerIntegration
LanguageServerProtocolExtensions
LanguageServerProtocolJSONRPC
SKLogging
SwiftToolsProtocols::LanguageServerProtocolTransport
SwiftToolsProtocols::SKLogging
TSCExtensions
)
@@ -13,16 +13,17 @@
import BuildServerIntegration
import Foundation
import IndexStoreDB
package import LanguageServerProtocol
import LanguageServerProtocolExtensions
import LanguageServerProtocolJSONRPC
import SKLogging
@_spi(SourceKitLSP) package import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
package import SKOptions
package import SourceKitLSP
package import SwiftExtensions
import SwiftExtensions
package import SwiftSyntax
import TSCExtensions
package import ToolchainRegistry
@_spi(SourceKitLSP) package import ToolsProtocolsSwiftExtensions
#if os(Windows)
import WinSDK
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
/// `clangd` might use a different semantic token legend than SourceKit-LSP.
///
@@ -13,6 +13,7 @@
package import CompletionScoring
import Foundation
import SwiftExtensions
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions
import XCTest
@inline(never)
+2 -1
View File
@@ -28,10 +28,11 @@ set_target_properties(Diagnose PROPERTIES
target_link_libraries(Diagnose PUBLIC
BuildServerIntegration
InProcessClient
SKLogging
SwiftToolsProtocols::SKLogging
SKOptions
SourceKitD
SwiftExtensions
SwiftToolsProtocols::ToolsProtocolsSwiftExtensions
ToolchainRegistry
ArgumentParser
SwiftSyntax::SwiftIDEUtils
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import Foundation
import SKLogging
@_spi(SourceKitLSP) import SKLogging
// MARK: - Entry point
+3 -2
View File
@@ -12,11 +12,12 @@
package import ArgumentParser
import Foundation
import LanguageServerProtocolExtensions
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import SKLogging
import SwiftExtensions
import TSCExtensions
import ToolchainRegistry
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions
import struct TSCBasic.AbsolutePath
import class TSCBasic.Process
+4 -2
View File
@@ -13,12 +13,14 @@
public import ArgumentParser
import Foundation
import InProcessClient
import LanguageServerProtocol
import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
import SKOptions
import SourceKitLSP
import SwiftExtensions
import ToolchainRegistry
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions
import struct TSCBasic.AbsolutePath
import class TSCBasic.Process
+1 -1
View File
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import Foundation
import SKLogging
@_spi(SourceKitLSP) import SKLogging
extension RequestInfo {
/// Check if the issue reproduces when merging all `.swift` input files into a single file.
+1 -1
View File
@@ -12,7 +12,7 @@
#if canImport(OSLog)
import OSLog
import SKLogging
@_spi(SourceKitLSP) import SKLogging
import RegexBuilder
/// Reads oslog messages to find recent sourcekitd crashes.
@@ -13,7 +13,7 @@
package import ArgumentParser
import Csourcekitd
import Foundation
import SKLogging
@_spi(SourceKitLSP) import SKLogging
import SKUtilities
import SourceKitD
import SwiftExtensions
+1 -1
View File
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import Foundation
import SKLogging
@_spi(SourceKitLSP) import SKLogging
import SourceKitD
import SwiftExtensions
@_spi(FixItApplier) import SwiftIDEUtils
@@ -11,10 +11,10 @@
//===----------------------------------------------------------------------===//
import BuildServerIntegration
import BuildServerProtocol
@_spi(SourceKitLSP) import BuildServerProtocol
import Foundation
import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
extension BuildServerManager {
/// Retrieves the name of the Swift module for a given target.
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import Foundation
import SKLogging
@_spi(SourceKitLSP) import SKLogging
import SKUtilities
@_spi(LinkCompletion) @preconcurrency import SwiftDocC
@@ -11,10 +11,10 @@
//===----------------------------------------------------------------------===//
import BuildServerIntegration
import BuildServerProtocol
@_spi(SourceKitLSP) import BuildServerProtocol
import Foundation
import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
import SwiftDocC
struct DocCDocumentationManager: Sendable {
@@ -12,8 +12,8 @@
import Foundation
import IndexStoreDB
import LanguageServerProtocol
import SKLogging
@_spi(SourceKitLSP) import LanguageServerProtocol
@_spi(SourceKitLSP) import SKLogging
import SemanticIndex
@_spi(Linkcompletion) @preconcurrency import SwiftDocC
import SwiftExtensions
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import Foundation
import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocol
enum DocCDocumentationError: LocalizedError {
case unsupportedLanguage(Language)
@@ -13,9 +13,9 @@
import BuildServerIntegration
import Foundation
@preconcurrency import IndexStoreDB
package import LanguageServerProtocol
@_spi(SourceKitLSP) package import LanguageServerProtocol
import Markdown
import SKLogging
@_spi(SourceKitLSP) import SKLogging
import SKUtilities
import SemanticIndex
import SourceKitLSP
@@ -12,7 +12,7 @@
import Foundation
import IndexStoreDB
package import LanguageServerProtocol
@_spi(SourceKitLSP) package import LanguageServerProtocol
package import SKOptions
package import SourceKitLSP
import SwiftExtensions
@@ -12,7 +12,7 @@
import Foundation
import IndexStoreDB
import SKLogging
@_spi(SourceKitLSP) import SKLogging
import SemanticIndex
@preconcurrency @_spi(LinkCompletion) import SwiftDocC
import SwiftExtensions
+3 -2
View File
@@ -8,8 +8,9 @@ set_target_properties(InProcessClient PROPERTIES
target_link_libraries(InProcessClient PUBLIC
BuildServerIntegration
ClangLanguageService
LanguageServerProtocol
SKLogging
Crypto
SwiftToolsProtocols::LanguageServerProtocol
SwiftToolsProtocols::SKLogging
SKOptions
SourceKitLSP
SwiftLanguageService
@@ -12,14 +12,16 @@
import BuildServerIntegration
public import Foundation
public import LanguageServerProtocol
import LanguageServerProtocolExtensions
import SKLogging
@_spi(SourceKitLSP) public import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocolExtensions
@_spi(SourceKitLSP) import LanguageServerProtocolTransport
@_spi(SourceKitLSP) import SKLogging
public import SKOptions
package import SourceKitLSP
import SwiftExtensions
import TSCExtensions
package import ToolchainRegistry
@_spi(SourceKitLSP) import ToolsProtocolsSwiftExtensions
import struct TSCBasic.AbsolutePath
@@ -56,6 +58,7 @@ public final class InProcessSourceKitLSPClient: Sendable {
workspaceFolders: [WorkspaceFolder],
messageHandler: any MessageHandler
) async throws {
LoggingScope.configureDefaultLoggingSubsystem("org.swift.sourcekit-lsp")
let serverToClientConnection = LocalConnection(receiverName: "client")
self.server = SourceKitLSPServer(
client: serverToClientConnection,
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
import ClangLanguageService
import LanguageServerProtocol
@_spi(SourceKitLSP) import LanguageServerProtocol
package import SourceKitLSP
import SwiftLanguageService
@@ -1,155 +0,0 @@
add_library(LanguageServerProtocol STATIC
Connection.swift
CustomCodable.swift
Error.swift
Message.swift
MessageRegistry.swift
Messages.swift
PositionRange.swift
RequestID.swift
Notifications/CancelRequestNotification.swift
Notifications/CancelWorkDoneProgressNotification.swift
Notifications/ConfigurationNotification.swift
Notifications/DidChangeActiveDocumentNotification.swift
Notifications/DidChangeFileNotifications.swift
Notifications/DidChangeWatchedFilesNotification.swift
Notifications/DidChangeWorkspaceFoldersNotification.swift
Notifications/ExitNotification.swift
Notifications/InitializedNotification.swift
Notifications/LogMessageNotification.swift
Notifications/LogTraceNotification.swift
Notifications/PublishDiagnosticsNotification.swift
Notifications/ReopenTextDocumentNotifications.swift
Notifications/SetTraceNotification.swift
Notifications/ShowMessageNotification.swift
Notifications/TextSynchronizationNotifications.swift
Notifications/WorkDoneProgress.swift
Requests/ApplyEditRequest.swift
Requests/CallHierarchyIncomingCallsRequest.swift
Requests/CallHierarchyOutgoingCallsRequest.swift
Requests/CallHierarchyPrepareRequest.swift
Requests/CodeActionRequest.swift
Requests/CodeActionResolveRequest.swift
Requests/CodeLensRefreshRequest.swift
Requests/CodeLensRequest.swift
Requests/CodeLensResolveRequest.swift
Requests/ColorPresentationRequest.swift
Requests/CompletionItemResolveRequest.swift
Requests/CompletionRequest.swift
Requests/CreateWorkDoneProgressRequest.swift
Requests/DeclarationRequest.swift
Requests/DefinitionRequest.swift
Requests/DiagnosticsRefreshRequest.swift
Requests/DoccDocumentationRequest.swift
Requests/DocumentColorRequest.swift
Requests/DocumentDiagnosticsRequest.swift
Requests/DocumentHighlightRequest.swift
Requests/DocumentLinkRequest.swift
Requests/DocumentLinkResolveRequest.swift
Requests/DocumentSemanticTokensDeltaRequest.swift
Requests/DocumentSemanticTokensRangeRequest.swift
Requests/DocumentSemanticTokensRequest.swift
Requests/DocumentSymbolRequest.swift
Requests/DocumentTestsRequest.swift
Requests/ExecuteCommandRequest.swift
Requests/FoldingRangeRequest.swift
Requests/FormattingRequests.swift
Requests/GetReferenceDocumentRequest.swift
Requests/HoverRequest.swift
Requests/ImplementationRequest.swift
Requests/IndexedRenameRequest.swift
Requests/InitializeRequest.swift
Requests/InlayHintRefreshRequest.swift
Requests/InlayHintRequest.swift
Requests/InlayHintResolveRequest.swift
Requests/InlineValueRefreshRequest.swift
Requests/InlineValueRequest.swift
Requests/IsIndexingRequest.swift
Requests/LinkedEditingRangeRequest.swift
Requests/MonikersRequest.swift
Requests/OutputPathsRequest.swift
Requests/PeekDocumentsRequest.swift
Requests/PrepareRenameRequest.swift
Requests/ReferencesRequest.swift
Requests/RegisterCapabilityRequest.swift
Requests/RenameRequest.swift
Requests/SelectionRangeRequest.swift
Requests/SetOptionsRequest.swift
Requests/ShowDocumentRequest.swift
Requests/ShowMessageRequest.swift
Requests/ShutdownRequest.swift
Requests/SignatureHelpRequest.swift
Requests/SourceKitOptionsRequest.swift
Requests/SymbolInfoRequest.swift
Requests/SynchronizeRequest.swift
Requests/TriggerReindexRequest.swift
Requests/TypeDefinitionRequest.swift
Requests/TypeHierarchyPrepareRequest.swift
Requests/TypeHierarchySubtypesRequest.swift
Requests/TypeHierarchySupertypesRequest.swift
Requests/UnregisterCapabilityRequest.swift
Requests/WillChangeFilesRequests.swift
Requests/WillSaveWaitUntilTextDocumentRequest.swift
Requests/WorkspaceDiagnosticsRequest.swift
Requests/WorkspaceFoldersRequest.swift
Requests/WorkspaceSemanticTokensRefreshRequest.swift
Requests/WorkspaceSymbolResolveRequest.swift
Requests/WorkspaceSymbolsRequest.swift
Requests/WorkspaceTestsRequest.swift
SupportTypes/CallHierarchyItem.swift
SupportTypes/ClientCapabilities.swift
SupportTypes/CodeActionKind.swift
SupportTypes/Command.swift
SupportTypes/CompletionItem.swift
SupportTypes/CompletionItemKind.swift
SupportTypes/Diagnostic.swift
SupportTypes/DocumentURI.swift
SupportTypes/FileEvent.swift
SupportTypes/FileSystemWatcher.swift
SupportTypes/FoldingRangeKind.swift
SupportTypes/InlayHint.swift
SupportTypes/InsertReplaceEdit.swift
SupportTypes/Language.swift
SupportTypes/Location.swift
SupportTypes/LocationLink.swift
SupportTypes/LocationsOrLocationLinksResponse.swift
SupportTypes/LSPAny.swift
SupportTypes/MarkupContent.swift
SupportTypes/NotebookCellTextDocumentFilter.swift
SupportTypes/NotebookDocument.swift
SupportTypes/NotebookDocumentChangeEvent.swift
SupportTypes/NotebookDocumentIdentifier.swift
SupportTypes/Position.swift
SupportTypes/PositionEncoding.swift
SupportTypes/ProgressToken.swift
SupportTypes/RegistrationOptions.swift
SupportTypes/SemanticTokenModifiers.swift
SupportTypes/SemanticTokens.swift
SupportTypes/SemanticTokenTypes.swift
SupportTypes/ServerCapabilities.swift
SupportTypes/StringOrMarkupContent.swift
SupportTypes/SupportedCodeLensCommand.swift
SupportTypes/SymbolKind.swift
SupportTypes/TestItem.swift
SupportTypes/TextDocumentContentChangeEvent.swift
SupportTypes/TextDocumentEdit.swift
SupportTypes/TextDocumentIdentifier.swift
SupportTypes/TextDocumentItem.swift
SupportTypes/TextDocumentSaveReason.swift
SupportTypes/TextEdit.swift
SupportTypes/Tracing.swift
SupportTypes/TypeHierarchyItem.swift
SupportTypes/VersionedNotebookDocumentIdentifier.swift
SupportTypes/VersionedTextDocumentIdentifier.swift
SupportTypes/WindowMessageType.swift
SupportTypes/WorkspaceEdit.swift
SupportTypes/WorkspaceFolder.swift
SupportTypes/WorkspaceSettings.swift)
set_target_properties(LanguageServerProtocol PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(LanguageServerProtocol PUBLIC
$<$<NOT:$<PLATFORM_ID:Darwin>>:swiftDispatch>
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>)
@@ -1,103 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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
//
//===----------------------------------------------------------------------===//
/// An abstract connection, allow messages to be sent to a (potentially remote) `MessageHandler`.
public protocol Connection: Sendable {
/// Send a notification without a reply.
func send(_ notification: some NotificationType)
/// Generate a new request ID to be used in the `send` method that does not take an explicit request ID.
///
/// These request IDs need to be unique and must not conflict with any request ID that clients might manually specify
/// to `send(_:id:reply:)`.
///
/// To allow, this request IDs starting with `sk-` are reserved to only be generated by this method and are not
/// allowed to be passed directly to `send(_:id:reply:)`. Thus, generating request IDs prefixed with `sk-` here is
/// safe. Similarly returning UUID-based requests IDs is safe because UUIDs are already unique.
func nextRequestID() -> RequestID
/// Send a request with a pre-defined request ID and (asynchronously) receive a reply.
///
/// The request ID must not conflict with any request ID generated by `nextRequestID()`.
func send<Request: RequestType>(
_ request: Request,
id: RequestID,
reply: @escaping @Sendable (LSPResult<Request.Response>) -> Void
)
}
extension Connection {
/// Send a request and (asynchronously) receive a reply.
public func send<Request: RequestType>(
_ request: Request,
reply: @escaping @Sendable (LSPResult<Request.Response>) -> Void
) -> RequestID {
let id = nextRequestID()
self.send(request, id: id, reply: reply)
return id
}
}
/// An abstract message handler, such as a language server or client.
public protocol MessageHandler: AnyObject, Sendable {
/// Handle a notification without a reply.
///
/// The method should return as soon as the notification has been sufficiently
/// handled to avoid out-of-order requests, e.g. once the notification has
/// been forwarded to clangd.
func handle(_ notification: some NotificationType)
/// Handle a request and (asynchronously) receive a reply.
///
/// The method should return as soon as the request has been sufficiently
/// handled to avoid out-of-order requests, e.g. once the corresponding
/// request has been sent to sourcekitd. The actual semantic computation
/// should occur after the method returns and report the result via `reply`.
func handle<Request: RequestType>(
_ request: Request,
id: RequestID,
reply: @Sendable @escaping (LSPResult<Request.Response>) -> Void
)
}
// MARK: - WeakMessageHelper
/// Wrapper around a weak `MessageHandler`.
///
/// This allows us to eg. set the ``TestSourceKitLSPClient`` as the message handler of
/// `SourceKitLSPServer` without retaining it.
public final class WeakMessageHandler: MessageHandler, Sendable {
// `nonisolated(unsafe)` is fine because `handler` is never modified, only if the weak reference is deallocated, which
// is atomic.
private nonisolated(unsafe) weak var handler: (any MessageHandler)?
public init(_ handler: any MessageHandler) {
self.handler = handler
}
public func handle(_ params: some NotificationType) {
handler?.handle(params)
}
public func handle<Request: RequestType>(
_ params: Request,
id: RequestID,
reply: @Sendable @escaping (LSPResult<Request.Response>) -> Void
) {
guard let handler = handler else {
reply(.failure(.unknown("Handler has been deallocated")))
return
}
handler.handle(params, id: id, reply: reply)
}
}
@@ -1,115 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
/// Property wrapper allowing per-property customization of how the value is
/// encoded/decoded when using Codable.
///
/// CustomCodable is generic over a `CustomCoder: CustomCodableWrapper`, which
/// wraps the underlying value, and provides the specific Codable implementation.
/// Since each instance of CustomCodable provides its own CustomCoder wrapper,
/// properties of the same type can provide different Codable implementations
/// within the same container.
///
/// Example: change the encoding of a property `foo` in the following struct to
/// do its encoding through a String instead of the normal Codable implementation.
///
/// ```
/// struct MyStruct: Codable {
/// @CustomCodable<SillyIntCoding> var foo: Int
/// }
///
/// struct SillyIntCoding: CustomCodableWrapper {
/// init(from decoder: Decoder) throws {
/// wrappedValue = try Int(decoder.singleValueContainer().decoder(String.self))!
/// }
/// func encode(to encoder: Encoder) throws {
/// try encoder.singleValueContainer().encode("\(wrappedValue)")
/// }
/// var wrappedValue: Int { get }
/// init(wrappedValue: WrappedValue) { self.wrappedValue = wrappedValue }
/// }
/// ```
@propertyWrapper
public struct CustomCodable<CustomCoder: CustomCodableWrapper> {
public typealias CustomCoder = CustomCoder
/// The underlying value.
public var wrappedValue: CustomCoder.WrappedValue
public init(wrappedValue: CustomCoder.WrappedValue) {
self.wrappedValue = wrappedValue
}
}
extension CustomCodable: Sendable where CustomCoder.WrappedValue: Sendable {}
extension CustomCodable: Codable {
public init(from decoder: Decoder) throws {
self.wrappedValue = try CustomCoder(from: decoder).wrappedValue
}
public func encode(to encoder: Encoder) throws {
try CustomCoder(wrappedValue: self.wrappedValue).encode(to: encoder)
}
}
extension CustomCodable: Equatable where CustomCoder.WrappedValue: Equatable {}
extension CustomCodable: Hashable where CustomCoder.WrappedValue: Hashable {}
/// Wrapper type providing a Codable implementation for use with `CustomCodable`.
public protocol CustomCodableWrapper: Codable {
/// The type of the underlying value being wrapped.
associatedtype WrappedValue
/// The underlying value.
var wrappedValue: WrappedValue { get }
/// Create a wrapper from an underlying value.
init(wrappedValue: WrappedValue)
}
extension Optional: CustomCodableWrapper where Wrapped: CustomCodableWrapper {
public var wrappedValue: Wrapped.WrappedValue? { self?.wrappedValue }
public init(wrappedValue: Wrapped.WrappedValue?) {
self = wrappedValue.flatMap { Wrapped.init(wrappedValue: $0) }
}
}
// The following extensions allow us to encode `CustomCodable<Optional<T>>`
// using `encodeIfPresent` (and `decodeIfPresent`) in synthesized `Codable`
// conformances. Without these, we would encode `nil` using `encodeNil` instead
// of skipping the key.
extension KeyedDecodingContainer {
public func decode<T: CustomCodableWrapper>(
_ type: CustomCodable<T?>.Type,
forKey key: Key
) throws -> CustomCodable<T?> {
CustomCodable<T?>(wrappedValue: try decodeIfPresent(T.self, forKey: key)?.wrappedValue)
}
}
extension KeyedEncodingContainer {
public mutating func encode<T: CustomCodableWrapper>(
_ value: CustomCodable<T?>,
forKey key: Key
) throws {
try encodeIfPresent(
value.wrappedValue.map {
type(of: value).CustomCoder(wrappedValue: $0)
},
forKey: key
)
}
}
-219
View File
@@ -1,219 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// A convenience wrapper for `Result` where the error is a `ResponseError`.
public typealias LSPResult<T> = Swift.Result<T, ResponseError>
/// Error code suitable for use between language server and client.
public struct ErrorCode: RawRepresentable, Codable, Hashable, Sendable {
public var rawValue: Int
public init(rawValue: Int) {
self.rawValue = rawValue
}
// MARK: JSON RPC
public static let parseError: ErrorCode = ErrorCode(rawValue: -32700)
public static let invalidRequest: ErrorCode = ErrorCode(rawValue: -32600)
public static let methodNotFound: ErrorCode = ErrorCode(rawValue: -32601)
public static let invalidParams: ErrorCode = ErrorCode(rawValue: -32602)
public static let internalError: ErrorCode = ErrorCode(rawValue: -32603)
/// This is the start range of JSON-RPC reserved error codes.
/// It doesn't denote a real error code. No LSP error codes should
/// be defined between the start and end range. For backwards
/// compatibility the `ServerNotInitialized` and the `UnknownErrorCode`
/// are left in the range.
public static let jsonrpcReservedErrorRangeStart = ErrorCode(rawValue: -32099)
public static let serverErrorStart: ErrorCode = jsonrpcReservedErrorRangeStart
/// Error code indicating that a server received a notification or
/// request before the server has received the `initialize` request.
public static let serverNotInitialized = ErrorCode(rawValue: -32002)
public static let unknownErrorCode = ErrorCode(rawValue: -32001)
/// This is the end range of JSON-RPC reserved error codes.
/// It doesn't denote a real error code.
public static let jsonrpcReservedErrorRangeEnd = ErrorCode(rawValue: -32000)
/// Deprecated, use jsonrpcReservedErrorRangeEnd
public static let serverErrorEnd = jsonrpcReservedErrorRangeEnd
/// This is the start range of LSP reserved error codes.
/// It doesn't denote a real error code.
public static let lspReservedErrorRangeStart = ErrorCode(rawValue: -32899)
/// A request failed but it was syntactically correct, e.g the
/// method name was known and the parameters were valid. The error
/// message should contain human readable information about why
/// the request failed.
public static let requestFailed = ErrorCode(rawValue: -32803)
/// The server cancelled the request. This error code should
/// only be used for requests that explicitly support being
/// server cancellable.
public static let serverCancelled = ErrorCode(rawValue: -32802)
/// The server detected that the content of a document got
/// modified outside normal conditions. A server should
/// NOT send this error code if it detects a content change
/// in it unprocessed messages. The result even computed
/// on an older state might still be useful for the client.
///
/// If a client decides that a result is not of any use anymore
/// the client should cancel the request.
public static let contentModified = ErrorCode(rawValue: -32801)
/// The client has canceled a request and a server as detected
/// the cancel.
public static let cancelled: ErrorCode = ErrorCode(rawValue: -32800)
/// This is the end range of LSP reserved error codes.
/// It doesn't denote a real error code.
public static let lspReservedErrorRangeEnd = ErrorCode(rawValue: -32800)
// MARK: SourceKit-LSP specific error codes
public static let workspaceNotOpen: ErrorCode = ErrorCode(rawValue: -32003)
/// The method is not implemented in this `LanguageService`.
///
/// This informs `SourceKitLSPServer` that it should query secondary language services for the results.
public static let requestNotImplemented: ErrorCode = ErrorCode(rawValue: -32004)
}
/// An error response represented by a code and message.
public struct ResponseError: Error, Codable, Hashable {
public var code: ErrorCode
public var message: String
public var data: LSPAny?
public init(code: ErrorCode, message: String, data: LSPAny? = nil) {
self.code = code
self.message = message
self.data = data
}
}
extension ResponseError {
// MARK: Convenience properties for common errors.
public static let cancelled: ResponseError = ResponseError(code: .cancelled, message: "request cancelled by client")
public static let serverCancelled: ResponseError = ResponseError(
code: .serverCancelled,
message: "request cancelled by server"
)
public static func workspaceNotOpen(_ uri: DocumentURI) -> ResponseError {
return ResponseError(code: .workspaceNotOpen, message: "No workspace containing '\(uri)' found")
}
public static func invalidParams(_ message: String) -> ResponseError {
return ResponseError(code: .invalidParams, message: message)
}
public static func methodNotFound(_ method: String) -> ResponseError {
return ResponseError(code: .methodNotFound, message: "method not found: \(method)")
}
public static func unknown(_ message: String) -> ResponseError {
return ResponseError(code: .unknownErrorCode, message: message)
}
public static func requestFailed(_ message: String) -> ResponseError {
return ResponseError(code: .requestFailed, message: message)
}
public static func internalError(_ message: String) -> ResponseError {
return ResponseError(code: .internalError, message: message)
}
public static func requestNotImplemented(_ method: any RequestType.Type) -> ResponseError {
return ResponseError(code: .requestNotImplemented, message: "request not implemented: \(method.method)")
}
}
/// An error during message decoding.
public struct MessageDecodingError: Error, Hashable {
/// The error code.
public var code: ErrorCode
/// A free-form description of the error.
public var message: String
/// If it was possible to recover the request id, it is stored here. This can be used e.g. to reply with a `ResponseError` to invalid requests.
public var id: RequestID?
@frozen public enum MessageKind: Sendable {
case request
case response
case notification
case unknown
}
/// What kind of message was being decoded, or `.unknown`.
public var messageKind: MessageKind
public init(code: ErrorCode, message: String, id: RequestID? = nil, messageKind: MessageKind = .unknown) {
self.code = code
self.message = message
self.id = id
self.messageKind = messageKind
}
}
extension MessageDecodingError {
public static func methodNotFound(
_ method: String,
id: RequestID? = nil,
messageKind: MessageKind = .unknown
) -> MessageDecodingError {
return MessageDecodingError(
code: .methodNotFound,
message: "method not found: \(method)",
id: id,
messageKind: messageKind
)
}
public static func invalidRequest(
_ reason: String,
id: RequestID? = nil,
messageKind: MessageKind = .unknown
) -> MessageDecodingError {
return MessageDecodingError(code: .invalidRequest, message: reason, id: id, messageKind: messageKind)
}
public static func invalidParams(
_ reason: String,
id: RequestID? = nil,
messageKind: MessageKind = .unknown
) -> MessageDecodingError {
return MessageDecodingError(code: .invalidParams, message: reason, id: id, messageKind: messageKind)
}
public static func parseError(
_ reason: String,
id: RequestID? = nil,
messageKind: MessageKind = .unknown
) -> MessageDecodingError {
return MessageDecodingError(code: .parseError, message: reason, id: id, messageKind: messageKind)
}
}
extension ResponseError {
/// Converts a `MessageDecodingError` to a `ResponseError`.
public init(_ decodingError: MessageDecodingError) {
self.init(code: decodingError.code, message: decodingError.message)
}
}
@@ -1,79 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
public protocol MessageType: Codable, Sendable {}
/// `RequestType` with no associated type or same-type requirements. Most users should prefer
/// `RequestType`.
public protocol _RequestType: MessageType {
/// The name of the request.
static var method: String { get }
/// *Implementation detail*. Dispatch `self` to the given handler and reply on `connection`.
/// Only needs to be declared as a protocol requirement of `_RequestType` so we can call the implementation on `RequestType` from the underscored type.
func _handle(
_ handler: MessageHandler,
id: RequestID,
reply: @Sendable @escaping (LSPResult<ResponseType>, RequestID) -> Void
)
}
/// A request, which must have a unique `method` name as well as an associated response type.
public protocol RequestType: _RequestType {
/// The type of of the response to this request.
associatedtype Response: ResponseType
}
/// A notification, which must have a unique `method` name.
public protocol NotificationType: MessageType {
/// The name of the request.
static var method: String { get }
}
/// A response.
public protocol ResponseType: MessageType {}
extension RequestType {
public func _handle(
_ handler: MessageHandler,
id: RequestID,
reply: @Sendable @escaping (LSPResult<ResponseType>, RequestID) -> Void
) {
handler.handle(self, id: id) { response in
reply(response.map({ $0 as ResponseType }), id)
}
}
}
extension NotificationType {
public func _handle(_ handler: MessageHandler) {
handler.handle(self)
}
}
public protocol LSPRequest: RequestType {}
public protocol LSPNotification: NotificationType {}
/// A `textDocument/*` notification, which takes a text document identifier
/// indicating which document it operates in or on.
public protocol TextDocumentNotification: LSPNotification {
var textDocument: TextDocumentIdentifier { get }
}
/// A `textDocument/*` request, which takes a text document identifier
/// indicating which document it operates in or on.
public protocol TextDocumentRequest: LSPRequest {
var textDocument: TextDocumentIdentifier { get }
}
@@ -1,36 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
public final class MessageRegistry: Sendable {
public static let lspProtocol: MessageRegistry =
MessageRegistry(requests: builtinRequests, notifications: builtinNotifications)
private let methodToRequest: [String: _RequestType.Type]
private let methodToNotification: [String: NotificationType.Type]
public init(requests: [_RequestType.Type], notifications: [NotificationType.Type]) {
self.methodToRequest = Dictionary(uniqueKeysWithValues: requests.map { ($0.method, $0) })
self.methodToNotification = Dictionary(uniqueKeysWithValues: notifications.map { ($0.method, $0) })
}
/// Returns the type of the message named `method`, or nil if it is unknown.
public func requestType(for method: String) -> _RequestType.Type? {
return methodToRequest[method]
}
/// Returns the type of the message named `method`, or nil if it is unknown.
public func notificationType(for method: String) -> NotificationType.Type? {
return methodToNotification[method]
}
}
@@ -1,140 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// The set of known requests.
///
/// All requests from LSP as well as any extensions provided by the server should be listed here.
/// If you are adding a message for testing only, you can register it dynamically using
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
public let builtinRequests: [_RequestType.Type] = [
ApplyEditRequest.self,
CallHierarchyIncomingCallsRequest.self,
CallHierarchyOutgoingCallsRequest.self,
CallHierarchyPrepareRequest.self,
CodeActionRequest.self,
CodeActionResolveRequest.self,
CodeLensRefreshRequest.self,
CodeLensRequest.self,
CodeLensResolveRequest.self,
ColorPresentationRequest.self,
CompletionItemResolveRequest.self,
CompletionRequest.self,
CreateWorkDoneProgressRequest.self,
DeclarationRequest.self,
DefinitionRequest.self,
DiagnosticsRefreshRequest.self,
DoccDocumentationRequest.self,
DocumentColorRequest.self,
DocumentDiagnosticsRequest.self,
DocumentFormattingRequest.self,
DocumentHighlightRequest.self,
DocumentLinkRequest.self,
DocumentLinkResolveRequest.self,
DocumentOnTypeFormattingRequest.self,
DocumentRangeFormattingRequest.self,
DocumentSemanticTokensDeltaRequest.self,
DocumentSemanticTokensRangeRequest.self,
DocumentSemanticTokensRequest.self,
DocumentSymbolRequest.self,
DocumentTestsRequest.self,
ExecuteCommandRequest.self,
FoldingRangeRequest.self,
GetReferenceDocumentRequest.self,
HoverRequest.self,
ImplementationRequest.self,
InitializeRequest.self,
InlayHintRefreshRequest.self,
InlayHintRequest.self,
InlayHintResolveRequest.self,
InlineValueRefreshRequest.self,
InlineValueRequest.self,
IsIndexingRequest.self,
LinkedEditingRangeRequest.self,
MonikersRequest.self,
OutputPathsRequest.self,
PeekDocumentsRequest.self,
SynchronizeRequest.self,
PrepareRenameRequest.self,
ReferencesRequest.self,
RegisterCapabilityRequest.self,
RenameRequest.self,
SelectionRangeRequest.self,
SetOptionsRequest.self,
ShowDocumentRequest.self,
ShowMessageRequest.self,
ShutdownRequest.self,
SignatureHelpRequest.self,
SourceKitOptionsRequest.self,
SymbolInfoRequest.self,
TriggerReindexRequest.self,
TypeDefinitionRequest.self,
TypeHierarchyPrepareRequest.self,
TypeHierarchySubtypesRequest.self,
TypeHierarchySupertypesRequest.self,
UnregisterCapabilityRequest.self,
WillCreateFilesRequest.self,
WillDeleteFilesRequest.self,
WillRenameFilesRequest.self,
WillSaveWaitUntilTextDocumentRequest.self,
WorkspaceDiagnosticsRequest.self,
WorkspaceFoldersRequest.self,
WorkspaceSemanticTokensRefreshRequest.self,
WorkspaceSymbolResolveRequest.self,
WorkspaceSymbolsRequest.self,
WorkspaceTestsRequest.self,
]
/// The set of known notifications.
///
/// All notifications from LSP as well as any extensions provided by the server should be listed
/// here. If you are adding a message for testing only, you can register it dynamically using
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
public let builtinNotifications: [NotificationType.Type] = [
CancelRequestNotification.self,
CancelWorkDoneProgressNotification.self,
DidChangeActiveDocumentNotification.self,
DidChangeConfigurationNotification.self,
DidChangeNotebookDocumentNotification.self,
DidChangeTextDocumentNotification.self,
DidChangeWatchedFilesNotification.self,
DidChangeWorkspaceFoldersNotification.self,
DidCloseNotebookDocumentNotification.self,
DidCloseTextDocumentNotification.self,
DidCreateFilesNotification.self,
DidDeleteFilesNotification.self,
DidOpenNotebookDocumentNotification.self,
DidOpenTextDocumentNotification.self,
DidRenameFilesNotification.self,
DidSaveNotebookDocumentNotification.self,
DidSaveTextDocumentNotification.self,
ExitNotification.self,
InitializedNotification.self,
LogMessageNotification.self,
LogTraceNotification.self,
PublishDiagnosticsNotification.self,
SetTraceNotification.self,
ShowMessageNotification.self,
WillSaveTextDocumentNotification.self,
WorkDoneProgress.self,
]
// MARK: Miscellaneous Message Types
public struct VoidResponse: ResponseType, Hashable {
public init() {}
}
extension Optional: MessageType where Wrapped: MessageType {}
extension Optional: ResponseType where Wrapped: ResponseType {}
extension Array: MessageType where Element: MessageType {}
extension Array: ResponseType where Element: ResponseType {}
@@ -1,30 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// Notification that the given request (previously made) should be cancelled, if possible.
///
/// Cancellation is not guaranteed and the underlying request may finish normally. If the request is
/// successfully cancelled, it should return the `.cancelled` error code.
///
/// As with any `$` requests, the server is free to ignore this notification.
///
/// - Parameter id: The request to cancel.
public struct CancelRequestNotification: LSPNotification, Hashable {
public static let method: String = "$/cancelRequest"
/// The request to cancel.
public var id: RequestID
public init(id: RequestID) {
self.id = id
}
}
@@ -1,21 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//
public struct CancelWorkDoneProgressNotification: LSPNotification {
public static let method: String = "window/workDoneProgress/cancel"
public var token: ProgressToken
public init(token: ProgressToken) {
self.token = token
}
}
@@ -1,27 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// Notification from the client that the configuration of the workspace has changed.
///
/// - Note: the format of the settings is implementation-defined.
///
/// - Parameter settings: The changed workspace settings.
public struct DidChangeConfigurationNotification: LSPNotification {
public static let method: String = "workspace/didChangeConfiguration"
/// The changed workspace settings.
public var settings: WorkspaceSettingsChange
public init(settings: WorkspaceSettingsChange) {
self.settings = settings
}
}
@@ -1,23 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//
public struct DidChangeActiveDocumentNotification: LSPNotification {
public static let method: String = "window/didChangeActiveDocument"
/// The document that is being displayed in the active editor or `null` to indicate that either no document is active
/// or that the currently open document is not handled by SourceKit-LSP.
public var textDocument: TextDocumentIdentifier?
public init(textDocument: TextDocumentIdentifier?) {
self.textDocument = textDocument
}
}
@@ -1,45 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//
public struct DidCreateFilesNotification: LSPNotification {
public static let method: String = "workspace/didCreateFiles"
/// An array of all files/folders created in this operation.
public var files: [FileCreate]
public init(files: [FileCreate]) {
self.files = files
}
}
public struct DidRenameFilesNotification: LSPNotification {
public static let method: String = "workspace/didRenameFiles"
/// An array of all files/folders renamed in this operation. When a folder
/// is renamed, only the folder will be included, and not its children.
public var files: [FileRename]
public init(files: [FileRename]) {
self.files = files
}
}
public struct DidDeleteFilesNotification: LSPNotification {
public static let method: String = "workspace/didDeleteFiles"
/// An array of all files/folders created in this operation.
public var files: [FileDelete]
public init(files: [FileDelete]) {
self.files = files
}
}
@@ -1,25 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 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
//
//===----------------------------------------------------------------------===//
/// Notification from the client when changes to watched files are detected.
///
/// - Parameter changes: The set of file changes.
public struct DidChangeWatchedFilesNotification: LSPNotification {
public static let method: String = "workspace/didChangeWatchedFiles"
/// The file changes.
public var changes: [FileEvent]
public init(changes: [FileEvent]) {
self.changes = changes
}
}
@@ -1,42 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// Notification from the client that the set of open workspace folders has changed.
///
/// - Parameter event: The set of changes.
///
/// Requires the `workspaceFolders` capability on both the client and server.
public struct DidChangeWorkspaceFoldersNotification: LSPNotification {
public static let method: String = "workspace/didChangeWorkspaceFolders"
/// The set of changes.
public var event: WorkspaceFoldersChangeEvent
public init(event: WorkspaceFoldersChangeEvent) {
self.event = event
}
}
/// The workspace folder change event.
public struct WorkspaceFoldersChangeEvent: Codable, Hashable, Sendable {
/// The array of added workspace folders
public var added: [WorkspaceFolder]?
/// The array of the removed workspace folders
public var removed: [WorkspaceFolder]?
public init(added: [WorkspaceFolder]? = nil, removed: [WorkspaceFolder]? = nil) {
self.added = added
self.removed = removed
}
}
@@ -1,19 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
/// Notification that the server process should exit.
///
/// This notification will come after the shutdown request finishes.
public struct ExitNotification: LSPNotification, Hashable {
public static let method: String = "exit"
public init() {}
}
@@ -1,18 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
/// Notification from the client that its own initialization of the language server has finished.
public struct InitializedNotification: LSPNotification, Hashable {
public static let method: String = "initialized"
public init() {}
}
@@ -1,199 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// Notification from the server containing a log message.
///
/// - Parameters:
/// - type: The kind of log message.
/// - message: The contents of the message.
public struct LogMessageNotification: LSPNotification, Hashable {
public static let method: String = "window/logMessage"
/// The kind of log message.
public var type: WindowMessageType
/// The contents of the message.
public var message: String
/// If specified, the client should log the message to a log with this name instead of the standard log for this LSP
/// server.
///
/// **(LSP Extension)**
public var logName: String?
/// If specified, allows grouping log messages that belong to the same originating task together, instead of logging
/// them in chronological order in which they were produced.
///
/// **(LSP Extension)** guarded by the experimental `structured-logs` feature.
public var structure: StructuredLogKind?
public init(type: WindowMessageType, message: String, logName: String? = nil, structure: StructuredLogKind? = nil) {
self.type = type
self.message = message
self.logName = logName
self.structure = structure
}
}
public enum StructuredLogKind: Codable, Hashable, Sendable {
case begin(StructuredLogBegin)
case report(StructuredLogReport)
case end(StructuredLogEnd)
public var taskID: String {
switch self {
case .begin(let begin): return begin.taskID
case .report(let report): return report.taskID
case .end(let end): return end.taskID
}
}
public init(from decoder: Decoder) throws {
if let begin = try? StructuredLogBegin(from: decoder) {
self = .begin(begin)
} else if let report = try? StructuredLogReport(from: decoder) {
self = .report(report)
} else if let end = try? StructuredLogEnd(from: decoder) {
self = .end(end)
} else {
let context = DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Expected StructuredLogBegin, StructuredLogReport, or StructuredLogEnd"
)
throw DecodingError.dataCorrupted(context)
}
}
public func encode(to encoder: Encoder) throws {
switch self {
case .begin(let begin):
try begin.encode(to: encoder)
case .report(let report):
try report.encode(to: encoder)
case .end(let end):
try end.encode(to: encoder)
}
}
}
/// Indicates the beginning of a new task that may receive updates with `StructuredLogReport` or `StructuredLogEnd`
/// payloads.
public struct StructuredLogBegin: Codable, Hashable, Sendable {
/// A succinct title that can be used to describe the task that started this structured.
public var title: String
/// A unique identifier, identifying the task this structured log message belongs to.
public var taskID: String
private enum CodingKeys: CodingKey {
case kind
case title
case taskID
}
public init(title: String, taskID: String) {
self.title = title
self.taskID = taskID
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard try container.decode(String.self, forKey: .kind) == "begin" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of StructuredLogBegin is not 'begin'"
)
}
self.title = try container.decode(String.self, forKey: .title)
self.taskID = try container.decode(String.self, forKey: .taskID)
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("begin", forKey: .kind)
try container.encode(self.title, forKey: .title)
try container.encode(self.taskID, forKey: .taskID)
}
}
/// Adds a new log message to a structured log without ending it.
public struct StructuredLogReport: Codable, Hashable, Sendable {
/// A unique identifier, identifying the task this structured log message belongs to.
public var taskID: String
private enum CodingKeys: CodingKey {
case kind
case taskID
}
public init(taskID: String) {
self.taskID = taskID
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard try container.decode(String.self, forKey: .kind) == "report" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of StructuredLogReport is not 'report'"
)
}
self.taskID = try container.decode(String.self, forKey: .taskID)
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("report", forKey: .kind)
try container.encode(self.taskID, forKey: .taskID)
}
}
/// Ends a structured log. No more `StructuredLogReport` updates should be sent for this task ID.
///
/// The task ID may be re-used for new structured logs by beginning a new structured log for that task.
public struct StructuredLogEnd: Codable, Hashable, Sendable {
/// A unique identifier, identifying the task this structured log message belongs to.
public var taskID: String
private enum CodingKeys: CodingKey {
case kind
case taskID
}
public init(taskID: String) {
self.taskID = taskID
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard try container.decode(String.self, forKey: .kind) == "end" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of StructuredLogEnd is not 'end'"
)
}
self.taskID = try container.decode(String.self, forKey: .taskID)
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("end", forKey: .kind)
try container.encode(self.taskID, forKey: .taskID)
}
}
@@ -1,30 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//
/// A notification to log the trace of the servers execution. The amount and content of these notifications depends on the current trace configuration. If trace is 'off', the server should not send any logTrace notification. If trace is 'messages', the server should not add the 'verbose' field in the LogTraceParams.
///
/// $/logTrace should be used for systematic trace reporting. For single debugging messages, the server should send window/logMessage notifications.
public struct LogTraceNotification: LSPNotification, Hashable, Codable {
public static let method: String = "$/logTrace"
/// The message to be logged.
public var message: String
/// Additional information that can be computed if the `trace` configuration
/// is set to `'verbose'`
public var verbose: String?
public init(message: String, verbose: String?) {
self.message = message
self.verbose = verbose
}
}
@@ -1,44 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// Notification from the server containing any diagnostics to show in a given document.
///
/// The publishDiagnostics notification provides the complete set of diagnostics and must be sent
/// whenever the set of active diagnostics change. For example, if a `didChange` notification from
/// the client fixes all of the existing errors, there should be a `publishDiagnostics` notification
/// with an empty `diagnostics = []`.
///
/// There is no guarantee about _when_ the `publishDiagnostics` notification will be sent, and the
/// server is free to not send a notification unless the set of diagnostics has actually changed, or
/// to coalesce the notification across multiple changes in a short period of time.
///
/// - Parameters:
/// - uri: The document in which the diagnostics should be shown.
/// - diagnostics: The complete list of diagnostics in the document, if any.
public struct PublishDiagnosticsNotification: LSPNotification, Hashable, Codable {
public static let method: String = "textDocument/publishDiagnostics"
/// The document in which the diagnostics should be shown.
public var uri: DocumentURI
/// Optional the version number of the document the diagnostics are published for.
public var version: Int?
/// The complete list of diagnostics in the document, if any.
public var diagnostics: [Diagnostic]
public init(uri: DocumentURI, version: Int? = nil, diagnostics: [Diagnostic]) {
self.uri = uri
self.version = version
self.diagnostics = diagnostics
}
}
@@ -1,29 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 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
//
//===----------------------------------------------------------------------===//
/// Re-open the given document, discarding any in-memory state.
///
/// This notification is designed to be used internally in SourceKit-LSP: When build setting have changed, we re-open
/// the document in sourcekitd to re-build its AST. This needs to be handled via a notification to ensure that no other
/// request for this document is executing at the same time.
///
/// **(LSP Extension)**
public struct ReopenTextDocumentNotification: LSPNotification, Hashable {
public static let method: String = "textDocument/reopen"
/// The document identifier and initial contents.
public var textDocument: TextDocumentIdentifier
public init(textDocument: TextDocumentIdentifier) {
self.textDocument = textDocument
}
}
@@ -1,23 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//
/// A notification that should be used by the client to modify the trace setting of the server.
public struct SetTraceNotification: LSPNotification, Hashable, Codable {
public static let method: String = "$/setTrace"
/// The new value that should be assigned to the trace setting.
public var value: Tracing
public init(value: Tracing) {
self.value = value
}
}
@@ -1,31 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
/// Notification from the server containing a message for the client to display.
///
/// - Parameters:
/// - type: The kind of message.
/// - message: The contents of the message.
public struct ShowMessageNotification: LSPNotification, Hashable {
public static let method: String = "window/showMessage"
/// The kind of message.
public var type: WindowMessageType
/// The contents of the message.
public var message: String
public init(type: WindowMessageType, message: String) {
self.type = type
self.message = message
}
}
@@ -1,224 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/// Notification from the client that a new document is open and its content should be managed by
/// the text synchronization notifications until it has been closed.
///
/// The `didOpen` notification provides the initial contents of the document. Thereafter, any
/// queries that need the content of this document should use the contents provided here (or updated
/// via subsequent `didChange` notifications) and should ignore the contents on disk.
///
/// An open document can be modified using the `didChange` notification, and when done closed using
/// the `didClose` notification. Once closed, the server can use the contents on disk, if needed.
/// A document can only be opened once at a time, and must be balanced by a `didClose` before being
/// opened again.
///
/// Servers that provide document synchronization should set the `textDocumentSync` server
/// capability.
///
/// - Parameter textDocument: The document identifier and initial contents.
public struct DidOpenTextDocumentNotification: LSPNotification, Hashable {
public static let method: String = "textDocument/didOpen"
/// The document identifier and initial contents.
public var textDocument: TextDocumentItem
public init(textDocument: TextDocumentItem) {
self.textDocument = textDocument
}
}
/// Notification that the given document is closed and no longer managed by the text synchronization
/// notifications.
///
/// The document must have previously been opened with `didOpen`. Closing the document returns
/// management of the document contents to disk, if appropriate.
///
/// - Parameter textDocument: The document to close, which must be currently open.
public struct DidCloseTextDocumentNotification: LSPNotification, Hashable {
public static let method: String = "textDocument/didClose"
/// The document to close, which must be currently open.
public var textDocument: TextDocumentIdentifier
public init(textDocument: TextDocumentIdentifier) {
self.textDocument = textDocument
}
}
/// Notification that the contents of the given document have been changed.
///
/// Updates the content of a document previously opened with `didOpen` by applying a list of
/// changes, which may either be full document replacements, or incremental edits.
///
/// Servers that support incremental edits should set the `change` text document sync option.
///
/// - Parameters:
/// - textDocument: The document to change and its current version identifier.
/// - contentChanges: Edits to the document.
public struct DidChangeTextDocumentNotification: LSPNotification, Hashable {
public static let method: String = "textDocument/didChange"
/// The document that did change. The version number points
/// to the version after all provided content changes have
/// been applied.
public var textDocument: VersionedTextDocumentIdentifier
/// The actual content changes. The content changes describe single state
/// changes to the document. So if there are two content changes c1 (at
/// array index 0) and c2 (at array index 1) for a document in state S then
/// c1 moves the document from S to S' and c2 from S' to S''. So c1 is
/// computed on the state S and c2 is computed on the state S'.
///
/// To mirror the content of a document using change events use the following
/// approach:
/// - start with the same initial content
/// - apply the 'textDocument/didChange' notifications in the order you
/// receive them.
/// - apply the `TextDocumentContentChangeEvent`s in a single notification
/// in the order you receive them.
public var contentChanges: [TextDocumentContentChangeEvent]
/// Force the LSP to rebuild its AST for the given file. This is useful for clangd to workaround clangd's assumption that
/// missing header files will stay missing.
/// **LSP Extension from clangd**.
public var forceRebuild: Bool? = nil
public init(
textDocument: VersionedTextDocumentIdentifier,
contentChanges: [TextDocumentContentChangeEvent],
forceRebuild: Bool? = nil
) {
self.textDocument = textDocument
self.contentChanges = contentChanges
self.forceRebuild = forceRebuild
}
}
/// Notification that the given document will be saved.
///
/// - Parameters:
/// - textDocument: The document that will be saved.
/// - reason: Whether this was user-initiated, auto-saved, etc.
///
/// Servers that support willSave should set the `willSave` text document sync option.
public struct WillSaveTextDocumentNotification: TextDocumentNotification, Hashable {
public static let method: String = "textDocument/willSave"
/// The document that will be saved.
public var textDocument: TextDocumentIdentifier
/// Whether this is user-initiated save, auto-saved, etc.
public var reason: TextDocumentSaveReason
public init(textDocument: TextDocumentIdentifier, reason: TextDocumentSaveReason) {
self.textDocument = textDocument
self.reason = reason
}
}
/// Notification that the given document was saved.
///
/// - Parameters:
/// - textDocument: The document that was saved.
/// - text: The content of the document at the time of save.
///
/// Servers that support didSave should set the `save` text document sync option.
public struct DidSaveTextDocumentNotification: TextDocumentNotification, Hashable {
public static let method: String = "textDocument/didSave"
/// The document that was saved.
public var textDocument: TextDocumentIdentifier
/// The content of the document at the time of save.
///
/// Only provided if the server specified `includeText == true`.
public var text: String?
public init(textDocument: TextDocumentIdentifier, text: String? = nil) {
self.textDocument = textDocument
self.text = text
}
}
/// The open notification is sent from the client to the server when a notebook document is opened. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidOpenNotebookDocumentNotification: LSPNotification, Hashable {
public static let method: String = "notebookDocument/didOpen"
/// The notebook document that got opened.
public var notebookDocument: NotebookDocument
/// The text documents that represent the content
/// of a notebook cell.
public var cellTextDocuments: [TextDocumentItem]
public init(notebookDocument: NotebookDocument, cellTextDocuments: [TextDocumentItem]) {
self.notebookDocument = notebookDocument
self.cellTextDocuments = cellTextDocuments
}
}
/// The change notification is sent from the client to the server when a notebook document changes. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidChangeNotebookDocumentNotification: LSPNotification, Hashable {
public static let method: String = "notebookDocument/didChange"
/// The notebook document that did change. The version number points
/// to the version after all provided changes have been applied.
public var notebookDocument: VersionedNotebookDocumentIdentifier
/// The actual changes to the notebook document.
///
/// The change describes single state change to the notebook document.
/// So it moves a notebook document, its cells and its cell text document
/// contents from state S to S'.
///
/// To mirror the content of a notebook using change events use the
/// following approach:
/// - start with the same initial content
/// - apply the 'notebookDocument/didChange' notifications in the order
/// you receive them.
public var change: NotebookDocumentChangeEvent
public init(notebookDocument: VersionedNotebookDocumentIdentifier, change: NotebookDocumentChangeEvent) {
self.notebookDocument = notebookDocument
self.change = change
}
}
/// The save notification is sent from the client to the server when a notebook document is saved. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidSaveNotebookDocumentNotification: LSPNotification {
public static let method: String = "notebookDocument/didSave"
/// The notebook document that got saved.
public var notebookDocument: NotebookDocumentIdentifier
public init(notebookDocument: NotebookDocumentIdentifier) {
self.notebookDocument = notebookDocument
}
}
/// The close notification is sent from the client to the server when a notebook document is closed. It is only sent by a client if the server requested the synchronization mode `notebook` in its `notebookDocumentSync` capability.
public struct DidCloseNotebookDocumentNotification: LSPNotification {
public static let method: String = "notebookDocument/didClose"
/// The notebook document that got closed.
public var notebookDocument: NotebookDocumentIdentifier
/// The text documents that represent the content
/// of a notebook cell that got closed.
public var cellTextDocuments: [TextDocumentIdentifier]
public init(notebookDocument: NotebookDocumentIdentifier, cellTextDocuments: [TextDocumentIdentifier]) {
self.notebookDocument = notebookDocument
self.cellTextDocuments = cellTextDocuments
}
}
@@ -1,224 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//
public struct WorkDoneProgress: LSPNotification, Hashable {
public static let method: String = "$/progress"
/// The progress token provided by the client or server.
public var token: ProgressToken
/// The progress data.
public var value: WorkDoneProgressKind
public init(token: ProgressToken, value: WorkDoneProgressKind) {
self.token = token
self.value = value
}
}
public enum WorkDoneProgressKind: Codable, Hashable, Sendable {
case begin(WorkDoneProgressBegin)
case report(WorkDoneProgressReport)
case end(WorkDoneProgressEnd)
public init(from decoder: Decoder) throws {
if let begin = try? WorkDoneProgressBegin(from: decoder) {
self = .begin(begin)
} else if let report = try? WorkDoneProgressReport(from: decoder) {
self = .report(report)
} else if let end = try? WorkDoneProgressEnd(from: decoder) {
self = .end(end)
} else {
let context = DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Expected WorkDoneProgressBegin, WorkDoneProgressReport, or WorkDoneProgressEnd"
)
throw DecodingError.dataCorrupted(context)
}
}
public func encode(to encoder: Encoder) throws {
switch self {
case .begin(let begin):
try begin.encode(to: encoder)
case .report(let report):
try report.encode(to: encoder)
case .end(let end):
try end.encode(to: encoder)
}
}
}
public struct WorkDoneProgressBegin: Codable, Hashable, Sendable {
/// Mandatory title of the progress operation. Used to briefly inform about
/// the kind of operation being performed.
///
/// Examples: "Indexing" or "Linking dependencies".
public var title: String
/// Controls if a cancel button should show to allow the user to cancel the
/// long running operation. Clients that don't support cancellation are
/// allowed to ignore the setting.
public var cancellable: Bool?
/// Optional, more detailed associated progress message. Contains
/// complementary information to the `title`.
///
/// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
/// If unset, the previous progress message (if any) is still valid.
public var message: String?
/// Optional progress percentage to display (value 100 is considered 100%).
/// If not provided infinite progress is assumed and clients are allowed
/// to ignore the `percentage` value in subsequent in report notifications.
///
/// The value should be steadily rising. Clients are free to ignore values
/// that are not following this rule. The value range is [0, 100]
public var percentage: Int?
public init(title: String, cancellable: Bool? = nil, message: String? = nil, percentage: Int? = nil) {
self.title = title
self.cancellable = cancellable
self.message = message
self.percentage = percentage
}
enum CodingKeys: CodingKey {
case kind
case title
case cancellable
case message
case percentage
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = try container.decode(String.self, forKey: .kind)
guard kind == "begin" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of WorkDoneProgressBegin is not 'begin'"
)
}
self.title = try container.decode(String.self, forKey: .title)
self.cancellable = try container.decodeIfPresent(Bool.self, forKey: .cancellable)
self.message = try container.decodeIfPresent(String.self, forKey: .message)
self.percentage = try container.decodeIfPresent(Int.self, forKey: .percentage)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("begin", forKey: .kind)
try container.encode(self.title, forKey: .title)
try container.encodeIfPresent(self.cancellable, forKey: .cancellable)
try container.encodeIfPresent(self.message, forKey: .message)
try container.encodeIfPresent(self.percentage, forKey: .percentage)
}
}
public struct WorkDoneProgressReport: Codable, Hashable, Sendable {
/// Controls enablement state of a cancel button. This property is only valid
/// if a cancel button got requested in the `WorkDoneProgressBegin` payload.
///
/// Clients that don't support cancellation or don't support control the
/// button's enablement state are allowed to ignore the setting.
public var cancellable: Bool?
/// Optional, more detailed associated progress message. Contains
/// complementary information to the `title`.
///
/// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
/// If unset, the previous progress message (if any) is still valid.
public var message: String?
/// Optional progress percentage to display (value 100 is considered 100%).
/// If not provided infinite progress is assumed and clients are allowed
/// to ignore the `percentage` value in subsequent in report notifications.
///
/// The value should be steadily rising. Clients are free to ignore values
/// that are not following this rule. The value range is [0, 100]
public var percentage: Int?
public init(cancellable: Bool? = nil, message: String? = nil, percentage: Int? = nil) {
self.cancellable = cancellable
self.message = message
self.percentage = percentage
}
enum CodingKeys: CodingKey {
case kind
case cancellable
case message
case percentage
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = try container.decode(String.self, forKey: .kind)
guard kind == "report" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of WorkDoneProgressReport is not 'report'"
)
}
self.cancellable = try container.decodeIfPresent(Bool.self, forKey: .cancellable)
self.message = try container.decodeIfPresent(String.self, forKey: .message)
self.percentage = try container.decodeIfPresent(Int.self, forKey: .percentage)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("report", forKey: .kind)
try container.encodeIfPresent(self.cancellable, forKey: .cancellable)
try container.encodeIfPresent(self.message, forKey: .message)
try container.encodeIfPresent(self.percentage, forKey: .percentage)
}
}
public struct WorkDoneProgressEnd: Codable, Hashable, Sendable {
/// Optional, a final message indicating to for example indicate the outcome
/// of the operation.
public var message: String?
public init(message: String? = nil) {
self.message = message
}
enum CodingKeys: CodingKey {
case kind
case message
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = try container.decode(String.self, forKey: .kind)
guard kind == "end" else {
throw DecodingError.dataCorruptedError(
forKey: .kind,
in: container,
debugDescription: "Kind of WorkDoneProgressReport is not 'end'"
)
}
self.message = try container.decodeIfPresent(String.self, forKey: .message)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode("end", forKey: .kind)
try container.encodeIfPresent(self.message, forKey: .message)
}
}
@@ -1,94 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 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
//
//===----------------------------------------------------------------------===//
extension Range where Bound == Position {
/// Create a range for a single position.
public init(_ pos: Position) {
self = pos..<pos
}
}
/// An LSP-compatible encoding for `Range<Position>`, for use with `CustomCodable`.
public struct PositionRange: CustomCodableWrapper {
public var wrappedValue: Range<Position>
public init(wrappedValue: Range<Position>) {
self.wrappedValue = wrappedValue
}
fileprivate enum CodingKeys: String, CodingKey {
case lowerBound = "start"
case upperBound = "end"
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let lhs = try container.decode(Position.self, forKey: .lowerBound)
let rhs = try container.decode(Position.self, forKey: .upperBound)
self.wrappedValue = lhs..<rhs
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(wrappedValue.lowerBound, forKey: .lowerBound)
try container.encode(wrappedValue.upperBound, forKey: .upperBound)
}
}
/// An LSP-compatible encoding for `Array<Range<Position>>`, for use with `CustomCodable`.
public struct PositionRangeArray: CustomCodableWrapper {
public var wrappedValue: [Range<Position>]
public init(wrappedValue: [Range<Position>]) {
self.wrappedValue = wrappedValue
}
public init(from decoder: Decoder) throws {
var values: [Range<Position>] = []
var arrayContainer = try decoder.unkeyedContainer()
values.reserveCapacity(arrayContainer.count ?? 1)
while !arrayContainer.isAtEnd {
let range = try arrayContainer.decode(PositionRange.self)
values.append(range.wrappedValue)
}
self.wrappedValue = values
}
public func encode(to encoder: Encoder) throws {
var arrayContainer = encoder.unkeyedContainer()
for rangeValue in wrappedValue {
try arrayContainer.encode(PositionRange(wrappedValue: rangeValue))
}
}
}
extension Range: LSPAnyCodable where Bound == Position {
public init?(fromLSPDictionary dictionary: [String: LSPAny]) {
guard case .dictionary(let start)? = dictionary[PositionRange.CodingKeys.lowerBound.stringValue],
let startPosition = Position(fromLSPDictionary: start),
case .dictionary(let end)? = dictionary[PositionRange.CodingKeys.upperBound.stringValue],
let endPosition = Position(fromLSPDictionary: end)
else {
return nil
}
self = startPosition..<endPosition
}
public func encodeToLSPAny() -> LSPAny {
return .dictionary([
PositionRange.CodingKeys.lowerBound.stringValue: lowerBound.encodeToLSPAny(),
PositionRange.CodingKeys.upperBound.stringValue: upperBound.encodeToLSPAny(),
])
}
}
@@ -1,48 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
public enum RequestID: Hashable, Sendable {
case string(String)
case number(Int)
}
extension RequestID: Codable {
public init(from decoder: Decoder) throws {
let value = try decoder.singleValueContainer()
if let intValue = try? value.decode(Int.self) {
self = .number(intValue)
} else if let strValue = try? value.decode(String.self) {
self = .string(strValue)
} else {
throw MessageDecodingError.invalidRequest("could not decode request id")
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let value):
try container.encode(value)
case .number(let value):
try container.encode(value)
}
}
}
extension RequestID: CustomStringConvertible {
public var description: String {
switch self {
case .number(let n): return String(n)
case .string(let s): return "\"\(s)\""
}
}
}

Some files were not shown because too many files have changed in this diff Show More