Skip to content

Commit 8fd3090

Browse files
handle *.md and *.tutorial files for Swift DocC
1 parent 3131ca3 commit 8fd3090

File tree

7 files changed

+352
-1
lines changed

7 files changed

+352
-1
lines changed

Sources/BuildSystemIntegration/BuildSystemManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
632632
}
633633

634634
switch language {
635-
case .swift:
635+
case .swift, .markdown, .tutorial:
636636
return await toolchainRegistry.preferredToolchain(containing: [\.sourcekitd, \.swift, \.swiftc])
637637
case .c, .cpp, .objective_c, .objective_cpp:
638638
return await toolchainRegistry.preferredToolchain(containing: [\.clang, \.clangd])

Sources/LanguageServerProtocol/SupportTypes/Language.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extension Language: CustomStringConvertible, CustomDebugStringConvertible {
9292
case .shellScript: return "Shell Script (Bash)"
9393
case .sql: return "SQL"
9494
case .swift: return "Swift"
95+
case .tutorial: return "Tutorial"
9596
case .typeScript: return "TypeScript"
9697
case .typeScriptReact: return "TypeScript React"
9798
case .tex: return "TeX"
@@ -153,6 +154,7 @@ public extension Language {
153154
static let shellScript = Language(rawValue: "shellscript") // Shell Script (Bash)
154155
static let sql = Language(rawValue: "sql")
155156
static let swift = Language(rawValue: "swift")
157+
static let tutorial = Language(rawValue: "tutorial")
156158
static let typeScript = Language(rawValue: "typescript")
157159
static let typeScriptReact = Language(rawValue: "typescriptreact") // TypeScript React
158160
static let tex = Language(rawValue: "tex")

Sources/SKTestSupport/Utils.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extension Language {
2626
var fileExtension: String {
2727
switch self {
2828
case .objective_c: return "m"
29+
case .markdown: return "md"
30+
case .tutorial: return "tutorial"
2931
default: return self.rawValue
3032
}
3133
}
@@ -37,6 +39,8 @@ extension Language {
3739
case "m": self = .objective_c
3840
case "mm": self = .objective_cpp
3941
case "swift": self = .swift
42+
case "md": self = .markdown
43+
case "tutorial": self = .tutorial
4044
default: return nil
4145
}
4246
}

Sources/SourceKitLSP/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ target_sources(SourceKitLSP PRIVATE
2424
Clang/ClangLanguageService.swift
2525
Clang/SemanticTokenTranslator.swift
2626
)
27+
target_sources(SourceKitLSP PRIVATE
28+
Documentation/DocumentationLanguageService.swift
29+
)
2730
target_sources(SourceKitLSP PRIVATE
2831
Swift/AdjustPositionToStartOfIdentifier.swift
2932
Swift/CodeActions/AddDocumentation.swift
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import BuildSystemIntegration
14+
import Csourcekitd
15+
import Dispatch
16+
import Foundation
17+
import IndexStoreDB
18+
import SKLogging
19+
import SemanticIndex
20+
import SwiftExtensions
21+
import SwiftParser
22+
import SwiftParserDiagnostics
23+
24+
#if compiler(>=6)
25+
package import LanguageServerProtocol
26+
package import SKOptions
27+
package import SwiftSyntax
28+
package import ToolchainRegistry
29+
#else
30+
import LanguageServerProtocol
31+
import SKOptions
32+
import SwiftSyntax
33+
import ToolchainRegistry
34+
#endif
35+
36+
package actor DocumentationLanguageService: LanguageService, Sendable {
37+
package init?(
38+
sourceKitLSPServer: SourceKitLSPServer,
39+
toolchain: Toolchain,
40+
options: SourceKitLSPOptions,
41+
testHooks: TestHooks,
42+
workspace: Workspace
43+
) async throws {}
44+
45+
package nonisolated func canHandle(workspace: Workspace) -> Bool {
46+
return true
47+
}
48+
49+
package func initialize(
50+
_ initialize: InitializeRequest
51+
) async throws -> InitializeResult {
52+
return InitializeResult(
53+
capabilities: ServerCapabilities()
54+
)
55+
}
56+
57+
package func clientInitialized(_ initialized: InitializedNotification) async {
58+
// Nothing to set up
59+
}
60+
61+
package func shutdown() async {
62+
// Nothing to tear down
63+
}
64+
65+
package func addStateChangeHandler(
66+
handler: @escaping @Sendable (LanguageServerState, LanguageServerState) -> Void
67+
) async {
68+
// There is no underlying language server with which to report state
69+
}
70+
71+
package func openDocument(
72+
_ notification: DidOpenTextDocumentNotification,
73+
snapshot: DocumentSnapshot
74+
) async {
75+
// The DocumentationLanguageService does not do anything with document events
76+
}
77+
78+
package func closeDocument(_ notification: DidCloseTextDocumentNotification) async {
79+
// The DocumentationLanguageService does not do anything with document events
80+
}
81+
82+
package func reopenDocument(_ notification: ReopenTextDocumentNotification) async {
83+
// The DocumentationLanguageService does not do anything with document events
84+
}
85+
86+
package func changeDocument(
87+
_ notification: DidChangeTextDocumentNotification,
88+
preEditSnapshot: DocumentSnapshot,
89+
postEditSnapshot: DocumentSnapshot,
90+
edits: [SwiftSyntax.SourceEdit]
91+
) async {
92+
// The DocumentationLanguageService does not do anything with document events
93+
}
94+
95+
package func willSaveDocument(_ notification: WillSaveTextDocumentNotification) async {
96+
// The DocumentationLanguageService does not do anything with document events
97+
}
98+
99+
package func didSaveDocument(_ notification: DidSaveTextDocumentNotification) async {
100+
// The DocumentationLanguageService does not do anything with document events
101+
}
102+
103+
package func documentUpdatedBuildSettings(_ uri: DocumentURI) async {
104+
// The DocumentationLanguageService does not do anything with document events
105+
}
106+
107+
package func documentDependenciesUpdated(_ uris: Set<DocumentURI>) async {
108+
// The DocumentationLanguageService does not do anything with document events
109+
}
110+
111+
package func completion(_ req: CompletionRequest) async throws -> CompletionList {
112+
.init(isIncomplete: false, items: [])
113+
}
114+
115+
package func hover(_ req: HoverRequest) async throws -> HoverResponse? {
116+
.none
117+
}
118+
119+
package func symbolInfo(
120+
_ request: SymbolInfoRequest
121+
) async throws -> [SymbolDetails] {
122+
[]
123+
}
124+
125+
package func openGeneratedInterface(
126+
document: DocumentURI,
127+
moduleName: String,
128+
groupName: String?,
129+
symbolUSR symbol: String?
130+
) async throws -> GeneratedInterfaceDetails? {
131+
nil
132+
}
133+
134+
package func definition(
135+
_ request: DefinitionRequest
136+
) async throws -> LocationsOrLocationLinksResponse? {
137+
nil
138+
}
139+
140+
package func declaration(
141+
_ request: DeclarationRequest
142+
) async throws -> LocationsOrLocationLinksResponse? {
143+
nil
144+
}
145+
146+
package func documentSymbolHighlight(
147+
_ req: DocumentHighlightRequest
148+
) async throws -> [DocumentHighlight]? {
149+
nil
150+
}
151+
152+
package func foldingRange(
153+
_ req: FoldingRangeRequest
154+
) async throws -> [FoldingRange]? {
155+
nil
156+
}
157+
158+
package func documentSymbol(
159+
_ req: DocumentSymbolRequest
160+
) async throws -> DocumentSymbolResponse? {
161+
nil
162+
}
163+
164+
package func documentColor(
165+
_ req: DocumentColorRequest
166+
) async throws -> [ColorInformation] {
167+
[]
168+
}
169+
170+
package func documentSemanticTokens(
171+
_ req: DocumentSemanticTokensRequest
172+
) async throws -> DocumentSemanticTokensResponse? {
173+
nil
174+
}
175+
176+
package func documentSemanticTokensDelta(
177+
_ req: DocumentSemanticTokensDeltaRequest
178+
) async throws -> DocumentSemanticTokensDeltaResponse? {
179+
nil
180+
}
181+
182+
package func documentSemanticTokensRange(
183+
_ req: DocumentSemanticTokensRangeRequest
184+
) async throws -> DocumentSemanticTokensResponse? {
185+
nil
186+
}
187+
188+
package func colorPresentation(
189+
_ req: ColorPresentationRequest
190+
) async throws -> [ColorPresentation] {
191+
[]
192+
}
193+
194+
package func codeAction(
195+
_ req: CodeActionRequest
196+
) async throws -> CodeActionRequestResponse? {
197+
nil
198+
}
199+
200+
package func inlayHint(
201+
_ req: InlayHintRequest
202+
) async throws -> [InlayHint] {
203+
[]
204+
}
205+
206+
package func codeLens(_ req: CodeLensRequest) async throws -> [CodeLens] {
207+
[]
208+
}
209+
210+
package func documentDiagnostic(
211+
_ req: DocumentDiagnosticsRequest
212+
) async throws -> DocumentDiagnosticReport {
213+
.full(.init(items: []))
214+
}
215+
216+
package func documentFormatting(
217+
_ req: DocumentFormattingRequest
218+
) async throws -> [TextEdit]? {
219+
nil
220+
}
221+
222+
package func documentRangeFormatting(
223+
_ req: LanguageServerProtocol.DocumentRangeFormattingRequest
224+
) async throws -> [LanguageServerProtocol.TextEdit]? {
225+
return nil
226+
}
227+
228+
package func documentOnTypeFormatting(_ req: DocumentOnTypeFormattingRequest) async throws -> [TextEdit]? {
229+
return nil
230+
}
231+
232+
package func rename(
233+
_ request: RenameRequest
234+
) async throws -> (edits: WorkspaceEdit, usr: String?) {
235+
(edits: .init(), usr: nil)
236+
}
237+
238+
package func editsToRename(
239+
locations renameLocations: [RenameLocation],
240+
in snapshot: DocumentSnapshot,
241+
oldName: CrossLanguageName,
242+
newName: CrossLanguageName
243+
) async throws -> [TextEdit] {
244+
[]
245+
}
246+
247+
package func prepareRename(
248+
_ request: PrepareRenameRequest
249+
) async throws -> (prepareRename: PrepareRenameResponse, usr: String?)? {
250+
nil
251+
}
252+
253+
package func indexedRename(
254+
_ request: IndexedRenameRequest
255+
) async throws -> WorkspaceEdit? {
256+
nil
257+
}
258+
259+
package func editsToRenameParametersInFunctionBody(
260+
snapshot: DocumentSnapshot,
261+
renameLocation: RenameLocation,
262+
newName: CrossLanguageName
263+
) async -> [TextEdit] {
264+
[]
265+
}
266+
267+
package func executeCommand(
268+
_ req: ExecuteCommandRequest
269+
) async throws -> LSPAny? {
270+
nil
271+
}
272+
273+
package func getReferenceDocument(
274+
_ req: GetReferenceDocumentRequest
275+
) async throws -> GetReferenceDocumentResponse {
276+
.init(content: "")
277+
}
278+
279+
package func syntacticDocumentTests(
280+
for uri: DocumentURI,
281+
in workspace: Workspace
282+
) async throws -> [AnnotatedTestItem]? {
283+
nil
284+
}
285+
286+
package func canonicalDeclarationPosition(
287+
of position: Position,
288+
in uri: DocumentURI
289+
) async -> Position? {
290+
nil
291+
}
292+
293+
package func crash() async {
294+
// There's no way to crash the DocumentationLanguageService
295+
}
296+
}

Sources/SourceKitLSP/LanguageServerType.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ import LanguageServerProtocol
1717
enum LanguageServerType: Hashable {
1818
case clangd
1919
case swift
20+
case documentation
2021

2122
init?(language: Language) {
2223
switch language {
2324
case .c, .cpp, .objective_c, .objective_cpp:
2425
self = .clangd
2526
case .swift:
2627
self = .swift
28+
case .markdown, .tutorial:
29+
self = .documentation
2730
default:
2831
return nil
2932
}
@@ -44,6 +47,8 @@ enum LanguageServerType: Hashable {
4447
return ClangLanguageService.self
4548
case .swift:
4649
return SwiftLanguageService.self
50+
case .documentation:
51+
return DocumentationLanguageService.self
4752
}
4853
}
4954
}

0 commit comments

Comments
 (0)