Skip to content

Commit dfe1046

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

File tree

81 files changed

+1465
-1188
lines changed

Some content is hidden

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

81 files changed

+1465
-1188
lines changed

Package.swift

Lines changed: 45 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
],
@@ -464,6 +465,7 @@ var targets: [Target] = [
464465
"SourceKitD",
465466
"SourceKitLSP",
466467
"SwiftExtensions",
468+
"SwiftLanguageService",
467469
"ToolchainRegistry",
468470
"TSCExtensions",
469471
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
@@ -533,17 +535,8 @@ var targets: [Target] = [
533535
"ToolchainRegistry",
534536
"TSCExtensions",
535537
.product(name: "IndexStoreDB", package: "indexstore-db"),
536-
.product(name: "Crypto", package: "swift-crypto"),
537538
.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-
]),
539+
] + swiftSyntaxDependencies(["SwiftSyntax"]),
547540
exclude: ["CMakeLists.txt"],
548541
swiftSettings: globalSwiftSettings
549542
),
@@ -597,6 +590,48 @@ var targets: [Target] = [
597590
swiftSettings: globalSwiftSettings
598591
),
599592

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

602637
.target(

Sources/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name sourcekit_lsp>")
22
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-DRESILIENT_LIBRARIES>")
33
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-swift-version 6>")
4-
add_subdirectory(BuildServerProtocol)
54
add_subdirectory(BuildServerIntegration)
5+
add_subdirectory(BuildServerProtocol)
66
add_subdirectory(CAtomics)
77
add_subdirectory(CCompletionScoring)
88
add_subdirectory(ClangLanguageService)
@@ -17,10 +17,11 @@ add_subdirectory(SemanticIndex)
1717
add_subdirectory(SKLogging)
1818
add_subdirectory(SKOptions)
1919
add_subdirectory(SKUtilities)
20-
add_subdirectory(SourceKitLSP)
21-
add_subdirectory(SourceKitD)
2220
add_subdirectory(sourcekit-lsp)
21+
add_subdirectory(SourceKitD)
22+
add_subdirectory(SourceKitLSP)
2323
add_subdirectory(SwiftExtensions)
24+
add_subdirectory(SwiftLanguageService)
2425
add_subdirectory(SwiftSourceKitClientPlugin)
2526
add_subdirectory(SwiftSourceKitPlugin)
2627
add_subdirectory(SwiftSourceKitPluginCommon)

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/SKTestSupport/SkipUnless.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import SKLogging
1818
import SourceKitD
1919
import SourceKitLSP
2020
import SwiftExtensions
21+
import SwiftLanguageService
2122
import TSCExtensions
2223
import ToolchainRegistry
2324
import XCTest
@@ -378,7 +379,7 @@ package actor SkipUnless {
378379

379380
let tokens = SyntaxHighlightingTokens(lspEncodedTokens: response.data)
380381
return tokens.tokens.last
381-
== SourceKitLSP.SyntaxHighlightingToken(
382+
== SyntaxHighlightingToken(
382383
range: Position(line: 1, utf16index: 4)..<Position(line: 1, utf16index: 11),
383384
kind: .variable,
384385
modifiers: []

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
}

0 commit comments

Comments
 (0)