3

I have a golang project which includes windows-specific code. When working on this project from vscode running on macOS, I'm getting the following warning opening file getFileCreationTime_windows.go:

This file is within module ".", which is not included in your workspace. To fix this problem, you can add a go.work file that uses this directory. See the documentation for more information on setting up your workspace: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md.go list

It's not clear to me what should I do with this warning. I'm not using multiple modules, it's a simple application project.

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
vbezhenar
  • 11,148
  • 9
  • 49
  • 63

1 Answers1

1

The Go language server does not support build tags very well. See the discussions in this issue: x/tools/gopls: improve handling for build tags #29202.

You can ignore this warning message.

If you need completions, diagnostics, etc for this file, you can choose one of the following approaches:

  1. If you only need to edit files for other platforms occasionally, you can start VSCode like this:

    GOOS=windows code /path/to/the/project
    
  2. If you are developing codes for other platforms most of the time and you don't want to specify GOOS every time, you can save it to the .vscode/settings.json file:

    {
      "go.toolsEnvVars": { "GOOS": "windows" }
    }
    
Zeke Lu
  • 6,349
  • 1
  • 17
  • 23