Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error loading workspace...outside module and outside $GOPATH/src #2637

Closed
ricky-charlet opened this issue Feb 1, 2023 · 6 comments
Closed
Labels
FrozenDueToAge Question This is a question, rather than an issue report. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@ricky-charlet
Copy link

Howdy,

I'm using vscode 1.74.3
extension: remote-ssh 0.94.0 preview
(on remote installed) extension: go 0.37.1

I have an environment with a complex goroot and gopath which I accept the responsibility for manually configuring in my settings.

When opening my workspace, the go extension shows this error message:
----copy---
Error loading workspace: You are outside of a module and outside of $GOPATH/src. If you are using modules, please open your editor to a directory in your module. If you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new.
----paste---

Yet, I am quite certain my code is in $GOPATH/src.

Here are some diagnostic outputs:

my goextension-workspace settings file is
----copy---
{
"folders": [
{
"path": "halon/halon-src"
},
],
"settings": {
"go.languageServerFlags": [

	],
	"go.delveConfig": {

	},
	"go.gopath": "/ws/charletr/halon/halon-src/hpe-policyd",
	"go.toolsManagement.autoUpdate": true,
	"go.buildOnSave": "off",
	"go.goroot": "/ws/charletr/halon/build-genericx86-p4/tmp/work/core2-64-cnos-linux/hpe-policyd/1.0-r0/recipe-sysroot/usr/lib/go",
}

}
----paste----

(on remote) output of ls /ws/charletr/halon/halon-src/hpe-policyd:
--- copy---
charletr@hpnsw4371:$ ls /ws/charletr/halon/halon-src/hpe-policyd
cleanup_alerts.sh c_src metadata.json NAE_DESIGN.md ops-tests pkg REVIEWERS sandbox.proto scripts src templateapi tools
charletr@hpnsw4371:
$ ls /ws/charletr/halon/halon-src/hpe-policyd/src/rdlabs.hpecorp.net/hpe-policyd/
action agent database eventlog Gopkg.lock internal log main.go mock script utils vsx
adc capacities errpolicyd events Gopkg.toml libsandbox main_coverage_test.go main_test.go parser system_manager vendor watchdog
charletr@hpnsw4371:$
charletr@hpnsw4371:
$ ls /ws/charletr/halon/build-genericx86-p4/tmp/work/core2-64-cnos-linux/hpe-policyd/1.0-r0/recipe-sysroot/usr/lib/go
pkg src
charletr@hpnsw4371:~$
---- paste ---

output of vscode go env:
----copy---

go env
Workspace Folder (halon-src): /ws/charletr/halon/halon-src
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/users/charletr/.cache/go-build"
GOENV="/users/charletr/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/ws/charletr/halon/halon-src/hpe-policyd/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/ws/charletr/halon/halon-src/hpe-policyd"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/ws/charletr/halon/build-genericx86-p4/tmp/work/core2-64-cnos-linux/hpe-policyd/1.0-r0/recipe-sysroot/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/ws/charletr/halon/build-genericx86-p4/tmp/work/core2-64-cnos-linux/hpe-policyd/1.0-r0/recipe-sysroot/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L --sysroot="
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build697172772=/tmp/go-build -gno-record-gcc-switches"

----paste---

@findleyr findleyr transferred this issue from golang/go Feb 1, 2023
@gopherbot gopherbot added this to the Untriaged milestone Feb 1, 2023
@hyangah
Copy link
Contributor

hyangah commented Feb 2, 2023

@ricky-charlet It looks like the error message "outside module and outside $GOPATH/src" is exactly what's happening.

Your workspace root is /ws/charletr/halon/halon-src.
Your GOPATH is /ws/charletr/halon/halon-src/hpe-policyd.

And the workspace directory does't have go.mod, nor is under directory with go.mod so it is outside module. (as indicated in GOMOD="").

Can you tell me why you want to have your GOPATH under your workspace root? If that wasn't intended, remove "go.gopath": "/ws/charletr/halon/halon-src/hpe-policyd" from your setting.

Are you using Go modules or do you need to use the old GOPATH mode? If you use Go module, open the vscode window from the folder with go.mod file.

Currently this extension assumes the workspace to be organized in certain ways as described in https://github.com/golang/vscode-go#setting-up-your-workspace.

We have a plan to improve UX by removing this restriction (golang/go#57979) this year, but now you will need to either have your workspace folder under GOPATH or in a module or use go.work.

@hyangah hyangah added Question This is a question, rather than an issue report. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Feb 2, 2023
@ricky-charlet
Copy link
Author

ricky-charlet commented Feb 2, 2023

Thanks Hyang-Ah,

I'm still hoping this is really a configuration problem...
Firstly, I did try your advice about removing my explicit directorty from go.gopath. It did not help.

Now I will explain my (admittedly) complex setup.

I work at an enterprise where we compile a very large software set to run on an embedded device we sell. The compile task is equivalent (or larger) than building an entire linux distribution. Many people work on many parts. I personally am currently focused on only one daemon of the whole large set. And the daemon I have responsibility for is in golang.

my direcorty stucture will be
WORKSPACE_ROOT = /ws/charletr/halon/halon-src/
under that, a very long list of directories can be found, most of which I don't care about.
To successfully parse my hpe-policyd, I wish I could see into a few (not all) the directories under halon-src:
halon-src/hpe-policyd/src/rdlabs.hpecorp.net/hpe-policyd
halon-src/go-common/go-log/src/rdlabs.hpecorp.net/log
(and a few more which I will manage after I learn the pattern)

So I do not want to parse all of halon-src, only subdirectory parts of it.
And I don't have, and prefer not to start, a go mod file. I want vscode to find my source.
When I type that my go.path is /ws/charletr/halon/halon-src/hpe-policyd/src I wish vscode could find all the source located under /ws/charletr/halon/halon-src/hpe-policyd/src/rdlabs.hpecorp.net/hpe-policyd

---copy---
charletr@hpnsw4371:/ws/charletr/halon/halon-src/hpe-policyd/src/rdlabs.hpecorp.net/hpe-policyd$ ls
action agent database eventlog Gopkg.lock internal log main.go mock script utils vsx
adc capacities errpolicyd events Gopkg.toml libsandbox main_coverage_test.go main_test.go parser system_manager vendor watchdog
charletr@hpnsw4371:/ws/charletr/halon/halon-src/hpe-policyd/src/rdlabs.hpecorp.net/hpe-policyd$
---paste---

@hyangah
Copy link
Contributor

hyangah commented Feb 3, 2023

Option 1: If you want to keep your projects in the old GOPATH mode,
I think the easiest path forward is to utilize the multi-root workspace mode. (https://code.visualstudio.com/docs/editor/multi-root-workspaces)
So you can add the hpe-policyd and the go-common/go-log directories as roots.

Option 2: You may want to open a separate window for each project (hpe-policyd or go-log or ..).

Since you don't want to adopt Go modules, I think explicitly disabling the module mode ("go.toolsEnvVars": { "GO111MODULE": "off" }) is a good idea. You can also consider "go.inferGopath" if your projects are organized in a way to keep GOPATH under each root.

@ricky-charlet
Copy link
Author

"the go language server does not support a multiroot environment."

Sooo...I got it working. I pulled out a sledge hammer and:

  • erased my go installation
  • reinstalled go
  • reinstalled all the go tools vscode:go asked for (gopls, staticcheck, godef...)
  • deleted my workspace
    *recreated my workspace
  • configured my worspace GOPATH to be a few select subdirectories under my workspace root.

Seems it is working now. And I don't know which among those things was helpful.

@ricky-charlet
Copy link
Author

I'm confident I had some type of config error in my environment that I wound up healing by reinstalling golang and vscode:go extension.

So...not a bug in vscode or vscode:go.

I'll mark this closed.

@ricky-charlet
Copy link
Author

BUT!!! I do want respect for my use case please....
rootDir
+--codedir1
+--cod3dir2
+--codedir3
+--codedir4

where I can direct vscode:go to parse only a subset of codedirs. And don't tell me to solve this with modules...just parse the list of directories I can point at please. This is achievable right now, but the UI requires I edit settings.json files and forums have a difficult time believing I really want to do this. It should be simpler for me to instruct vscode:go where my directories are.

@golang golang locked and limited conversation to collaborators Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Question This is a question, rather than an issue report. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants