ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
460 stars 88 forks source link

remotePathResolve not working on VS Code Windows with a coverage.xml file using Unix paths #400

Open denisrossetre opened 1 year ago

denisrossetre commented 1 year ago

Describe the bug

remotePathResolve does not seem to work when having a coverage.xml file with Unix paths and the VS Code Coverage Gutters extension running on Windows.

To Reproduce

  1. Run the tests of a Python project in a Docker container using Linux, which produces a coverage.xml file. The coverage file has a line <sources><source>/opt/myproject</source></sources> and the rest of the paths are relative (in the <package name="src.module"> XML entities).
  2. Have a line with "coverage-gutters.remotePathResolve": ["/opt/local", "c:/Users/myusername/projects/myprojectname"], in the VS Code settings.json file.
  3. Open any source code file which has coverage.
  4. Click on the coverage bottom bar button to refresh the coverage, the result is an empty circle with "No Coverage".

Note that the extension works when replacing <sources><source>/opt/myproject</source></sources> by <sources><source>.</source></sources> and removing the remotePathResolve setting.

Expected behaviour

Coverage shows.

Screenshots

No screenshots because of nature of the code. I could provide a reproducible example if needed.

Desktop (please complete the following information):

Additional context

I'd be very happy to get extra logs about how the coverage.xml path is interpreted and when/if it is translated by remotePathResolve. Right now, I'm debugging in the dark.

ryanluker commented 1 year ago

@denisrossetre Thanks for the ticket! Are you able to grab more logs from the extension output log area? Screenshot from 2023-04-08 14-43-12

In terms of extra logging, check out this area, and you could maybe remove the .size to print the whole cache and that would assist us in figuring out what is inside (this should really be an extension setting to enable "verbose" logging mode but sadly haven't got to that yet 😓). https://github.com/ryanluker/vscode-coverage-gutters/blob/c15ac1aab3e43d882a2ab283a9b6a6ec501214d8/src/coverage-system/coverageservice.ts#L101-L105

denisrossetre commented 1 year ago

Actually, I solved the problem! The thing is that the path parsing will be done on a Unix path in a Windows system.

By changing the value "coverage-gutters.remotePathResolve": ["/opt/local", "c:/Users/myusername/projects/myprojectname"] to "coverage-gutters.remotePathResolve": ["\\opt\\local", "."] the problem disappeared (the second value "." does not matter so much, but I prefer relative paths for the local dev system as they are more stable).

To close this issue, I'd like to write a bit of documentation for the remotePathResolve setting. Would you accept a PR, and if so, where should I put the documentation?

ryanluker commented 1 year ago

Actually, I solved the problem! The thing is that the path parsing will be done on a Unix path in a Windows system.

By changing the value "coverage-gutters.remotePathResolve": ["/opt/local", "c:/Users/myusername/projects/myprojectname"] to "coverage-gutters.remotePathResolve": ["\\opt\\local", "."] the problem disappeared (the second value "." does not matter so much, but I prefer relative paths for the local dev system as they are more stable.

To close this issue, I'd like to write a bit of documentation for the remotePathResolve setting. Would you accept a PR, and if so, where should I put the documentation?

I am glad you got it figured out 👍🏻 ! More documentation is always welcome, so PR will definitely be accepted, thanks.

I think the tips and tricks section would be a good fit? It gets great SEO from being on the front page + in the marketplace. https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters https://github.com/ryanluker/vscode-coverage-gutters#tips-and-tricks

ralittl commented 11 months ago

@denisrossetre I'm encountering the same issue that you were -- I'm using Windows 10, and I have a docker container running Linux, but coverage gutters isn't showing the code coverage in VSC.

I tried using your fix, here is my settings.json

"coverage-gutters.coverageFileNames": [
        "coverage.xml",
        "lcov.info",
        "cov.xml",
        "jacoco.xml"
    ],
    "coverage-gutters.remotePathResolve": [

        [
            "\\home\\dev\\Mxxxx",
            "."
        ]
    ]

The /home/dev/M... path is what I'm using in the container.

In the CG log I see this:

[1698181260483][coverageservice]: c:\Users\Exxxxxxxx\gitlab\Mxxxx\coverage.xml
[1698181260483][coverageservice]: Loaded 1 data file(s)
[1698181260488][coverageservice]: Caching 6 coverage(s)
[1698181260488][coverageservice]: READY
[1698181260488][coverageservice]: RENDERING
[1698181260488][coverageservice]: READY

so I know that it's picking up my coverage file, but there's just still no visual indication on the file, and the bottom bar still shows "No coverage".

Did you end up having to do anything else other than changing this setting, to fix the issue? I'm running Coverage Gutters v2.11.0

ryanluker commented 11 months ago

@denisrossetre I'm encountering the same issue that you were -- I'm using Windows 10, and I have a docker container running Linux, but coverage gutters isn't showing the code coverage in VSC.

I tried using your fix, here is my settings.json

"coverage-gutters.coverageFileNames": [
        "coverage.xml",
        "lcov.info",
        "cov.xml",
        "jacoco.xml"
    ],
    "coverage-gutters.remotePathResolve": [

        [
            "\\home\\dev\\Mxxxx",
            "."
        ]
    ]

The /home/dev/M... path is what I'm using in the container.

In the CG log I see this:

[1698181260483][coverageservice]: c:\Users\Exxxxxxxx\gitlab\Mxxxx\coverage.xml
[1698181260483][coverageservice]: Loaded 1 data file(s)
[1698181260488][coverageservice]: Caching 6 coverage(s)
[1698181260488][coverageservice]: READY
[1698181260488][coverageservice]: RENDERING
[1698181260488][coverageservice]: READY

so I know that it's picking up my coverage file, but there's just still no visual indication on the file, and the bottom bar still shows "No coverage".

Did you end up having to do anything else other than changing this setting, to fix the issue? I'm running Coverage Gutters v2.11.0

@ralittl Hmm I think you might want to try one level of array instead? "coverage-gutters.remotePathResolve": ["\\home\\dev\\Mxxxx", "."]

Also, once you get the system working, try out the watch button in the bottom status bar and you should get an output similar to the following:

[1699830894119][coverageservice]: INITIALIZING
[1699830925569][coverageservice]: LOADING
[1699830925644][coverageservice]: Loading 7 file(s)
[1699830925644][coverageservice]: /home/ryan/Dev/vscode-coverage-gutters/example/node/lcov.info,/home/ryan/Dev/vscode-coverage-gutters/example/remote-node/lcov.info,/home/ryan/Dev/vscode-coverage-gutters/example/ruby/lcov.info,/home/ryan/Dev/vscode-coverage-gutters/example/java/my-app/cov.xml,/home/ryan/Dev/vscode-coverage-gutters/example/php/cov.xml,/home/ryan/Dev/vscode-coverage-gutters/example/python/cov.xml,/home/ryan/Dev/vscode-coverage-gutters/example/multimodule-java/jacoco.xml
[1699830925646][coverageservice]: Loaded 7 data file(s)
[1699830925670][coverageservice]: Caching 19 coverage(s)
[1699830925670][coverageservice]: READY
[1699830925670][coverageservice]: RENDERING
[1699830925670][renderer][section file path]: ./node/test.js
[1699830925671][renderer][section file path]: ./node/test.js
[1699830925671][coverageservice]: READY
[1699830925671][coverageservice]: Listening to file system at {/home/ryan/Dev/vscode-coverage-gutters/example}/**/{lcov.info,cov.xml,coverage.xml,jacoco.xml,coverage.cobertura.xml}
[1699830933310][coverageservice]: RENDERING
[1699830933311][renderer][section file path]: ./node/test.js
[1699830933311][coverageservice]: READY