golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.89k stars 752 forks source link

Bouncing "run test | debug Test" during typing #2435

Open ch1ll0ut1 opened 2 years ago

ch1ll0ut1 commented 2 years ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go1.18.4 darwin/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - command not found: gopls * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.70.2 e4503b30fc78200f846c62cf8091b76ff5547662 x64 * Check your installed extensions to get the version of the VS Code Go extension - v0.35.2 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. - GOBIN: undefined toolsGopath: gopath: /Users/.../go GOROOT: /usr/local/go PATH: /usr/local/go/bin:/usr/bin:/bin:/usr/sbin:/sbin PATH (vscode launched with): /usr/bin:/bin:/usr/sbin:/sbin go: /usr/local/go/bin/go: go version go1.18.4 darwin/amd64 gotests: /Users/.../go/bin/gotests (version: v1.6.0 built with go: go1.18.4) gomodifytags: /Users/.../go/bin/gomodifytags (version: v1.16.0 built with go: go1.18.4) impl: /Users/.../go/bin/impl (version: v1.1.0 built with go: go1.18.4) goplay: /Users/.../go/bin/goplay (version: v1.0.0 built with go: go1.18.4) dlv: /Users/.../go/bin/dlv (version: v1.9.0 built with go: go1.18.4) staticcheck: /Users/.../go/bin/staticcheck (version: v0.3.2 built with go: go1.18.4) gopls: /Users/.../go/bin/gopls (version: v0.9.4 built with go: go1.18.4) go env Workspace Folder (project): /Users/.../Projects/project

Share the Go related settings you have added/edited

// Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.
"go.addTags": {
    "tags": "json",
    "options": "json=omitempty",
    "promptForTags": false,
    "transform": "snakecase",
    "template": ""
},

// Alternate tools or alternate paths for the same tools used by the Go extension. Provide either absolute path or the name of the binary in GOPATH/bin, GOROOT/bin or PATH. Useful when you want to use wrapper script for the Go tools.
"go.alternateTools": {},

// Include unimported packages in auto-complete suggestions. Not applicable when using the language server.
"go.autocompleteUnimportedPackages": false,

// Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if `gopls.build.buildFlags` is not specified.
"go.buildFlags": [],

// Compiles code on file save using 'go build' or 'go test -c'. Options are 'workspace', 'package', or 'off'.  Not applicable when using the language server's diagnostics. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
"go.buildOnSave": "package",

// The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set. This is propagated to the language server if `gopls.build.buildFlags` is not specified.
"go.buildTags": "",

// This option lets you choose the way to display code coverage. Choose either to highlight the complete line or to show a decorator in the gutter. You can customize the colors and borders for the former and the style for the latter.
"go.coverageDecorator": {
    "type": "highlight",
    "coveredHighlightColor": "rgba(64,128,128,0.5)",
    "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
    "coveredBorderColor": "rgba(64,128,128,0.5)",
    "uncoveredBorderColor": "rgba(128,64,64,0.25)",
    "coveredGutterStyle": "blockblue",
    "uncoveredGutterStyle": "slashyellow"
},

// Use these options to control whether only covered or only uncovered code or both should be highlighted after running test coverage
"go.coverageOptions": "showBothCoveredAndUncoveredCode",

// When generating code coverage, the value for -covermode. 'default' is the default value chosen by the 'go test' command.
"go.coverMode": "default",

// If true, runs 'go test -coverprofile' on save and shows test coverage.
"go.coverOnSave": false,

// If true, shows test coverage when Go: Test Function at cursor command is run.
"go.coverOnSingleTest": false,

// If true, shows test coverage when Go: Test Single File command is run.
"go.coverOnSingleTestFile": false,

// If true, shows test coverage when Go: Test Package command is run.
"go.coverOnTestPackage": true,

// When generating code coverage, should counts be shown as --374--
"go.coverShowCounts": false,

// Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.
"go.delveConfig": {},

// If true, tests will not run concurrently. When a new test run is started, the previous will be cancelled.
"go.disableConcurrentTests": false,

// Pick 'godoc' or 'gogetdoc' to get documentation. Not applicable when using the language server.
"go.docsTool": "godoc",

// Experimental Feature: Enable/Disable entries from the context menu in the editor.
"go.editorContextMenuCommands": {
    "toggleTestFile": true,
    "addTags": true,
    "removeTags": false,
    "fillStruct": false,
    "testAtCursor": true,
    "testFile": false,
    "testPackage": false,
    "generateTestForFunction": true,
    "generateTestForFile": false,
    "generateTestForPackage": false,
    "addImport": true,
    "testCoverage": true,
    "playground": true,
    "debugTestAtCursor": true,
    "benchmarkAtCursor": false
},

// Feature level setting to enable/disable code lens for references and run/debug tests
"go.enableCodeLens": {
    "references": false,
    "runtest": true
},

// Flags to pass to format tool (e.g. ["-s"]). Not applicable when using the language server.
"go.formatFlags": [],

// When the language server is enabled and one of default/gofmt/goimports/gofumpt is chosen, the language server will handle formatting. Otherwise, the extension will use the specified tool for formatting.
//  - default: If the language server is enabled, format via the language server, which already supports gofmt, goimports, goreturns, and gofumpt. Otherwise, goimports.
//  - gofmt: Formats the file according to the standard Go style. (not applicable when the language server is enabled)
//  - goimports: Organizes imports and formats the file with gofmt. (not applicable when the language server is enabled)
//  - goformat: Configurable gofmt, see https://github.com/mbenkmann/goformat.
//  - gofumpt: Stricter version of gofmt, see https://github.com/mvdan/gofumpt. (not applicable when the language server is enabled)
//  - undefined: Applies gofumpt formatting and organizes imports.
"go.formatTool": "default",

// Additional command line flags to pass to `gotests` for generating tests.
"go.generateTestsFlags": [],

// Enable gocode's autobuild feature. Not applicable when using the language server.
"go.gocodeAutoBuild": false,

// Additional flags to pass to gocode. Not applicable when using the language server.
"go.gocodeFlags": [
    "-builtin",
    "-ignore-case",
    "-unimported-packages"
],

// Used to determine the Go package lookup rules for completions by gocode. Only applies when using nsf/gocode. Latest versions of the Go extension uses mdempsky/gocode by default. Not applicable when using the language server.
"go.gocodePackageLookupMode": "go",

// Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true.
"go.gopath": null,

// Specifies the GOROOT to use when no environment variable is set.
"go.goroot": null,

// Folder names (not paths) to ignore while using Go to Symbol in Workspace feature. Not applicable when using the language server.
"go.gotoSymbol.ignoreFolders": [],

// If false, the standard library located at $GOROOT will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server.
"go.gotoSymbol.includeGoroot": false,

// If false, the import statements will be excluded while using the Go to Symbol in File feature. Not applicable when using the language server.
"go.gotoSymbol.includeImports": false,

// Infer GOPATH from the workspace root. This is ignored when using Go Modules.
"go.inferGopath": false,

// Enable/disable inlay hints for variable types in assign statements:
// ```go
//  i/* int*/, j/* int*/ := 0, len(r)-1
// ```
"go.inlayHints.assignVariableTypes": false,

// Enable/disable inlay hints for composite literal field names:
// ```go
//  {/*in: */"Hello, world", /*want: */"dlrow ,olleH"}
// ```
"go.inlayHints.compositeLiteralFields": false,

// Enable/disable inlay hints for composite literal types:
// ```go
//  for _, c := range []struct {
//      in, want string
//  }{
//      /*struct{ in string; want string }*/{"Hello, world", "dlrow ,olleH"},
//  }
// ```
"go.inlayHints.compositeLiteralTypes": false,

// Enable/disable inlay hints for constant values:
// ```go
//  const (
//      KindNone   Kind = iota/* = 0*/
//      KindPrint/*  = 1*/
//      KindPrintf/* = 2*/
//      KindErrorf/* = 3*/
//  )
// ```
"go.inlayHints.constantValues": false,

// Enable/disable inlay hints for implicit type parameters on generic functions:
// ```go
//  myFoo/*[int, string]*/(1, "hello")
// ```
"go.inlayHints.functionTypeParameters": false,

// Enable/disable inlay hints for parameter names:
// ```go
//  parseInt(/* str: */ "123", /* radix: */ 8)
// ```
"go.inlayHints.parameterNames": false,

// Enable/disable inlay hints for variable types in range statements:
// ```go
//  for k/* int*/, v/* string*/ := range []string{} {
//      fmt.Println(k, v)
//  }
// ```
"go.inlayHints.rangeVariableTypes": false,

// If true, then `-i` flag will be passed to `go build` everytime the code is compiled. Since Go 1.10, setting this may be unnecessary unless you are in GOPATH mode and do not use the language server.
"go.installDependenciesWhenBuilding": false,

// Temporary flag to enable/disable diagnostics from the language server. This setting will be deprecated soon. Please see and response to [Issue 50](https://github.com/golang/vscode-go/issues/50).
"go.languageServerExperimentalFeatures": {
    "diagnostics": true
},

// Flags like -rpc.trace and -logfile to be used while running the language server.
"go.languageServerFlags": [],

// Flags to pass to Lint tool (e.g. ["-min_confidence=.8"])
"go.lintFlags": [],

// Lints code on file save using the configured Lint tool. Options are 'file', 'package', 'workspace' or 'off'.
//  - file: lint the current file on file saving
//  - package: lint the current package on file saving
//  - workspace: lint all the packages in the current workspace root folder on file saving
//  - off: do not run lint automatically
"go.lintOnSave": "package",

// Specifies Lint tool name.
"go.lintTool": "staticcheck",

// Use gotype on the file currently being edited and report any semantic or syntactic errors found after configured delay. Not applicable when using the language server.
"go.liveErrors": {
    "enabled": false,
    "delay": 500
},

// The logging level the extension logs at, defaults to 'error'
"go.logging.level": "error",

// The flags configured here will be passed through to command `goplay`
"go.playground": {
    "openbrowser": true,
    "share": true,
    "run": true
},

// Tags and options configured here will be used by the Remove Tags command to remove tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, all tags and options will be removed.
"go.removeTags": {
    "tags": "",
    "options": "",
    "promptForTags": false
},

// Prompt for surveys, including the gopls survey and the Go developer survey.
"go.survey.prompt": true,

// Apply the Go & PATH environment variables used by the extension to all integrated terminals.
"go.terminal.activateEnvironment": true,

// Absolute path to a file containing environment variables definitions. File contents should be of the form key=value.
"go.testEnvFile": null,

// Environment variables that will be passed to the process that runs the Go tests
"go.testEnvVars": {},

// Run benchmarks when running all tests in a file or folder.
"go.testExplorer.alwaysRunBenchmarks": false,

// Concatenate all test log messages for a given location into a single message.
"go.testExplorer.concatenateMessages": true,

// Enable the Go test explorer
"go.testExplorer.enable": true,

// Present packages in the test explorer flat or nested.
"go.testExplorer.packageDisplayMode": "flat",

// Set the source location of dynamically discovered subtests to the location of the containing function. As a result, dynamically discovered subtests will be added to the gutter test widget of the containing function.
"go.testExplorer.showDynamicSubtestsInEditor": false,

// Open the test output terminal when a test run is started.
"go.testExplorer.showOutput": true,

// Flags to pass to `go test`. If null, then buildFlags will be used. This is not propagated to the language server.
"go.testFlags": null,

// Run 'go test' on save for current package. It is not advised to set this to `true` when you have Auto Save enabled.
"go.testOnSave": false,

// The Go build tags to use for when running tests. If null, then buildTags will be used.
"go.testTags": null,

// Specifies the timeout for go test in ParseDuration format.
"go.testTimeout": "30s",

// Environment variables that will be passed to the tools that run the Go tools (e.g. CGO_CFLAGS) and debuggee process launched by Delve. Format as string key:value pairs. When debugging, merged with `envFile` and `env` values with precedence `env` > `envFile` > `go.toolsEnvVars`.
"go.toolsEnvVars": {},

// Location to install the Go tools that the extension depends on if you don't want them in your GOPATH.
"go.toolsGopath": null,

// Automatically update the tools used by the extension, without prompting the user.
"go.toolsManagement.autoUpdate": false,

// Specify whether to prompt about new versions of Go and the Go tools (currently, only `gopls`) the extension depends on
//  - proxy: keeps notified of new releases by checking the Go module proxy (GOPROXY)
//  - local: checks only the minimum tools versions required by the extension
//  - off: completely disables version check (not recommended)
"go.toolsManagement.checkForUpdates": "proxy",

// The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.
"go.toolsManagement.go": "",

// Trace the communication between VS Code and the Go language server.
"go.trace.server": "off",

// Complete functions with their parameter signature, including the variable type. Not propagated to the language server.
"go.useCodeSnippetsOnFunctionSuggest": false,

// Complete functions with their parameter signature, excluding the variable types. Use `gopls.usePlaceholders` when using the language server.
"go.useCodeSnippetsOnFunctionSuggestWithoutType": false,

// Use `go.toolsManagement.checkForUpdates` instead.
// When enabled, the extension automatically checks the Go proxy if there are updates available for Go and the Go tools (at present, only gopls) it depends on and prompts the user accordingly
"go.useGoProxyToCheckForToolUpdates": true,

// Use the Go language server "gopls" from Google for powering language features like code navigation, completion, refactoring, formatting & diagnostics.
"go.useLanguageServer": true,

// Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"])
"go.vetFlags": [],

// Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics. See 'go.languageServerExperimentalFeatures.diagnostics' setting.
//  - package: vet the current package on file saving
//  - workspace: vet all the packages in the current workspace root folder on file saving
//  - off: do not run vet automatically
"go.vetOnSave": "package",

// Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.
"gopls": {},

Describe the bug

When editing a test file, 2 buttons are displayed above a test "run test | debug test".

These buttons will disappear and re-appear with every key stroke.

It might not technically be a bug but for DX it is because on every key stroke all the lines after the buttons will move up and down. It's very distracting.

Steps to reproduce the behavior:

  1. Go to any go file with "*_test.go" filename
  2. Write a test func with "func Test*"
  3. Look for "run test | debug test"4.
  4. Write code in the test case (make sure to write something that doesn't compile during you type, like writing a variable assignment or a if condition)

Screenshots or recordings

https://user-images.githubusercontent.com/6835266/188111680-6e6b6133-069c-45b2-a75f-04cede2dd851.mov

ch1ll0ut1 commented 2 years ago

Workaround solution: Disable feature by unchecking "Go: Enable Code Lens" in VSCode settings. This still leaves a Run test button on the side and only removes the hovering buttons above the test function.

adonovan commented 2 years ago

We've seen a similar problem related to parser error recovery, but that doesn't trigger on every keystroke. Can you confirm that this does indeed occur even when you type something that doesn't change the syntax (e.g. within a comment)? thanks.

ch1ll0ut1 commented 2 years ago

We've seen a similar problem related to parser error recovery, but that doesn't trigger on every keystroke. Can you confirm that this does indeed occur even when you type something that doesn't change the syntax (e.g. within a comment)? thanks.

Oh yes you are right, not every keystroke. I think it might be only keystrokes that change the code compile success state. So like invalid syntax to valid syntax and the other way around.

I've also noticed that if a task is running with debugging, autocomplete and definition infos are missing randomly. As well as when there is a syntax error higher up in the code. All code intelligence infos are missing in code below that syntax error.

Its quite frustrating because it sometimes gives the feeling of its loading but actually the info never comes. (automcomplete entries & definition tooltip). Typescript doesn't seem to have any of this issues except that infos can take longer to load in bigger projects. But my current Go project is very small with around 10 files.