golang / vscode-go

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

Code fragment breaks coloring of subsequent code #3370

Closed mokiat closed 5 months ago

mokiat commented 5 months 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_. - `go version go1.22.2 linux/amd64` * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - `golang.org/x/tools/gopls v0.15.3` * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - `1.88.1` * Check your installed extensions to get the version of the VS Code Go extension - `v0.41.4` * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. - ``` gopls: /home/momchil/.go/bin/gopls (version: v0.15.3 built with go: go1.22.0) gotests: /home/momchil/.go/bin/gotests (version: v1.6.0 built with go: go1.22.0) gomodifytags: /home/momchil/.go/bin/gomodifytags (version: v1.16.0 built with go: go1.22.0) impl: /home/momchil/.go/bin/impl (version: v1.1.0 built with go: go1.22.0) goplay: /home/momchil/.go/bin/goplay (version: v1.0.0 built with go: go1.22.0) dlv: /home/momchil/.go/bin/dlv (version: v1.22.1 built with go: go1.22.0) staticcheck: /home/momchil/.go/bin/staticcheck (version: v0.4.7 built with go: go1.22.0) ```

Share the Go related settings you have added/edited

    "go.gopath": "/home/momchil/.go",
    "go.lintTool": "staticcheck",
    "go.useLanguageServer": true,
    "go.toolsManagement.autoUpdate": true,
    "[go]": {
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        },
        "editor.snippetSuggestions": "none"
    },
    "gopls": {
        "ui.completion.usePlaceholders": true,
        "ui.diagnostic.analyses": {
            "staticcheck": true
        }
    },

Describe the bug

The color scheme gets messed up after a specific valid Go code sequence.

Steps to reproduce the behavior:

  1. Open a new Go editor tab in VSCode.
  2. Paste the following snippet:
var (
    vertexData = gblob.LittleEndianBlock(make([]byte, len(geometry.vertices)*int(stride)))
)

if 5 > 10 {

}
  1. Observe that the if has a light blue and not the usual purple.

Screenshots or recordings

go-styling-bug

hyangah commented 5 months ago

Please check https://github.com/golang/vscode-go/wiki/faq#syntax-highlighting-doesnt-seem-to-work and if it is about the default syntax highlighting (not the semantic highlighting), please report the issue to the go-syntax project.

mokiat commented 5 months ago

I have checked. Using "gopls": { "ui.semanticTokens": true } the issue cannot be reproduced.

Side note: It still happens when done in a separate tab snippet but I guess the semantic tokens styling is not applied when the code is incomplete or is outside a project and VSCode defaults to go syntax.

I guess I should report this to go-syntax as a follow up.