golang / vscode-go

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

`go.coverShowCounts: true` not works with `go.coverageDecorator.type: "gutter"` #3588

Open d-enk opened 2 weeks ago

d-enk commented 2 weeks ago
"go.coverShowCounts": true,

image

if change type without resetting coverage

"go.coverageDecorator": {
  "type": "gutter",
},

works like expected image

but if rerun test - counter disappears image

ansaba commented 2 weeks ago

cc: @h9jiang

h9jiang commented 1 week ago

I'm able to reproduce the behavior you saw.

First, run test using configuration below

"go.coverageDecorator": {
    "type":"highlight",
}

The --1-- showed up in VSCode. If I change the type from highlight to gutter, rerun the test, the --1-- disappear. I can find the source code which controls this behavior.

Based on the comment // irrelevant for "gutter": If the type is "highlight", the elaborate function returns both the highlight of the code as well as the count number before this snippet of code. If the type of the decorator is "gutter", neither will be rendered.

image

See goCover.ts

I'm still new to this, but I think the purpose of the decorator.Type == "gutter" means we should only render things in the gutter without introducing any text or decorations in the source code itself. (Keeping the code clean and untouched).

But the "go.coverShowCounts": true, is a configuration in parallel with "go.coverageDecorator". I did not expect to see them impacting each other. Is there any place we can render a number in gutter. (my guess is no) 🤔

@pjweinb @hyangah for suggestions.

If we ever decided to render the count in "gutter" type, I'm afraid we will need to have some background highlight for this. And this background highlight should not inherit from the go.coverageDecorator.coveredBorderColor go.coverageDecorator.uncoveredBorderColor to avoid confusion.

pjweinb commented 1 week ago

h9jiang is right. Here's my explanation: The leftover --1-- that d-enk sees is a bug in the implementation. When the settings change, the code tries to remove all the coverage information, but it's failing to remove the counts, which are inlay hints.

I think interpolating counts in gutter mode would be a new feature.

firelizzard18 commented 1 week ago

Once the next preview version of gopls (0.17) and vscode-go (0.43) are released, you could use Go Companion's test coverage support. Coverage decorations are handled via VSCode's native testing and test coverage support which seems pretty solid.