extension/src/language: extend range support to type def
gopls.lsp is triggered programmerly by the language client,
if error encountered, the vscode will pop up notifications
as if the ongoing LSP method is blocking. This CL also
suppress the error encountered gopls.lsp command.
diff --git a/extension/src/language/goLanguageServer.ts b/extension/src/language/goLanguageServer.ts
index 735f751..6d08f83 100644
--- a/extension/src/language/goLanguageServer.ts
+++ b/extension/src/language/goLanguageServer.ts
@@ -477,6 +477,31 @@
}
},
middleware: {
+ provideTypeDefinition: async (doc, pos, token, next) => {
+ if (!goCtx.languageClient) {
+ return await next(doc, pos, token);
+ }
+
+ const editor = vscode.window.activeTextEditor;
+ if (!editor || doc !== editor.document) {
+ return await next(doc, pos, token);
+ }
+
+ const selection = editor?.selection;
+ if (selection.isEmpty || !selection.contains(pos)) {
+ return await next(doc, pos, token);
+ }
+
+ // Attaching selected range to gopls type def request.
+ const param = goCtx.languageClient.code2ProtocolConverter.asTextDocumentPositionParams(doc, pos);
+ (param as any).range = goCtx.languageClient.code2ProtocolConverter.asRange(selection);
+
+ const result: any = await vscode.commands.executeCommand('gopls.lsp', {
+ method: 'textDocument/typeDefinition',
+ param: param
+ });
+ return goCtx.languageClient.protocol2CodeConverter.asDefinitionResult(result);
+ },
provideHover: async (doc, pos, token, next) => {
// gopls.lsp is a command that acts as a dispatcher, allowing
// the client to trigger any LSP RPC via "workspace/executeCommand"
@@ -492,7 +517,7 @@
}
const selection = editor?.selection;
- if (!selection || !selection.contains(pos)) {
+ if (selection.isEmpty || !selection.contains(pos)) {
return await next(doc, pos, token);
}
@@ -597,8 +622,9 @@
return res;
} catch (e) {
- // Suppress error messages for frequently triggered commands.
- if (command === 'gopls.package_symbols') {
+ // Suppress error messages for frequently triggered
+ // or programmerly triggered commads.
+ if (command === 'gopls.package_symbols' || command === 'gopls.lsp') {
return null;
}
// TODO: how to print ${e} reliably???
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
// or programmerly triggered commads."programmatically" ? As in it's not triggered directly by the user, it's triggered internally by the extension, if that's what you mean?
| 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. |
"programmatically" ? As in it's not triggered directly by the user, it's triggered internally by the extension, if that's what you mean?
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. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Hold | +1 |
Waiting for gopls CL to merge first.
| 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 |
| Hold | +0 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: extension/src/language/goLanguageServer.ts
Insertions: 1, Deletions: 1.
@@ -623,7 +623,7 @@
return res;
} catch (e) {
// Suppress error messages for frequently triggered
- // or programmerly triggered commads.
+ // or programmatically triggered commads.
if (command === 'gopls.package_symbols' || command === 'gopls.lsp') {
return null;
}
```
extension/src/language: extend range support to type def
gopls.lsp is triggered programmatically by the language client,
if error encountered, the vscode will pop up notifications
as if the ongoing LSP method is blocking. This CL also
suppress the error encountered gopls.lsp command.
Gopls CL 728600
For golang/go#76723
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |