extension/src/language: attach selected range to hover request
The middleware API allow the extension developer to modify the
input parameter of the call back function "next" but does not
allow the extension developer to introduce new arguments.
The vscode-languageclient still responsible for the putting up
the final parameter and send to gopls.
Based on the proposal from microsoft/language-server-protocol#377,
the final state is introducing a "range" field in PositionParams.
I think it make more sense to call a separate gopls command
"gopls.hover" (CL 706335) instead of forcely embeding a "range"
field to the "position" field.
The vscode-go extension only send the selected range if the range
and the original position come from the same text document.
For golang/go#69058
diff --git a/extension/src/language/goLanguageServer.ts b/extension/src/language/goLanguageServer.ts
index 95d59fa..348e942 100644
--- a/extension/src/language/goLanguageServer.ts
+++ b/extension/src/language/goLanguageServer.ts
@@ -33,6 +33,7 @@
ProvideCodeLensesSignature,
ProvideCompletionItemsSignature,
ProvideDocumentFormattingEditsSignature,
+ Hover,
ResponseError,
RevealOutputChannelOn
} from 'vscode-languageclient';
@@ -473,6 +474,24 @@
}
},
middleware: {
+ provideHover: async (doc, pos, token, next) => {
+ const useCommand = goCtx.serverInfo?.Commands?.includes('gopls.hover');
+ const editor = vscode.window.activeTextEditor;
+ if (useCommand && goCtx.languageClient && editor && doc === editor.document) {
+ const selection = editor.selection;
+ const param = goCtx.languageClient.code2ProtocolConverter.asTextDocumentPositionParams(
+ doc,
+ pos
+ );
+ // Attaching selected range to gopls hover request.
+ // See golang/go#69058.
+ (param as any).range = goCtx.languageClient.code2ProtocolConverter.asRange(selection);
+ const restult: Hover = await vscode.commands.executeCommand('gopls.hover', param);
+ return goCtx.languageClient.protocol2CodeConverter.asHover(restult);
+ } else {
+ return await next(doc, pos, token);
+ }
+ },
handleWorkDoneProgress: async (token, params, next) => {
switch (params.kind) {
case 'begin':
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Commit-Queue | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
(param as any).range = goCtx.languageClient.code2ProtocolConverter.asRange(selection);
Can't find references to this helper for some reason, what does it do when there's an error converting to a range?
const restult: Hover = await vscode.commands.executeCommand('gopls.lsp', {
result
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Auto-Submit | +1 |
Commit-Queue | +1 |
(param as any).range = goCtx.languageClient.code2ProtocolConverter.asRange(selection);
Can't find references to this helper for some reason, what does it do when there's an error converting to a range?
This function is a converter that convert a vscode type to a LSP type.
TLDR: it will not fail.
I checked the [source](https://github.com/microsoft/vscode-languageserver-node/blob/3412a17149850f445bf35b4ad71148cfe5f8411e/client/src/common/protocolConverter.ts#L401)
I think the function is very simple, it simply read the filed and return a different type.
It have multiple signature, but the signature we call is `asRange(value: code.Range): proto.Range`. It means, if you provide a Range, I will give you a proto.range. So it will never fail because what we passed into the function is a valid range.
const restult: Hover = await vscode.commands.executeCommand('gopls.lsp', {
Hongxiang Jiangresult
Done
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
extension/src/language: attach selected range to hover request
The middleware API allow the extension developer to modify the
input parameter of the call back function "next" but does not
allow the extension developer to introduce new arguments.
The vscode-languageclient still responsible for the putting up
the final parameter and send to gopls.
Based on the proposal from microsoft/language-server-protocol#377,
the final state is introducing a "range" field in PositionParams.
I think it make more sense to call a separate gopls command
"gopls.lsp" with method "hover" (CL 706335) instead of forcely
embeding a "range" field to the "position" field.
The vscode-go extension only send the selected range if the range
and the original position come from the same text document.
For golang/go#69058
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |