This file is within module ".", which is not included in your workspace – Go

by
Ali Hasan
algorithm gopls visual-studio-code

Quick Fix: 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" }
    }
    

The Solutions:

Solution 1: Ignore the warning

The warning is caused by the Go language server’s poor support for build tags. Since you’re not using multiple modules, you can safely ignore this warning message.

Solution 2: Start VSCode with `GOOS=windows`

If you need completions, diagnostics, etc. for the file with build tags, you can start VSCode with the `GOOS` environment variable set to “windows”. This will force the Go language server to use the Windows-specific version of the file.

GOOS=windows code /path/to/the/project

Solution 3: Set `go.toolsEnvVars` in `.vscode/settings.json`

If you want to permanently set the `GOOS` environment variable for VSCode, you can add the following code to your `.vscode/settings.json` file:

{
  "go.toolsEnvVars": { "GOOS": "windows" }
}

This will force the Go language server to always use the Windows-specific version of the file, regardless of the operating system you’re running VSCode on.

Q&A

What do I need to do if I get a warning that this file is within module .

You can ignore warning message.

Can I get completions if I see this warning?

Yes, you can either specify GOOS every time or you can save it to the .vscode/settings.json file

Video Explanation:

The following video, titled "Related Video", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Your browser can't play this video. Learn more.