mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-06-24 12:21:58 +02:00
1c99daabef
Previously, test discovery used the semantic index as the primary source and fell back to the syntactic index only for files where the semantic index was out-of-date. This meant test locations came from the semantic index, which only records a point position rather than the full symbol range. Flip the priority: use syntactic scan results as the primary source (which have correct location ranges) and supplement with semantic index results. The semantic results are range-fixed via 'textDocument/documentSymbol' before being returned. This logic is unified into a single 'combineTests' helper shared by both 'workspaceTests' and 'documentTests'. Also fix 'SyntacticSwiftXCTestScanner' to emit extensions as proper 'AnnotatedTestItem' nodes (with 'isExtension: true') rather than a flat list of methods, so extension test methods are correctly merged into their class via 'mergingTestsInExtensions'. The class and extension visitors are unified through a shared 'handleClassOrExtension' helper.
112 lines
3.5 KiB
Swift
112 lines
3.5 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 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 Foundation
|
|
import IndexStoreDB
|
|
@_spi(SourceKitLSP) package import LanguageServerProtocol
|
|
package import SKOptions
|
|
package import SourceKitLSP
|
|
import SwiftExtensions
|
|
package import SwiftSyntax
|
|
package import ToolchainRegistry
|
|
|
|
package actor DocumentationLanguageService: LanguageService, Sendable {
|
|
/// The ``SourceKitLSPServer`` instance that created this `DocumentationLanguageService`.
|
|
private(set) weak var sourceKitLSPServer: SourceKitLSPServer?
|
|
|
|
let documentationManager: DocCDocumentationManager
|
|
|
|
var documentManager: DocumentManager {
|
|
get throws {
|
|
guard let sourceKitLSPServer else {
|
|
throw ResponseError.unknown("Connection to the editor closed")
|
|
}
|
|
return sourceKitLSPServer.documentManager
|
|
}
|
|
}
|
|
|
|
package static var experimentalCapabilities: [String: LSPAny] {
|
|
return [
|
|
DoccDocumentationRequest.method: .dictionary(["version": .int(1)])
|
|
]
|
|
}
|
|
|
|
package init(
|
|
sourceKitLSPServer: SourceKitLSPServer,
|
|
toolchain: Toolchain,
|
|
options: SourceKitLSPOptions,
|
|
hooks: Hooks,
|
|
workspace: Workspace
|
|
) async throws {
|
|
self.sourceKitLSPServer = sourceKitLSPServer
|
|
self.documentationManager = DocCDocumentationManager(buildServerManager: workspace.buildServerManager)
|
|
}
|
|
|
|
package nonisolated func canHandle(workspace: Workspace, toolchain: Toolchain) -> Bool {
|
|
return true
|
|
}
|
|
|
|
package func initialize(
|
|
_ initialize: InitializeRequest
|
|
) async throws -> InitializeResult {
|
|
return InitializeResult(
|
|
capabilities: ServerCapabilities()
|
|
)
|
|
}
|
|
|
|
package func shutdown() async {
|
|
// Nothing to tear down
|
|
}
|
|
|
|
package func addStateChangeHandler(
|
|
handler: @escaping @Sendable (LanguageServerState, LanguageServerState) -> Void
|
|
) async {
|
|
// There is no underlying language server with which to report state
|
|
}
|
|
|
|
package func openDocument(
|
|
_ notification: DidOpenTextDocumentNotification,
|
|
snapshot: DocumentSnapshot
|
|
) async {
|
|
// The DocumentationLanguageService does not do anything with document events
|
|
}
|
|
|
|
package func closeDocument(_ notification: DidCloseTextDocumentNotification) async {
|
|
// The DocumentationLanguageService does not do anything with document events
|
|
}
|
|
|
|
package func reopenDocument(_ notification: ReopenTextDocumentNotification) async {
|
|
// The DocumentationLanguageService does not do anything with document events
|
|
}
|
|
|
|
package func syntacticTestItems(for snapshot: DocumentSnapshot) async -> [AnnotatedTestItem]? {
|
|
// We know documentation files have no test cases.
|
|
return []
|
|
}
|
|
|
|
package func syntacticPlaygrounds(
|
|
for snapshot: DocumentSnapshot,
|
|
in workspace: Workspace
|
|
) async -> [TextDocumentPlayground] {
|
|
return []
|
|
}
|
|
|
|
package func changeDocument(
|
|
_ notification: DidChangeTextDocumentNotification,
|
|
preEditSnapshot: DocumentSnapshot,
|
|
postEditSnapshot: DocumentSnapshot,
|
|
edits: [SwiftSyntax.SourceEdit]
|
|
) async {
|
|
// The DocumentationLanguageService does not do anything with document events
|
|
}
|
|
}
|