Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VScode show me the error after I install the proxy in vscode

When opening a directory in VSCode that consists of multiple Go projects the following error appears:

gopls requires a module at the root of your workspace.
You can work with multiple modules by opening each one as a workspace folder.
Improvements to this workflow will be coming soon (https://github.com/golang/go/issues/32394),
and you can learn more here: https://github.com/golang/go/issues/36899.

How can this be fixed?

like image 957
郭寰宇 Avatar asked Jan 16 '21 10:01

郭寰宇


People also ask

How do I fix VS Code proxy error?

If CodeTogether is still not connecting correctly through your proxy, you can try disabling the proxy support for extensions by setting http. proxySupport to off . For more information on configuring proxy support in VS Code, go to https://code.visualstudio.com/docs/setup/network#_proxy-server-support.

How do I change my proxy code on VS Code?

If your network requires a proxy to access the Internet, set the Visual Studio Code proxy as follows: Open Visual Studio Code, click the settings icon in the lower left corner, and click Settings.

How do I access settings JSON VS Code?

You can open the settings. json file with the Preferences: Open Settings (JSON) command in the Command Palette (Ctrl+Shift+P). Once the file is open in an editor, delete everything between the two curly braces {} , save the file, and VS Code will go back to using the default values.


5 Answers

You probably have more than one go module in your workspace. If that is the case, you can change the go extension settings, in order to allow gopls to look for multiple modules in the workspace. Just add the following to your settings.json:

"gopls": {
    "experimentalWorkspaceModule": true,
}

You can read more about gopls configuration in the docs: https://github.com/golang/tools/blob/master/gopls/doc/settings.md

like image 82
Stefano Mozart Avatar answered Oct 24 '22 08:10

Stefano Mozart


To solve this, follow below steps :

step 1 : Open Vscode, and then go to settings.

step 2 : In the search bar , type gopls

step 3 : Just below that you will find settings.json, click on that

step 4 : Paste the below code their "gopls": { "experimentalWorkspaceModule": true, }

step 5 : Save it and restart the Vscode, You are good to go now.

like image 39
Abhishek Nishad Avatar answered Oct 24 '22 07:10

Abhishek Nishad


Go 1.18+

From Go 1.18 onwards there is native support for multi-module workspaces. This is done by having a go.work file present in your parent directory.

For a directory structure such as:

$ tree /my/parent/dir
/my/parent/dir
├── project-one
│   ├── go.mod
│   ├── project-one.go
│   └── project-one_test.go
└── project-two
    ├── go.mod
    ├── project-two.go
    └── project-two_test.go

Create and populate the file by executing go work:

cd /my/parent/dir
go work init
go work use project-one
go work use project-two

This will add a go.work file in your parent directory that contains a list of directories you marked for usage:

go 1.18

use (
    ./project-one
    ./project-two
)
like image 8
F1ko Avatar answered Oct 24 '22 07:10

F1ko


The setting has changed, now you need to use:

"gopls": {
    "build.experimentalWorkspaceModule": true,
}
like image 6
papillon88 Avatar answered Oct 24 '22 08:10

papillon88


I had this error because I had not created my modules inside a src directory. So I had:

$GOPATH
   -> bin
   -> pkg
   -> github.com
      -> Module
         -> go.mod

and that needed to be:

$GOPATH
   -> bin
   -> pkg
   -> src
       -> github.com
          -> Module
            -> go.mod
like image 3
Liam Avatar answered Oct 24 '22 07:10

Liam