In VSCode, to show code coverage for all packages in a Go project, you need to generate a combined coverage report and then use an extension that supports displaying that coverage.
Generate Combined Coverage Report: Run Go tests with coverage for all packages and generate a combined report:
go test -coverprofile=coverage.out ./…
Use a Coverage Extension: Install a VSCode extension like “Coverage Gutters” or “Go Test Explorer.” These extensions allow you to load a coverage report and visualize it within VSCode.
Load the Coverage Report:
With the extension installed, open the coverage report (coverage.out) in VSCode.
Activate the coverage display feature (usually by clicking an icon or running a command from the command palette).
The coverage data should now be visible across all packages in your project.
With this setup, you should be able to view coverage across multiple packages in your Go project within VSCode.
Ensure that you have the official Go extension for VSCode installed. You can find it in the Extensions view (Ctrl+Shift+X) by searching for “Go” and installing the one provided by “Go Team at Google”.
Open your VSCode settings (File > Preferences > Settings or Ctrl+,) and click on the “Open Settings (JSON)” icon in the top-right corner of the settings window.