Skip to content

Commit e5908a7

Browse files
committed
Move SwiftLanguageService into its own module
1 parent d887490 commit e5908a7

File tree

79 files changed

+1458
-1184
lines changed

Some content is hidden

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

79 files changed

+1458
-1184
lines changed

Package.swift

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ var targets: [Target] = [
267267
"SKLogging",
268268
"SKOptions",
269269
"SourceKitLSP",
270+
"SwiftLanguageService",
270271
"ToolchainRegistry",
271272
"TSCExtensions",
272273
],
@@ -533,17 +534,8 @@ var targets: [Target] = [
533534
"ToolchainRegistry",
534535
"TSCExtensions",
535536
.product(name: "IndexStoreDB", package: "indexstore-db"),
536-
.product(name: "Crypto", package: "swift-crypto"),
537537
.product(name: "Markdown", package: "swift-markdown"),
538-
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
539-
]
540-
+ swiftPMDependency([
541-
.product(name: "SwiftPM-auto", package: "swift-package-manager")
542-
])
543-
+ swiftSyntaxDependencies([
544-
"SwiftBasicFormat", "SwiftDiagnostics", "SwiftIDEUtils", "SwiftParser", "SwiftParserDiagnostics",
545-
"SwiftRefactor", "SwiftSyntax",
546-
]),
538+
] + swiftSyntaxDependencies(["SwiftSyntax"]),
547539
exclude: ["CMakeLists.txt"],
548540
swiftSettings: globalSwiftSettings
549541
),
@@ -597,6 +589,48 @@ var targets: [Target] = [
597589
swiftSettings: globalSwiftSettings
598590
),
599591

592+
// MARK: SwiftLanguageService
593+
594+
.target(
595+
name: "SwiftLanguageService",
596+
dependencies: [
597+
"BuildServerProtocol",
598+
"BuildServerIntegration",
599+
"Csourcekitd",
600+
"DocCDocumentation",
601+
"LanguageServerProtocol",
602+
"LanguageServerProtocolExtensions",
603+
"LanguageServerProtocolJSONRPC",
604+
"SemanticIndex",
605+
"SKLogging",
606+
"SKOptions",
607+
"SKUtilities",
608+
"SourceKitD",
609+
"SourceKitLSP",
610+
"SwiftExtensions",
611+
"ToolchainRegistry",
612+
"TSCExtensions",
613+
.product(name: "IndexStoreDB", package: "indexstore-db"),
614+
.product(name: "Crypto", package: "swift-crypto"),
615+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
616+
]
617+
+ swiftPMDependency([
618+
.product(name: "SwiftPM-auto", package: "swift-package-manager")
619+
])
620+
+ swiftSyntaxDependencies([
621+
"SwiftBasicFormat",
622+
"SwiftDiagnostics",
623+
"SwiftIDEUtils",
624+
"SwiftParser",
625+
"SwiftParserDiagnostics",
626+
"SwiftRefactor",
627+
"SwiftSyntax",
628+
"SwiftSyntaxBuilder",
629+
]),
630+
exclude: ["CMakeLists.txt"],
631+
swiftSettings: globalSwiftSettings
632+
),
633+
600634
// MARK: SwiftSourceKitClientPlugin
601635

602636
.target(

Sources/ClangLanguageService/ClangLanguageService.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import BuildServerIntegration
1414
import Foundation
15+
package import IndexStoreDB
1516
package import LanguageServerProtocol
1617
import LanguageServerProtocolExtensions
1718
import LanguageServerProtocolJSONRPC
@@ -100,14 +101,16 @@ package actor ClangLanguageService: LanguageService, MessageHandler {
100101

101102
/// The documents that have been opened and which language they have been
102103
/// opened with.
103-
private var openDocuments: [DocumentURI: Language] = [:]
104+
private var openDocuments: [DocumentURI: LanguageServerProtocol.Language] = [:]
104105

105106
/// Type to map `clangd`'s semantic token legend to SourceKit-LSP's.
106107
private var semanticTokensTranslator: SemanticTokensLegendTranslator? = nil
107108

108109
/// While `clangd` is running, its `Process` object.
109110
private var clangdProcess: Process?
110111

112+
package static var builtInCommands: [String] { [] }
113+
111114
/// Creates a language server for the given client referencing the clang binary specified in `toolchain`.
112115
/// Returns `nil` if `clangd` can't be found.
113116
package init?(
@@ -500,7 +503,7 @@ extension ClangLanguageService {
500503
throw ResponseError.unknown("Connection to the editor closed")
501504
}
502505

503-
let snapshot = try await sourceKitLSPServer.documentManager.latestSnapshot(req.textDocument.uri)
506+
let snapshot = try sourceKitLSPServer.documentManager.latestSnapshot(req.textDocument.uri)
504507
throw ResponseError.requestFailed(doccDocumentationError: .unsupportedLanguage(snapshot.language))
505508
}
506509
#endif
@@ -509,6 +512,13 @@ extension ClangLanguageService {
509512
return try await forwardRequestToClangd(req)
510513
}
511514

515+
package func symbolGraph(
516+
forOnDiskContentsOf symbolDocumentUri: DocumentURI,
517+
at location: SymbolLocation
518+
) async throws -> String? {
519+
return nil
520+
}
521+
512522
package func documentSymbolHighlight(_ req: DocumentHighlightRequest) async throws -> [DocumentHighlight]? {
513523
return try await forwardRequestToClangd(req)
514524
}
@@ -652,6 +662,10 @@ extension ClangLanguageService {
652662
return nil
653663
}
654664

665+
package static func syntacticTestItems(in uri: DocumentURI) async -> [AnnotatedTestItem] {
666+
return []
667+
}
668+
655669
package func editsToRename(
656670
locations renameLocations: [RenameLocation],
657671
in snapshot: DocumentSnapshot,

Sources/InProcessClient/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target_link_libraries(InProcessClient PUBLIC
1212
SKLogging
1313
SKOptions
1414
SourceKitLSP
15+
SwiftLanguageService
1516
ToolchainRegistry
1617
)
1718

Sources/InProcessClient/LanguageServiceRegistry+staticallyKnownServices.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import ClangLanguageService
1414
import LanguageServerProtocol
1515
package import SourceKitLSP
16+
import SwiftLanguageService
1617

1718
extension LanguageServiceRegistry {
1819
/// All types conforming to `LanguageService` that are known at compile time.

Sources/SourceKitLSP/CMakeLists.txt

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ add_library(SourceKitLSP STATIC
44
DocumentManager.swift
55
DocumentSnapshot+FromFileContents.swift
66
DocumentSnapshot+PositionConversions.swift
7+
GeneratedInterfaceDocumentURLData.swift
78
Hooks.swift
89
IndexProgressManager.swift
910
IndexStoreDB+MainFilesProvider.swift
10-
LanguageServiceRegistry.swift
1111
LanguageService.swift
12+
LanguageServiceRegistry.swift
1213
LogMessageNotification+representingStructureUsingEmojiPrefixIfNecessary.swift
14+
MacroExpansionReferenceDocumentURLData.swift
1315
MessageHandlingDependencyTracker.swift
16+
ReferenceDocumentURL.swift
1417
Rename.swift
1518
SemanticTokensLegend+SourceKitLSPLegend.swift
1619
SharedWorkDoneProgressManager.swift
1720
SourceKitIndexDelegate.swift
1821
SourceKitLSPCommandMetadata.swift
1922
SourceKitLSPServer.swift
2023
SymbolLocation+DocumentURI.swift
24+
SyntacticTestIndex.swift
2125
TestDiscovery.swift
2226
TextEdit+IsNoop.swift
2327
Workspace.swift
@@ -26,80 +30,27 @@ target_sources(SourceKitLSP PRIVATE
2630
Documentation/DocCDocumentationHandler.swift
2731
Documentation/DocumentationLanguageService.swift
2832
)
29-
target_sources(SourceKitLSP PRIVATE
30-
Swift/AdjustPositionToStartOfIdentifier.swift
31-
Swift/ClosureCompletionFormat.swift
32-
Swift/CodeActions/AddDocumentation.swift
33-
Swift/CodeActions/ConvertIntegerLiteral.swift
34-
Swift/CodeActions/ConvertJSONToCodableStruct.swift
35-
Swift/CodeActions/ConvertStringConcatenationToStringInterpolation.swift
36-
Swift/CodeActions/PackageManifestEdits.swift
37-
Swift/CodeActions/SyntaxCodeActionProvider.swift
38-
Swift/CodeActions/SyntaxCodeActions.swift
39-
Swift/CodeActions/SyntaxRefactoringCodeActionProvider.swift
40-
Swift/CodeCompletion.swift
41-
Swift/CodeCompletionSession.swift
42-
Swift/CommentXML.swift
43-
Swift/CursorInfo.swift
44-
Swift/Diagnostic.swift
45-
Swift/DiagnosticReportManager.swift
46-
Swift/DocumentFormatting.swift
47-
Swift/DocumentSymbols.swift
48-
Swift/ExpandMacroCommand.swift
49-
Swift/FoldingRange.swift
50-
Swift/GeneratedInterfaceDocumentURLData.swift
51-
Swift/GeneratedInterfaceManager.swift
52-
Swift/GeneratedInterfaceManager.swift
53-
Swift/MacroExpansion.swift
54-
Swift/MacroExpansionReferenceDocumentURLData.swift
55-
Swift/OpenInterface.swift
56-
Swift/RefactoringEdit.swift
57-
Swift/RefactoringResponse.swift
58-
Swift/ReferenceDocumentURL.swift
59-
Swift/RelatedIdentifiers.swift
60-
Swift/RewriteSourceKitPlaceholders.swift
61-
Swift/SemanticRefactorCommand.swift
62-
Swift/SemanticRefactoring.swift
63-
Swift/SemanticTokens.swift
64-
Swift/SwiftCodeLensScanner.swift
65-
Swift/SwiftCommand.swift
66-
Swift/SwiftLanguageService.swift
67-
Swift/SwiftTestingScanner.swift
68-
Swift/SymbolInfo.swift
69-
Swift/SyntacticSwiftXCTestScanner.swift
70-
Swift/SyntacticTestIndex.swift
71-
Swift/SyntaxHighlightingToken.swift
72-
Swift/SyntaxHighlightingTokenParser.swift
73-
Swift/SyntaxHighlightingTokens.swift
74-
Swift/SyntaxTreeManager.swift
75-
Swift/VariableTypeInfo.swift
76-
Swift/WithSnapshotFromDiskOpenedInSourcekitd.swift
77-
)
7833
set_target_properties(SourceKitLSP PROPERTIES
79-
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
34+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}
35+
)
8036
target_link_libraries(SourceKitLSP PUBLIC
8137
BuildServerProtocol
8238
BuildServerIntegration
8339
LanguageServerProtocol
8440
LanguageServerProtocolExtensions
85-
LanguageServerProtocolJSONRPC
8641
SemanticIndex
87-
SKLogging
8842
SKOptions
8943
SKUtilities
90-
SourceKitD
9144
SwiftExtensions
9245
ToolchainRegistry
9346
IndexStoreDB
94-
SwiftSyntax::SwiftBasicFormat
95-
SwiftSyntax::SwiftDiagnostics
96-
SwiftSyntax::SwiftIDEUtils
97-
SwiftSyntax::SwiftParser
98-
SwiftSyntax::SwiftParserDiagnostics
99-
SwiftSyntax::SwiftRefactor
100-
SwiftSyntax::SwiftSyntax)
47+
SwiftSyntax::SwiftSyntax
48+
)
10149
target_link_libraries(SourceKitLSP PRIVATE
102-
PackageModelSyntax
50+
LanguageServerProtocolJSONRPC
51+
SKLogging
52+
SourceKitD
10353
TSCExtensions
104-
$<$<NOT:$<PLATFORM_ID:Darwin>>:FoundationXML>)
54+
$<$<NOT:$<PLATFORM_ID:Darwin>>:FoundationXML>
55+
)
10556

Sources/SourceKitLSP/CapabilityRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftExtensions
2020
/// capabilities.
2121
package final actor CapabilityRegistry {
2222
/// The client's capabilities as they were reported when sourcekit-lsp was launched.
23-
package let clientCapabilities: ClientCapabilities
23+
package nonisolated let clientCapabilities: ClientCapabilities
2424

2525
// MARK: Tracking capabilities dynamically registered in the client
2626

Sources/SourceKitLSP/DocumentSnapshot+PositionConversions.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,23 +237,6 @@ extension DocumentSnapshot {
237237
)
238238
}
239239

240-
// MARK: Position <-> SourceKitDPosition
241-
242-
func sourcekitdPosition(
243-
of position: Position,
244-
callerFile: StaticString = #fileID,
245-
callerLine: UInt = #line
246-
) -> SourceKitDPosition {
247-
let utf8Column = lineTable.utf8ColumnAt(
248-
line: position.line,
249-
utf16Column: position.utf16index,
250-
callerFile: callerFile,
251-
callerLine: callerLine
252-
)
253-
// FIXME: Introduce new type for UTF-8 based positions
254-
return SourceKitDPosition(line: position.line + 1, utf8Column: utf8Column + 1)
255-
}
256-
257240
// MAR: Position <-> SymbolLocation
258241

259242
/// Converts the given UTF-8-offset-based `SymbolLocation` to a UTF-16-based line:column `Position`.

Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,10 @@ extension DocumentationLanguageService {
6464
fetchSymbolGraph: { location in
6565
guard let symbolWorkspace = try await workspaceForDocument(uri: location.documentUri),
6666
let languageService = try await languageService(for: location.documentUri, .swift, in: symbolWorkspace)
67-
as? SwiftLanguageService
6867
else {
6968
throw ResponseError.internalError("Unable to find Swift language service for \(location.documentUri)")
7069
}
71-
return try await languageService.withSnapshotFromDiskOpenedInSourcekitd(
72-
uri: location.documentUri,
73-
fallbackSettingsAfterTimeout: false
74-
) { (snapshot, compileCommand) in
75-
let (_, _, symbolGraph) = try await languageService.cursorInfo(
76-
snapshot,
77-
compileCommand: compileCommand,
78-
Range(snapshot.position(of: location)),
79-
includeSymbolGraph: true
80-
)
81-
return symbolGraph
82-
}
70+
return try await languageService.symbolGraph(forOnDiskContentsOf: location.documentUri, at: location)
8371
}
8472
)
8573
else {
@@ -89,21 +77,13 @@ extension DocumentationLanguageService {
8977
guard
9078
let symbolWorkspace = try await workspaceForDocument(uri: symbolDocumentUri),
9179
let languageService = try await languageService(for: symbolDocumentUri, .swift, in: symbolWorkspace)
92-
as? SwiftLanguageService
9380
else {
9481
throw ResponseError.internalError("Unable to find Swift language service for \(symbolDocumentUri)")
9582
}
96-
let symbolGraph = try await languageService.withSnapshotFromDiskOpenedInSourcekitd(
97-
uri: symbolDocumentUri,
98-
fallbackSettingsAfterTimeout: false
99-
) { snapshot, compileCommand in
100-
try await languageService.cursorInfo(
101-
snapshot,
102-
compileCommand: compileCommand,
103-
Range(snapshot.position(of: symbolOccurrence.location)),
104-
includeSymbolGraph: true
105-
).symbolGraph
106-
}
83+
let symbolGraph = try await languageService.symbolGraph(
84+
forOnDiskContentsOf: symbolDocumentUri,
85+
at: symbolOccurrence.location
86+
)
10787
guard let symbolGraph else {
10888
throw ResponseError.internalError("Unable to retrieve symbol graph for \(symbolOccurrence.symbol.name)")
10989
}

Sources/SourceKitLSP/Documentation/DocumentationLanguageService.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14+
package import IndexStoreDB
1415
package import LanguageServerProtocol
1516
package import SKOptions
1617
import SwiftExtensions
@@ -30,6 +31,8 @@ package actor DocumentationLanguageService: LanguageService, Sendable {
3031
}
3132
}
3233

34+
package static var builtInCommands: [String] { [] }
35+
3336
package init?(
3437
sourceKitLSPServer: SourceKitLSPServer,
3538
toolchain: Toolchain,
@@ -140,6 +143,13 @@ package actor DocumentationLanguageService: LanguageService, Sendable {
140143
[]
141144
}
142145

146+
package func symbolGraph(
147+
forOnDiskContentsOf symbolDocumentUri: DocumentURI,
148+
at location: SymbolLocation
149+
) async throws -> String? {
150+
return nil
151+
}
152+
143153
package func openGeneratedInterface(
144154
document: DocumentURI,
145155
moduleName: String,
@@ -271,6 +281,10 @@ package actor DocumentationLanguageService: LanguageService, Sendable {
271281
nil
272282
}
273283

284+
package static func syntacticTestItems(in uri: DocumentURI) async -> [AnnotatedTestItem] {
285+
return []
286+
}
287+
274288
package func canonicalDeclarationPosition(
275289
of position: Position,
276290
in uri: DocumentURI

0 commit comments

Comments
 (0)