[tools] internal/server: store vulncheck prompt preference

3 views
Skip to first unread message

Ethan Lee (Gerrit)

unread,
Nov 19, 2025, 4:47:48 PM (13 days ago) Nov 19
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ethan Lee has uploaded the change for review

Commit message

internal/server: store vulncheck prompt preference

- Store users' vulncheck prompt behavior preference in
os.UserConfigDir()
Change-Id: Ic3f516871f5cb0afe483f111b1339f22e59dc3a8

Change diff

diff --git a/gopls/internal/server/vulncheck_prompt.go b/gopls/internal/server/vulncheck_prompt.go
index 177267c..32a5925 100644
--- a/gopls/internal/server/vulncheck_prompt.go
+++ b/gopls/internal/server/vulncheck_prompt.go
@@ -8,9 +8,11 @@
"context"
"crypto/sha256"
"encoding/hex"
+ "encoding/json"
"errors"
"fmt"
"os"
+ "path/filepath"
"reflect"
"time"

@@ -122,14 +124,28 @@
fileLink := fmt.Sprintf("[%s](%s)", change.URI.Path(), string(change.URI))
govulncheckLink := "[govulncheck](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck)"
message := fmt.Sprintf("Dependencies have changed in %s, would you like to run %s to check for vulnerabilities?", fileLink, govulncheckLink)
- action, err := showMessageRequest(ctx, s.client, protocol.Info, message, "Yes", "No", "Always", "Never")

+ preference, err := getVulncheckPreference()
+ if err != nil {
+ event.Error(ctx, "reading vulncheck preference", err)
+ }
+ if preference == "Always" || preference == "Never" {
+ // TODO: Update this so that we run vulncheck when Always is set.
+ return
+ }
+ action, err := showMessageRequest(ctx, s.client, protocol.Info, message, "Yes", "No", "Always", "Never")
if err != nil {
event.Error(ctx, "showing go.mod changed notification", err)
return
}

- // TODO: Implement persistent storage for "Always" and "Never" preferences.
+ if action == "Always" || action == "Never" {
+ if err := setVulncheckPreference(action); err != nil {
+ event.Error(ctx, "writing vulncheck preference", err)
+ showMessage(ctx, s.client, protocol.Error, fmt.Sprintf("Failed to save vulncheck preference: %v", err))
+ }
+ }
+
// TODO: Implement the logic to run govulncheck when action is "Yes" or "Always".
if action == "No" || action == "Never" || action == "" {
return // Skip the check and don't update the hash.
@@ -142,3 +158,46 @@
}
}()
}
+
+type vulncheckConfig struct {
+ Vulncheck string `json:"vulncheck"`
+}
+
+func getVulncheckPreference() (string, error) {
+ configDir, err := os.UserConfigDir()
+ if err != nil {
+ return "", err
+ }
+ path := filepath.Join(configDir, "gopls", "vulncheck", "settings.json")
+ content, err := os.ReadFile(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return "", nil
+ }
+ return "", err
+ }
+ var config vulncheckConfig
+ if err := json.Unmarshal(content, &config); err != nil {
+ return "", err
+ }
+ return config.Vulncheck, nil
+}
+
+func setVulncheckPreference(preference string) error {
+ configDir, err := os.UserConfigDir()
+ if err != nil {
+ return err
+ }
+ goplsDir := filepath.Join(configDir, "gopls", "vulncheck")
+ if err := os.MkdirAll(goplsDir, 0755); err != nil {
+ return err
+ }
+ path := filepath.Join(goplsDir, "settings.json")
+ fmt.Printf("Writing vulncheck preference to %s\n", path)
+ config := vulncheckConfig{Vulncheck: preference}
+ content, err := json.Marshal(config)
+ if err != nil {
+ return err
+ }
+ return os.WriteFile(path, content, 0644)
+}

Change information

Files:
  • M gopls/internal/server/vulncheck_prompt.go
Change size: M
Delta: 1 file changed, 61 insertions(+), 2 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: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ic3f516871f5cb0afe483f111b1339f22e59dc3a8
Gerrit-Change-Number: 722120
Gerrit-PatchSet: 1
Gerrit-Owner: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
Dec 2, 2025, 2:58:07 PM (13 hours ago) Dec 2
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #3 to this change.
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: newpatchset
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ic3f516871f5cb0afe483f111b1339f22e59dc3a8
Gerrit-Change-Number: 722120
Gerrit-PatchSet: 3
Gerrit-Owner: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
Dec 2, 2025, 2:59:56 PM (13 hours ago) Dec 2
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #4 to this change.
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: newpatchset
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ic3f516871f5cb0afe483f111b1339f22e59dc3a8
Gerrit-Change-Number: 722120
Gerrit-PatchSet: 4
Gerrit-Owner: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Hongxiang Jiang (Gerrit)

unread,
Dec 2, 2025, 11:57:40 PM (4 hours ago) Dec 2
to Ethan Lee, goph...@pubsubhelper.golang.org, Robert Findley, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Hongxiang Jiang voted and added 1 comment

Votes added by Hongxiang Jiang

Hold+1

1 comment

Patchset-level comments
File-level comment, Patchset 4 (Latest):
Hongxiang Jiang . resolved

Let's discuss the first CL and I will review this one afterwards.

Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Holds
    • 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: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic3f516871f5cb0afe483f111b1339f22e59dc3a8
    Gerrit-Change-Number: 722120
    Gerrit-PatchSet: 4
    Gerrit-Owner: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
    Gerrit-CC: Robert Findley <rfin...@google.com>
    Gerrit-Attention: Ethan Lee <etha...@google.com>
    Gerrit-Comment-Date: Wed, 03 Dec 2025 04:57:34 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages