Skip to content

Test explorer fails to resolve module name when the name does not appear on the first line in go.mod  #2171

@dlipovetsky

Description

@dlipovetsky

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.18 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • e18005f0f1b33c29e81d732535d8c0e47cafb0b5
      x64
      
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.32.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • n/a

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.

Describe the bug

The current method to find the module name from the contents of go.mod fails if the module name does not appear on the first line. That can happen, for example, if the first line is comment. By comparison, the go list -m command does find the name.

Steps to reproduce the behavior:

  1. Create a new module, or use an existing module.
  2. Insert a comment // Example comment on the first line of the go.mod file.
  3. Save the go.mod file.
  4. Open the Test Explorer.
  5. Notice the error diaog "Failed to resolve tests" appears.
  6. Inspect the "Go" output to find the message Failed to resolve tests: TypeError: Cannot read properties of null (reading 'groups')

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions