Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

code coverage: highlighting not working on windows outside GOPATH/src #553

Closed
benmj87 opened this issue Aug 20, 2020 · 11 comments
Closed

code coverage: highlighting not working on windows outside GOPATH/src #553

benmj87 opened this issue Aug 20, 2020 · 11 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@benmj87
Copy link

benmj87 commented Aug 20, 2020

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

  • Run go version to get version of Go
    go version go1.15 windows/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    1.48.0
    db40434f562994116e5b21c24015a2e40b2504e6
    x64
    
  • Check your installed extensions to get the version of the VS Code Go extension
    v0.16.1
  • Run go env to get the go development environment details
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Ben\AppData\Local\go-build
set GOENV=C:\Users\Ben\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Ben\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Ben\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Ben\AppData\Local\Temp\go-build063810058=/tmp/go-build -gno-record-gcc-switches

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

    "go.coverOnSave": true,
    "go.coverOnSingleTest": true,
    "go.coverOnSingleTestFile": true,
    "go.formatTool": "goimports"

Describe the bug

Upon updating vscode to the latest version, code coverage isn't shown in either the gutter or highlighting.

Steps to reproduce the behavior:

  1. With the following two files
package main

import "fmt"

func main() {
  fmt.Println(Sum(1, 2))
}

// Sum adds two numbers
func Sum(a int, b int) int {
  return a + b
}
package main

import "testing"

func TestSum(t *testing.T) {
  if Sum(1, 1) != 2 {
    t.Fail()
  }
}

Screenshots or recordings

image

@liambrown89
Copy link

I'm seeing this problem too

@hyangah
Copy link
Contributor

hyangah commented Aug 20, 2020

@benmj87 @liambrown89 Thanks for the report.
Seems like a bug in the extension that fails to handle the case when we are not in modules mode but not in GOPATH/src.
Can you try to run go mod init <module name> to switch to the module mode?

@pjweinbgo FYI

go list output for mapping between package import path and directory

> go list -f 'ImportPath: {{.ImportPath}} FolderPath: {{.Dir}}' 
ImportPath: _/C_/Users/hakim/work FolderPath: C:\Users\hakim\work

go-code-cover output

mode: set
c:\Users\hakim\work\main.go:5.13,7.2 1 0
c:\Users\hakim\work\main.go:10.28,12.2 1 1

@hyangah
Copy link
Contributor

hyangah commented Aug 20, 2020

The regexp used to parse the coverage file (https://github.com/golang/vscode-go/blob/master/src/goCover.ts#L258) does not work for windows absolute file path that includes drive name like (c:). And we also need to clean up the casing.

@hyangah hyangah added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 20, 2020
@hyangah hyangah added this to the v0.17.0 milestone Aug 20, 2020
@benmj87
Copy link
Author

benmj87 commented Aug 20, 2020

Creating an empty go mod file (go mod init) has got the test case working again 👍

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/250457 mentions this issue: src/goCover.ts: produce data for user to send on coverage failures

@Splizard
Copy link

Splizard commented Sep 2, 2020

I'm having this issue too after updating to go 1.15, code coverage was working last time I used it and now there is no code coverage. I am using Go modules.

@hyangah
Copy link
Contributor

hyangah commented Sep 2, 2020

@Splizard it sounds like you have a different issue if you are using go modules. Can you share your settings and the coverage output file from the test run? (In the Go Tests output channel, the test command with -coverprofile=* flag will appear).

@hyangah hyangah changed the title Code coverage highlighting not working code coverage: highlighting not working on windows outside GOPATH/src Sep 2, 2020
@Splizard
Copy link

Splizard commented Sep 3, 2020

@hyangah I've realised that the code coverage still works in other projects. So it must be something else.

I have only noticed the issue in one package. Here is the coverage file.
coverage.txt

There is a generated .go file in the package.

// Code generated ... DO NOT EDIT

It has a number of line-number overides, I am not sure if this could be cause trouble.

//line types.go2:1

It is a public module but I haven't pushed the changes yet, when I do I'l give this issue a bump and see if it can be reproduced.

@hyangah
Copy link
Contributor

hyangah commented Sep 3, 2020

@Splizard thanks for the update - seems like this is a different issue and worth opening a separate issue. BTW, is it .go2 file? I never tested coverage feature with go2.

@pjweinbgo
Copy link
Contributor

pjweinbgo commented Sep 3, 2020 via email

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/254017 mentions this issue: src/goCover.ts: correct windows absolute filepath handling

@golang golang locked and limited conversation to collaborators Sep 11, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants