Skip to content

Commit 5db1179

Browse files
committed
Migrate getReferenceDocument to upstream textDocumentContent
1 parent d11c101 commit 5db1179

12 files changed

+37
-77
lines changed

Contributor Documentation/LSP Extensions.md

-27
Original file line numberDiff line numberDiff line change
@@ -595,30 +595,3 @@ export interface PeekDocumentsResult {
595595
success: boolean;
596596
}
597597
```
598-
599-
## `workspace/getReferenceDocument`
600-
601-
Request from the client to the server asking for contents of a URI having a custom scheme.
602-
For example: "sourcekit-lsp:"
603-
604-
Enable the experimental client capability `"workspace/getReferenceDocument"` so that the server responds with reference document URLs for certain requests or commands whenever possible.
605-
606-
- params: `GetReferenceDocumentParams`
607-
608-
- result: `GetReferenceDocumentResponse`
609-
610-
```ts
611-
export interface GetReferenceDocumentParams {
612-
/**
613-
* The `DocumentUri` of the custom scheme url for which content is required
614-
*/
615-
uri: DocumentUri;
616-
}
617-
618-
/**
619-
* Response containing `content` of `GetReferenceDocumentRequest`
620-
*/
621-
export interface GetReferenceDocumentResult {
622-
content: string;
623-
}
624-
```

Sources/LanguageServerProtocol/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ add_library(LanguageServerProtocol STATIC
5555
Requests/ExecuteCommandRequest.swift
5656
Requests/FoldingRangeRequest.swift
5757
Requests/FormattingRequests.swift
58-
Requests/GetReferenceDocumentRequest.swift
5958
Requests/HoverRequest.swift
6059
Requests/ImplementationRequest.swift
6160
Requests/IndexedRenameRequest.swift
@@ -79,6 +78,7 @@ add_library(LanguageServerProtocol STATIC
7978
Requests/ShutdownRequest.swift
8079
Requests/SignatureHelpRequest.swift
8180
Requests/SymbolInfoRequest.swift
81+
Requests/TextDocumentContentRequest.swift
8282
Requests/TriggerReindexRequest.swift
8383
Requests/TypeDefinitionRequest.swift
8484
Requests/TypeHierarchyPrepareRequest.swift

Sources/LanguageServerProtocol/Messages.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public let builtinRequests: [_RequestType.Type] = [
4848
DocumentTestsRequest.self,
4949
ExecuteCommandRequest.self,
5050
FoldingRangeRequest.self,
51-
GetReferenceDocumentRequest.self,
5251
HoverRequest.self,
5352
ImplementationRequest.self,
5453
InitializeRequest.self,
@@ -71,6 +70,7 @@ public let builtinRequests: [_RequestType.Type] = [
7170
ShutdownRequest.self,
7271
SignatureHelpRequest.self,
7372
SymbolInfoRequest.self,
73+
TextDocumentContentRequest.self,
7474
TriggerReindexRequest.self,
7575
TypeDefinitionRequest.self,
7676
TypeHierarchyPrepareRequest.self,

Sources/LanguageServerProtocol/Requests/GetReferenceDocumentRequest.swift Sources/LanguageServerProtocol/Requests/TextDocumentContentRequest.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// Request from the client to the server asking for contents of a URI having a custom scheme **(LSP Extension)**
13+
/// Request from the client to the server asking for contents of a URI having a custom scheme
1414
/// For example: "sourcekit-lsp:"
1515
///
1616
/// - Parameters:
1717
/// - uri: The `DocumentUri` of the custom scheme url for which content is required
1818
///
19-
/// - Returns: `GetReferenceDocumentResponse` which contains the `content` to be displayed.
19+
/// - Returns: `TextDocumentContentResponse` which contains the `content` to be displayed.
2020
///
2121
/// ### LSP Extension
2222
///
2323
/// This request is an extension to LSP supported by SourceKit-LSP.
24-
/// Enable the experimental client capability `"workspace/getReferenceDocument"` so that the server responds with
24+
/// Enable the experimental client capability `"workspace/textDocumentContent"` so that the server responds with
2525
/// reference document URLs for certain requests or commands whenever possible.
26-
public struct GetReferenceDocumentRequest: RequestType {
27-
public static let method: String = "workspace/getReferenceDocument"
28-
public typealias Response = GetReferenceDocumentResponse
26+
public struct TextDocumentContentRequest: RequestType {
27+
public static let method: String = "workspace/textDocumentContent"
28+
public typealias Response = TextDocumentContentResponse
2929

3030
public var uri: DocumentURI
3131

@@ -34,11 +34,11 @@ public struct GetReferenceDocumentRequest: RequestType {
3434
}
3535
}
3636

37-
/// Response containing `content` of `GetReferenceDocumentRequest`
38-
public struct GetReferenceDocumentResponse: ResponseType {
39-
public var content: String
37+
/// Response containing `text` of `TextDocumentContentRequest`
38+
public struct TextDocumentContentResponse: ResponseType {
39+
public var text: String
4040

41-
public init(content: String) {
42-
self.content = content
41+
public init(text: String) {
42+
self.text = text
4343
}
4444
}

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ extension ClangLanguageService {
648648
return try await forwardRequestToClangd(req)
649649
}
650650

651-
func getReferenceDocument(_ req: GetReferenceDocumentRequest) async throws -> GetReferenceDocumentResponse {
651+
func textDocumentContent(_ req: TextDocumentContentRequest) async throws -> TextDocumentContentResponse {
652652
throw ResponseError.unknown("unsupported method")
653653
}
654654
}

Sources/SourceKitLSP/LanguageService.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ package protocol LanguageService: AnyObject, Sendable {
252252

253253
func executeCommand(_ req: ExecuteCommandRequest) async throws -> LSPAny?
254254

255-
func getReferenceDocument(_ req: GetReferenceDocumentRequest) async throws -> GetReferenceDocumentResponse
255+
func textDocumentContent(_ req: TextDocumentContentRequest) async throws -> TextDocumentContentResponse
256256

257257
/// Perform a syntactic scan of the file at the given URI for test cases and test classes.
258258
///

Sources/SourceKitLSP/MessageHandlingDependencyTracker.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ enum MessageHandlingDependencyTracker: DependencyTracker {
179179
} else {
180180
self = .freestanding
181181
}
182-
case let request as GetReferenceDocumentRequest:
182+
case let request as TextDocumentContentRequest:
183183
self = .documentRequest(request.uri)
184184
case is InitializeRequest:
185185
self = .globalConfigurationChange

Sources/SourceKitLSP/SourceKitLSPServer.swift

+4-16
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ extension SourceKitLSPServer: MessageHandler {
746746
await request.reply { try await executeCommand(request.params) }
747747
case let request as RequestAndReply<FoldingRangeRequest>:
748748
await self.handleRequest(for: request, requestHandler: self.foldingRange)
749-
case let request as RequestAndReply<GetReferenceDocumentRequest>:
750-
await request.reply { try await getReferenceDocument(request.params) }
749+
case let request as RequestAndReply<TextDocumentContentRequest>:
750+
await request.reply { try await textDocumentContent(request.params) }
751751
case let request as RequestAndReply<HoverRequest>:
752752
await self.handleRequest(for: request, requestHandler: self.hover)
753753
case let request as RequestAndReply<ImplementationRequest>:
@@ -986,8 +986,6 @@ extension SourceKitLSPServer {
986986
//
987987
// The below is a workaround for the vscode-swift extension since it cannot set client capabilities.
988988
// It passes "workspace/peekDocuments" through the `initializationOptions`.
989-
//
990-
// Similarly, for "workspace/getReferenceDocument".
991989
var clientCapabilities = req.capabilities
992990
if case .dictionary(let initializationOptions) = req.initializationOptions {
993991
if let peekDocuments = initializationOptions["workspace/peekDocuments"] {
@@ -999,15 +997,6 @@ extension SourceKitLSPServer {
999997
}
1000998
}
1001999

1002-
if let getReferenceDocument = initializationOptions["workspace/getReferenceDocument"] {
1003-
if case .dictionary(var experimentalCapabilities) = clientCapabilities.experimental {
1004-
experimentalCapabilities["workspace/getReferenceDocument"] = getReferenceDocument
1005-
clientCapabilities.experimental = .dictionary(experimentalCapabilities)
1006-
} else {
1007-
clientCapabilities.experimental = .dictionary(["workspace/getReferenceDocument": getReferenceDocument])
1008-
}
1009-
}
1010-
10111000
// The client announces what CodeLenses it supports, and the LSP will only return
10121001
// ones found in the supportedCommands dictionary.
10131002
if let codeLens = initializationOptions["textDocument/codeLens"],
@@ -1176,7 +1165,6 @@ extension SourceKitLSPServer {
11761165
"workspace/tests": .dictionary(["version": .int(2)]),
11771166
"textDocument/tests": .dictionary(["version": .int(2)]),
11781167
"workspace/triggerReindex": .dictionary(["version": .int(1)]),
1179-
"workspace/getReferenceDocument": .dictionary(["version": .int(1)]),
11801168
])
11811169
)
11821170
}
@@ -1744,7 +1732,7 @@ extension SourceKitLSPServer {
17441732
return try await languageService.executeCommand(executeCommand)
17451733
}
17461734

1747-
func getReferenceDocument(_ req: GetReferenceDocumentRequest) async throws -> GetReferenceDocumentResponse {
1735+
func textDocumentContent(_ req: TextDocumentContentRequest) async throws -> TextDocumentContentResponse {
17481736
let primaryFileURI = try ReferenceDocumentURL(from: req.uri).primaryFile
17491737

17501738
guard let workspace = await workspaceForDocument(uri: primaryFileURI) else {
@@ -1755,7 +1743,7 @@ extension SourceKitLSPServer {
17551743
throw ResponseError.unknown("No Language Service for URI: \(primaryFileURI)")
17561744
}
17571745

1758-
return try await languageService.getReferenceDocument(req)
1746+
return try await languageService.textDocumentContent(req)
17591747
}
17601748

17611749
func codeAction(

Sources/SourceKitLSP/Swift/MacroExpansion.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ extension SwiftLanguageService {
218218
}
219219

220220
if case .dictionary(let experimentalCapabilities) = self.capabilityRegistry.clientCapabilities.experimental,
221-
case .bool(true) = experimentalCapabilities["workspace/peekDocuments"],
222-
case .bool(true) = experimentalCapabilities["workspace/getReferenceDocument"]
221+
case .bool(true) = experimentalCapabilities["workspace/peekDocuments"]
223222
{
224223
let expansionURIs = try macroExpansionReferenceDocumentURLs.map {
225224
return DocumentURI(try $0.url)

Sources/SourceKitLSP/Swift/ReferenceDocumentURL.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import LanguageServerProtocol
1515

1616
/// A Reference Document is a document whose url scheme is `sourcekit-lsp:` and whose content can only be retrieved
17-
/// using `GetReferenceDocumentRequest`. The enum represents a specific type of reference document and its
17+
/// using `TextDocumentContentRequest`. The enum represents a specific type of reference document and its
1818
/// associated value represents the data necessary to generate the document's contents and its url
1919
///
2020
/// The `url` will be of the form: `sourcekit-lsp://<document-type>/<display-name>?<parameters>`

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1002,13 +1002,13 @@ extension SwiftLanguageService {
10021002
return nil
10031003
}
10041004

1005-
package func getReferenceDocument(_ req: GetReferenceDocumentRequest) async throws -> GetReferenceDocumentResponse {
1005+
package func textDocumentContent(_ req: TextDocumentContentRequest) async throws -> TextDocumentContentResponse {
10061006
let referenceDocumentURL = try ReferenceDocumentURL(from: req.uri)
10071007

10081008
switch referenceDocumentURL {
10091009
case let .macroExpansion(data):
1010-
return GetReferenceDocumentResponse(
1011-
content: try await macroExpansionManager.macroExpansion(for: data)
1010+
return TextDocumentContentResponse(
1011+
text: try await macroExpansionManager.macroExpansion(for: data)
10121012
)
10131013
}
10141014
}

Tests/SourceKitLSPTests/ExpandMacroTests.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ final class ExpandMacroTests: XCTestCase {
114114

115115
var filesContents = [String]()
116116
for uri in uris {
117-
let result = try await project.testClient.send(GetReferenceDocumentRequest(uri: uri))
117+
let result = try await project.testClient.send(TextDocumentContentRequest(uri: uri))
118118

119-
filesContents.append(result.content)
119+
filesContents.append(result.text)
120120
}
121121

122122
XCTAssertEqual(
@@ -290,9 +290,9 @@ final class ExpandMacroTests: XCTestCase {
290290

291291
var filesContents = [String]()
292292
for uri in uris {
293-
let result = try await project.testClient.send(GetReferenceDocumentRequest(uri: uri))
293+
let result = try await project.testClient.send(TextDocumentContentRequest(uri: uri))
294294

295-
filesContents.append(result.content)
295+
filesContents.append(result.text)
296296
}
297297

298298
XCTAssertEqual(
@@ -473,10 +473,10 @@ final class ExpandMacroTests: XCTestCase {
473473
try await fulfillmentOfOrThrow([outerPeekDocumentRequestReceived])
474474

475475
let outerPeekDocumentURI = try XCTUnwrap(outerPeekDocumentsRequestURIs.value?.only)
476-
let outerMacroExpansion = try await project.testClient.send(GetReferenceDocumentRequest(uri: outerPeekDocumentURI))
476+
let outerMacroExpansion = try await project.testClient.send(TextDocumentContentRequest(uri: outerPeekDocumentURI))
477477

478-
guard outerMacroExpansion.content == "/* padding */ #intermediate" else {
479-
XCTFail("Received unexpected macro expansion content: \(outerMacroExpansion.content)")
478+
guard outerMacroExpansion.text == "/* padding */ #intermediate" else {
479+
XCTFail("Received unexpected macro expansion content: \(outerMacroExpansion.text)")
480480
return
481481
}
482482

@@ -509,11 +509,11 @@ final class ExpandMacroTests: XCTestCase {
509509

510510
let intermediatePeekDocumentURI = try XCTUnwrap(intermediatePeekDocumentsRequestURIs.value?.only)
511511
let intermediateMacroExpansion = try await project.testClient.send(
512-
GetReferenceDocumentRequest(uri: intermediatePeekDocumentURI)
512+
TextDocumentContentRequest(uri: intermediatePeekDocumentURI)
513513
)
514514

515-
guard intermediateMacroExpansion.content == "#stringify(1 + 2)" else {
516-
XCTFail("Received unexpected macro expansion content: \(intermediateMacroExpansion.content)")
515+
guard intermediateMacroExpansion.text == "#stringify(1 + 2)" else {
516+
XCTFail("Received unexpected macro expansion content: \(intermediateMacroExpansion.text)")
517517
return
518518
}
519519

@@ -545,8 +545,8 @@ final class ExpandMacroTests: XCTestCase {
545545
try await fulfillmentOfOrThrow([innerPeekDocumentRequestReceived])
546546

547547
let innerPeekDocumentURI = try XCTUnwrap(innerPeekDocumentsRequestURIs.value?.only)
548-
let innerMacroExpansion = try await project.testClient.send(GetReferenceDocumentRequest(uri: innerPeekDocumentURI))
548+
let innerMacroExpansion = try await project.testClient.send(TextDocumentContentRequest(uri: innerPeekDocumentURI))
549549

550-
XCTAssertEqual(innerMacroExpansion.content, #"(1 + 2, "1 + 2")"#)
550+
XCTAssertEqual(innerMacroExpansion.text, #"(1 + 2, "1 + 2")"#)
551551
}
552552
}

0 commit comments

Comments
 (0)