[vscode-go] extension/src/language: attach selected range to hover request

4 views
Skip to first unread message

Hongxiang Jiang (Gerrit)

unread,
Sep 23, 2025, 5:35:54 PM (8 days ago) Sep 23
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Hongxiang Jiang has uploaded the change for review

Commit message

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
Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975

Change diff

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':

Change information

Files:
  • M extension/src/language/goLanguageServer.ts
Change size: S
Delta: 1 file changed, 19 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 1
Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Sep 23, 2025, 5:38:57 PM (8 days ago) Sep 23
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Hongxiang Jiang voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 1
Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Comment-Date: Tue, 23 Sep 2025 21:38:54 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Sep 24, 2025, 4:35:17 PM (7 days ago) Sep 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Madeline Kalil

Hongxiang Jiang uploaded new patchset

Hongxiang Jiang uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
  • TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Madeline Kalil
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 2
Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Madeline Kalil <mka...@google.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Sep 24, 2025, 4:35:53 PM (7 days ago) Sep 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Madeline Kalil

Hongxiang Jiang uploaded new patchset

Hongxiang Jiang uploaded patch set #3 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Madeline Kalil
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 3
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Sep 24, 2025, 4:54:18 PM (7 days ago) Sep 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Madeline Kalil

Hongxiang Jiang uploaded new patchset

Hongxiang Jiang uploaded patch set #4 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Madeline Kalil
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 4
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Sep 24, 2025, 4:56:02 PM (7 days ago) Sep 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Madeline Kalil

Hongxiang Jiang uploaded new patchset

Hongxiang Jiang uploaded patch set #5 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Madeline Kalil
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 5
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Sep 24, 2025, 4:56:22 PM (7 days ago) Sep 24
to goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, Madeline Kalil, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Madeline Kalil

Hongxiang Jiang voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Madeline Kalil
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
Gerrit-Change-Number: 706336
Gerrit-PatchSet: 5
Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Madeline Kalil <mka...@google.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
Gerrit-Comment-Date: Wed, 24 Sep 2025 20:56:19 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Madeline Kalil (Gerrit)

unread,
Sep 29, 2025, 11:28:00 AM (3 days ago) Sep 29
to Hongxiang Jiang, goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Alan Donovan and Hongxiang Jiang

Madeline Kalil added 2 comments

File extension/src/language/goLanguageServer.ts
Line 503, Patchset 5 (Latest): (param as any).range = goCtx.languageClient.code2ProtocolConverter.asRange(selection);
Madeline Kalil . unresolved

Can't find references to this helper for some reason, what does it do when there's an error converting to a range?

Line 505, Patchset 5 (Latest): const restult: Hover = await vscode.commands.executeCommand('gopls.lsp', {
Madeline Kalil . unresolved

result

Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
  • Hongxiang Jiang
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: vscode-go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
    Gerrit-Change-Number: 706336
    Gerrit-PatchSet: 5
    Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
    Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Hongxiang Jiang <hxj...@golang.org>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Comment-Date: Mon, 29 Sep 2025 15:27:56 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Hongxiang Jiang (Gerrit)

    unread,
    Oct 1, 2025, 2:43:04 PM (14 hours ago) Oct 1
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Alan Donovan and Hongxiang Jiang

    Hongxiang Jiang uploaded new patchset

    Hongxiang Jiang uploaded patch set #6 to this change.
    Following approvals got outdated and were removed:
    • TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI

    Related details

    Attention is currently required from:
    • Alan Donovan
    • Hongxiang Jiang
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: vscode-go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
      Gerrit-Change-Number: 706336
      Gerrit-PatchSet: 6
      unsatisfied_requirement
      open
      diffy

      Hongxiang Jiang (Gerrit)

      unread,
      Oct 1, 2025, 3:00:17 PM (13 hours ago) Oct 1
      to goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, Madeline Kalil, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Alan Donovan and Madeline Kalil

      Hongxiang Jiang voted and added 2 comments

      Votes added by Hongxiang Jiang

      Auto-Submit+1
      Commit-Queue+1

      2 comments

      File extension/src/language/goLanguageServer.ts
      Line 503, Patchset 5: (param as any).range = goCtx.languageClient.code2ProtocolConverter.asRange(selection);
      Madeline Kalil . resolved

      Can't find references to this helper for some reason, what does it do when there's an error converting to a range?

      Hongxiang Jiang

      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.

      Line 505, Patchset 5: const restult: Hover = await vscode.commands.executeCommand('gopls.lsp', {
      Madeline Kalil . resolved

      result

      Hongxiang Jiang

      Done

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Alan Donovan
      • Madeline Kalil
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: vscode-go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
        Gerrit-Change-Number: 706336
        Gerrit-PatchSet: 6
        Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
        Gerrit-Reviewer: Alan Donovan <adon...@google.com>
        Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
        Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Madeline Kalil <mka...@google.com>
        Gerrit-Attention: Alan Donovan <adon...@google.com>
        Gerrit-Comment-Date: Wed, 01 Oct 2025 19:00:13 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Comment-In-Reply-To: Madeline Kalil <mka...@google.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Madeline Kalil (Gerrit)

        unread,
        Oct 1, 2025, 4:18:33 PM (12 hours ago) Oct 1
        to Hongxiang Jiang, goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Alan Donovan and Hongxiang Jiang

        Madeline Kalil voted Code-Review+2

        Code-Review+2
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Alan Donovan
        • Hongxiang Jiang
        Submit Requirements:
        • requirement satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement satisfiedReview-Enforcement
        • requirement satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: vscode-go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
        Gerrit-Change-Number: 706336
        Gerrit-PatchSet: 6
        Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
        Gerrit-Reviewer: Alan Donovan <adon...@google.com>
        Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
        Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Hongxiang Jiang <hxj...@golang.org>
        Gerrit-Attention: Alan Donovan <adon...@google.com>
        Gerrit-Comment-Date: Wed, 01 Oct 2025 20:18:29 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Gopher Robot (Gerrit)

        unread,
        Oct 1, 2025, 4:19:36 PM (12 hours ago) Oct 1
        to Hongxiang Jiang, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Madeline Kalil, Go LUCI, Alan Donovan, golang-co...@googlegroups.com

        Gopher Robot submitted the change

        Change information

        Commit message:
        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
        Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
        Auto-Submit: Hongxiang Jiang <hxj...@golang.org>
        Reviewed-by: Madeline Kalil <mka...@google.com>
        Files:
        • M extension/src/language/goLanguageServer.ts
        Change size: S
        Delta: 1 file changed, 35 insertions(+), 0 deletions(-)
        Branch: refs/heads/master
        Submit Requirements:
        • requirement satisfiedCode-Review: +2 by Madeline Kalil
        • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
        Open in Gerrit
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: merged
        Gerrit-Project: vscode-go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie65a5d62d220882865a22f3749ed9330b6234975
        Gerrit-Change-Number: 706336
        Gerrit-PatchSet: 7
        Gerrit-Owner: Hongxiang Jiang <hxj...@golang.org>
        Gerrit-Reviewer: Alan Donovan <adon...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        open
        diffy
        satisfied_requirement
        Reply all
        Reply to author
        Forward
        0 new messages