golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.88k stars 752 forks source link

Error loading workspace folders (expected 1, got 0) #3563

Open JasonGoemaat opened 1 week ago

JasonGoemaat commented 1 week ago

Type: Bug

Create directory, use 'go mod init mine', open folder in vscode.

This error shows up twice in the bottom-right when the extension tries to open.

Extension version: 0.42.1 VS Code version: Code 1.94.1 (e10f2369d0d9614a452462f2e01cdc4aa9486296, 2024-10-05T05:44:32.189Z) OS version: Windows_NT x64 10.0.19045 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2592)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|undefined| |Memory (System)|31.88GB (21.23GB free)| |Process Argv|. --crash-reporter-id 8243935f-bf3f-4543-9aa0-04bf73824cd2| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492cf:30256860 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 pythongtdpath:30769146 pythonnoceb:30805159 asynctok:30898717 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 accentitlementst:30995554 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 bdiig495:31013172 a69g1124:31058053 dvdeprecation:31068756 dwnewjupytercf:31046870 impr_priority:31102340 nativerepl1:31139838 refactort:31108082 pythonrstrctxt:31112756 wkspc-onlycs-t:31132770 wkspc-ranged-t:31151552 cf971741:31144450 defaultse:31146405 iacca1:31156133 notype1cf:31157160 5fd0e150:31155592 ```
JasonGoemaat commented 1 week ago

Error:

image

Using Windows+R and typing in the string file:///C:/git/go/steampath opens the folder in a windows explorer window.

JasonGoemaat commented 1 week ago

This may be limited to git bash. I use git bash on windows and my normal workflow for any programming with vscode is to open a git bash terminal and cd to the directory, using the command line for git operations. I run 'code .' in the git bash terminal to open up vscode, and that is when I get the error. After spending a few hours uninstalling the extension, disabling all my other extensions, reinstalling go, etc, I started a powershell prompt and started vscode from it and I didn't get the errors, but I get them when I start from my git bash prompt. None of the other languages I use (C#, C, node, java) seem to have issues and vscode opens the folder and lets me edit the files just fine when I open from git bash, but the go extension throws this error (twice) for some reason.

JasonGoemaat commented 1 week ago

When it's working I see this when I open gopls trace:

[Info  - 9:49:51 PM] 2024/10/14 21:49:51 Created View (#1)
    directory=C:\git\go\workspace\pathway-saveeditor
    view_type="GoWork"
    root_dir="file:///C:/git/go/workspace"
    go_version="go version go1.23.2 windows/amd64"
    build_flags=[]
    env={GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\jason\AppData\Local\go-build GOMODCACHE:C:\Users\jason\go\pkg\mod GOPATH:C:\Users\jason\go GOPRIVATE: GOFLAGS: GO111MODULE: GOTOOLCHAIN:auto GoVersion:23 GoVersionOutput:go version go1.23.2 windows/amd64
 ExplicitGOWORK: EffectiveGOPACKAGESDRIVER:}
    env_overlay=[]

When I use git bash the go output shows this:

2024-10-14 21:52:41.230 [info] Try to start language server - activation (enabled: true)
2024-10-14 21:52:41.392 [info] Running language server gopls(v0.16.2/go1.23.2)

And the gopls output shows a bunch of these, but with no non-generic information like what it tried to open

[Error - 9:52:41 PM] Request textDocument/documentSymbol failed.
  Message: no views
  Code: 0 
[Error - 9:52:41 PM] Request textDocument/codeAction failed.
  Message: no views
  Code: 0
findleyr commented 1 day ago

Sorry, I haven't had time to look into this yet. I believe the problem may be related to a runtime.GOOS mismatch, and resulting confusion in the filepath package.

Can you please share the result of go version -m $(which gopls)?