Skip to content

Commit 0a95899

Browse files
make position optional
1 parent 3c318ec commit 0a95899

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Sources/LanguageServerProtocol/Error.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ extension ResponseError {
112112
return ResponseError(code: .workspaceNotOpen, message: "No workspace containing '\(uri)' found")
113113
}
114114

115+
public static func invalidParams(_ message: String) -> ResponseError {
116+
return ResponseError(code: .invalidParams, message: message)
117+
}
118+
115119
public static func methodNotFound(_ method: String) -> ResponseError {
116120
return ResponseError(code: .methodNotFound, message: "method not found: \(method)")
117121
}

Sources/SourceKitLSP/Documentation/DocumentationManager.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ package final actor DocumentationManager {
3535
_ documentURI: DocumentURI,
3636
at position: Position? = nil
3737
) async throws -> DoccDocumentationResponse {
38-
let position = position ?? Position(line: 0, utf16index: 0)
3938
guard let sourceKitLSPServer = sourceKitLSPServer else {
4039
throw ResponseError.internalError("SourceKit-LSP is shutting down")
4140
}
@@ -55,6 +54,9 @@ package final actor DocumentationManager {
5554
var overridingDocumentationComments = [String: [String]]()
5655
switch snapshot.language {
5756
case .swift:
57+
guard let position else {
58+
throw ResponseError.invalidParams("A position must be provided for Swift files")
59+
}
5860
guard let languageService = await sourceKitLSPServer.languageService(for: documentURI, .swift, in: workspace),
5961
let swiftLanguageService = languageService as? SwiftLanguageService
6062
else {
@@ -71,17 +73,17 @@ package final actor DocumentationManager {
7173
return .error(.noDocumentation)
7274
}
7375
// Retrieve the symbol graph as well as information about the symbol
74-
let position = await swiftLanguageService.adjustPositionToStartOfIdentifier(
76+
let symbolPosition = await swiftLanguageService.adjustPositionToStartOfIdentifier(
7577
snapshot.position(of: nearestDocumentableSymbol.position),
7678
in: snapshot
7779
)
7880
let (cursorInfo, _, symbolGraph) = try await swiftLanguageService.cursorInfo(
7981
documentURI,
80-
position..<position,
82+
Range(symbolPosition),
8183
includeSymbolGraph: true,
8284
fallbackSettingsAfterTimeout: false
8385
)
84-
guard let symbolGraph = symbolGraph,
86+
guard let symbolGraph,
8587
let cursorInfo = cursorInfo.first,
8688
let symbolUSR = cursorInfo.symbolInfo.usr
8789
else {

0 commit comments

Comments
 (0)