emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.8k stars 891 forks source link

gopls started with incorrect project root #3807

Closed Cerebus closed 2 years ago

Cerebus commented 2 years ago

Thank you for the bug report

Bug description

A golang project with one go.mod in the root (not a nested project). projectile finds the root correctly:

~/D/p/kne/topo [main] λ projectile-project-root
/Users/tmiller/Documents/projects/kne/

But lsp is started with the wrong root:

2022/11/09 08:43:30 go env for /Users/tmiller/Documents/projects
(root /Users/tmiller/Documents/projects)
(go version go version go1.19.2 darwin/amd64)
(valid build configuration = false)
(build flags: [])
GOWORK=
GOMOD=/dev/null
GOPROXY=https://proxy.golang.org,direct
GOROOT=/usr/local/Cellar/go/1.19.2/libexec
GO111MODULE=
GOPATH=/Users/tmiller/projects/go
GONOSUMDB=
GOFLAGS=
GONOPROXY=
GOSUMDB=sum.golang.org
GOCACHE=/Users/tmiller/Library/Caches/go-build
GOPRIVATE=
GOMODCACHE=/Users/tmiller/projects/go/pkg/mod
GOINSECURE=

No appropriate completions are offered at all.

Steps to reproduce

Expected behavior

Which Language Server did you use?

gopls 0.10.1

OS

MacOS

Error callstack

No response

Anything else?

No response

Cerebus commented 2 years ago

Absolutely minimal example:

/Documents/projects/newgo main
> ls -la
total 16
drwxr-xr-x   5 tmiller  staff   160 Nov  9 09:05 .
drwxr-xr-x@ 92 tmiller  staff  2944 Nov  9 09:05 ..
drwxr-xr-x  10 tmiller  staff   320 Nov  9 09:05 .git
-rw-r--r--   1 tmiller  staff    33 Nov  9 09:06 foo.go
-rw-r--r--   1 tmiller  staff    28 Nov  9 09:04 go.mod

Projectile correct:

~/D/projects/newgo [main] λ projectile-project-root
/Users/tmiller/Documents/projects/newgo/

Still starts in the wrong directory:

Command "gopls -remote=auto" is present on the path.
Command "gopls -remote=auto" is present on the path.
Found the following clients for /Users/tmiller/Documents/projects/kne/topo/topo.go: (server-id gopls, priority 0)
The following clients were selected based on priority: (server-id gopls, priority 0)
2022/11/09 08:57:21 Handshake session update
    update_session=1
    debug_address=""
    logfile=""
    server="1"
    gopls_path="/Users/tmiller/projects/go/bin/gopls"

Cancelling textDocument/documentLink(5) in hook post-command-hook
Cancelling textDocument/codeAction(4) in hook post-command-hook
2022/11/09 08:57:42 go env for /Users/tmiller/Documents/projects
(root /Users/tmiller/Documents/projects)
(go version go version go1.19.2 darwin/amd64)
(valid build configuration = false)
(build flags: [])
GO111MODULE=
GOMODCACHE=/Users/tmiller/projects/go/pkg/mod
GOPROXY=https://proxy.golang.org,direct
GOCACHE=/Users/tmiller/Library/Caches/go-build
GONOSUMDB=
GOWORK=
GONOPROXY=
GOROOT=/usr/local/Cellar/go/1.19.2/libexec
GOINSECURE=
GOMOD=/dev/null
GOSUMDB=sum.golang.org
GOPATH=/Users/tmiller/projects/go
GOFLAGS=
GOPRIVATE=

2022/11/09 08:57:42 go/packages.Load #1
    snapshot=0
    directory=/Users/tmiller/Documents/projects
    query=[./ builtin]
    packages=2

2022/11/09 08:57:42 go/packages.Load #1: updating metadata for 0 packages

Cancelling textDocument/hover(30) in hook after-change-functions
Cancelling textDocument/documentHighlight(29) in hook after-change-functions
Cancelling textDocument/documentLink(28) in hook after-change-functions
Cancelling textDocument/codeAction(27) in hook after-change-functions
Cancelling textDocument/documentLink(25) in hook after-change-functions
Cancelling textDocument/documentLink(21) in hook after-change-functions
Cancelling textDocument/documentLink(17) in hook after-change-functions
Cancelling textDocument/documentLink(13) in hook after-change-functions
Cancelling textDocument/documentLink(9) in hook after-change-functions
Cancelling textDocument/codeLens(7) in hook after-change-functions
Cancelling textDocument/documentHighlight(41) in hook after-change-functions
Cancelling textDocument/documentLink(40) in hook after-change-functions
Cancelling textDocument/codeAction(39) in hook after-change-functions
Cancelling textDocument/hover(38) in hook after-change-functions
Cancelling textDocument/codeLens(34) in hook after-change-functions
Cancelling textDocument/documentLink(33) in hook after-change-functions
Cancelling textDocument/codeLens(49) in hook after-change-functions
Cancelling textDocument/documentLink(48) in hook after-change-functions
Cancelling textDocument/codeAction(47) in hook after-change-functions
Cancelling textDocument/codeLens(55) in hook after-change-functions
Cancelling textDocument/documentLink(54) in hook after-change-functions
Cancelling textDocument/codeAction(53) in hook after-change-functions
Cancelling textDocument/documentHighlight(62) in hook after-change-functions
Cancelling textDocument/documentLink(61) in hook after-change-functions
Cancelling textDocument/codeAction(60) in hook after-change-functions
Cancelling textDocument/hover(59) in hook after-change-functions
Cancelling textDocument/codeLens(58) in hook after-change-functions
Cancelling textDocument/documentLink(57) in hook after-change-functions
Cancelling textDocument/codeLens(67) in hook after-change-functions
Cancelling textDocument/documentHighlight(66) in hook after-change-functions
Cancelling textDocument/documentLink(65) in hook after-change-functions
Cancelling textDocument/codeAction(64) in hook after-change-functions
Cancelling textDocument/hover(63) in hook after-change-functions
Cancelling textDocument/codeLens(72) in hook after-change-functions
Cancelling textDocument/documentHighlight(71) in hook after-change-functions
Cancelling textDocument/documentLink(70) in hook after-change-functions
Cancelling textDocument/codeAction(69) in hook after-change-functions
Cancelling textDocument/hover(68) in hook after-change-functions
Cancelling textDocument/codeLens(77) in hook kill-buffer-hook
Cancelling textDocument/hover(76) in hook kill-buffer-hook
Cancelling textDocument/documentHighlight(75) in hook kill-buffer-hook
Cancelling textDocument/documentSymbol(2) in hook kill-buffer-hook
Cancelling textDocument/documentLink(74) in hook post-command-hook
Cancelling textDocument/codeAction(73) in hook post-command-hook
Cleaning up watches for folder /Users/tmiller/Documents/projects. There is no workspace watching this folder...
Command "gopls -remote=auto" is present on the path.
Command "gopls -remote=auto" is present on the path.
Found the following clients for /Users/tmiller/Documents/projects/newgo/foo.go: (server-id gopls, priority 0)
The following clients were selected based on priority: (server-id gopls, priority 0)
2022/11/09 09:05:45 Handshake session update
    update_session=1
    debug_address=""
    logfile=""
    server="1"
    gopls_path="/Users/tmiller/projects/go/bin/gopls"

Cancelling textDocument/documentLink(85) in hook after-change-functions
Cancelling textDocument/codeAction(84) in hook after-change-functions
Cancelling textDocument/documentLink(83) in hook after-change-functions
Cancelling textDocument/codeLens(81) in hook after-change-functions
Cancelling textDocument/documentLink(91) in hook after-change-functions
Cancelling textDocument/codeAction(90) in hook after-change-functions
Cancelling textDocument/codeLens(89) in hook after-change-functions
Cancelling textDocument/documentLink(88) in hook after-change-functions
Cancelling textDocument/documentLink(94) in hook post-command-hook
Cancelling textDocument/codeAction(93) in hook post-command-hook
Cancelling textDocument/documentLink(100) in hook post-command-hook
Cancelling textDocument/codeAction(99) in hook post-command-hook
2022/11/09 09:06:06 go env for /Users/tmiller/Documents/projects
(root /Users/tmiller/Documents/projects)
(go version go version go1.19.2 darwin/amd64)
(valid build configuration = false)
(build flags: [])
GOSUMDB=sum.golang.org
GONOSUMDB=
GONOPROXY=
GOROOT=/usr/local/Cellar/go/1.19.2/libexec
GOPRIVATE=
GOFLAGS=
GOPATH=/Users/tmiller/projects/go
GOMODCACHE=/Users/tmiller/projects/go/pkg/mod
GOCACHE=/Users/tmiller/Library/Caches/go-build
GOMOD=/dev/null
GOWORK=
GO111MODULE=
GOINSECURE=
GOPROXY=https://proxy.golang.org,direct

2022/11/09 09:06:06 go/packages.Load #1
    snapshot=0
    directory=/Users/tmiller/Documents/projects
    query=[./ builtin]
    packages=2

2022/11/09 09:06:06 go/packages.Load #1: updating metadata for 0 packages

Cancelling textDocument/documentLink(104) in hook post-command-hook
Cancelling textDocument/codeAction(103) in hook post-command-hook
Cancelling textDocument/documentLink(112) in hook post-command-hook
Cancelling textDocument/codeAction(111) in hook post-command-hook
Cancelling textDocument/documentLink(108) in hook post-command-hook
yyoncho commented 2 years ago

Use lsp-workspace-folders-add/remove to fix incorrect project roots. Note that lsp-mode does not pick the project root but it is the user that either confirms the project root or uses I to interactively select the correct one.