From 024efc2fa17bc69e4c2da657a74c657cf2864c92 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 23 Apr 2025 18:02:34 +0200 Subject: [PATCH] Remove dependency from `SourceKitLSP` on `swift-docc-symbolkit` This way all dependencies on the `docc` libraries are wrapped inside the `DocCDocumentation` module. --- Package.swift | 1 - .../DocCDocumentation/EmptySymbolGraph.swift | 17 +++++++++++++++++ .../DoccDocumentationHandler.swift | 17 +---------------- 3 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 Sources/DocCDocumentation/EmptySymbolGraph.swift diff --git a/Package.swift b/Package.swift index cc7a6ebc..8d5c9c24 100644 --- a/Package.swift +++ b/Package.swift @@ -509,7 +509,6 @@ var targets: [Target] = [ .product(name: "Crypto", package: "swift-crypto"), .product(name: "Markdown", package: "swift-markdown"), .product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"), - .product(name: "SymbolKit", package: "swift-docc-symbolkit"), ] + swiftPMDependency([ .product(name: "SwiftPM-auto", package: "swift-package-manager") diff --git a/Sources/DocCDocumentation/EmptySymbolGraph.swift b/Sources/DocCDocumentation/EmptySymbolGraph.swift new file mode 100644 index 00000000..e041ca99 --- /dev/null +++ b/Sources/DocCDocumentation/EmptySymbolGraph.swift @@ -0,0 +1,17 @@ +import Foundation +import SymbolKit + +/// Generates a JSON string that represents an empty symbol graph for the given module name. +package func emptySymbolGraph(forModule moduleName: String) throws -> String? { + let symbolGraph = SymbolGraph( + metadata: SymbolGraph.Metadata( + formatVersion: SymbolGraph.SemanticVersion(major: 0, minor: 0, patch: 0), + generator: "SourceKit-LSP" + ), + module: SymbolGraph.Module(name: moduleName, platform: SymbolGraph.Platform()), + symbols: [], + relationships: [] + ) + let data = try JSONEncoder().encode(symbolGraph) + return String(data: data, encoding: .utf8) +} diff --git a/Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift b/Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift index dec395d8..362ff026 100644 --- a/Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift +++ b/Sources/SourceKitLSP/Documentation/DoccDocumentationHandler.swift @@ -19,7 +19,6 @@ package import LanguageServerProtocol import Markdown import SKUtilities import SemanticIndex -import SymbolKit extension DocumentationLanguageService { package func doccDocumentation(_ req: DoccDocumentationRequest) async throws -> DoccDocumentationResponse { @@ -107,23 +106,9 @@ extension DocumentationLanguageService { // Create a dummy symbol graph and tell SwiftDocC to convert the module name. // The version information isn't really all that important since we're creating // what is essentially an empty symbol graph. - let emptySymbolGraph = String( - data: try JSONEncoder().encode( - SymbolGraph( - metadata: SymbolGraph.Metadata( - formatVersion: SymbolGraph.SemanticVersion(major: 0, minor: 0, patch: 0), - generator: "SourceKit-LSP" - ), - module: SymbolGraph.Module(name: moduleName, platform: SymbolGraph.Platform()), - symbols: [], - relationships: [] - ) - ), - encoding: .utf8 - ) return try await documentationManager.renderDocCDocumentation( symbolUSR: moduleName, - symbolGraph: emptySymbolGraph, + symbolGraph: emptySymbolGraph(forModule: moduleName), markupFile: snapshot.text, moduleName: moduleName, catalogURL: catalogURL