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

version 1.7 doesn't work with gopls - "failed to get workspace configuration from client" #587

Open
shmul opened this issue Jan 9, 2021 · 21 comments

Comments

@shmul
Copy link

shmul commented Jan 9, 2021

Hi,

With the upgrade to 1.7 eglot stopped working with gopls (I tried a couple of versions and they all behaved the same; now I'm at 0.6.2). I switched to lsp-mode ( :( ) and it works fine. I'm using Mac Big Sur, though the problems were there with previous OS version as well. Emacs version is 27.1 .
I'll be happy to provide additional information if needed.

Cheers,
Shmul

[client-reply] (id:1) ERROR Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :id 1 :error
          (:code -32603 :message "Internal error"))
[server-notification] Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 3 :message "Error loading packages: failed to get workspace configuration from client (file:///Users/PROJECT-DIR/): Internal error"))
[server-notification] Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 1 :message "Error loading workspace folders (expected 1, got 0)\nfailed to load view for file:///Users/PROJECT-DIR/: failed to get workspace configuration from client (file:///Users/PROJECT-DIR/): Internal error\n"))
[server-notification] Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 4 :message "Loading packages..."))
[server-request] (id:2) Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///Users/PROJECT-DIR/pkg/bot" :section "gopls")])
          :id 2)
[client-reply] (id:2) ERROR Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :id 2 :error
          (:code -32603 :message "Internal error"))
[server-notification] Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 3 :message "Error loading packages: failed to get workspace configuration from client (file:///Users/PROJECT-DIR/pkg/bot): Internal error"))
[server-notification] Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 1 :message "Error loading workspace folders (expected 1, got 0)\nfailed to load view for file:///Users/PROJECT-DIR/pkg/bot: failed to get workspace configuration from client (file:///Users/PROJECT-DIR/pkg/bot): Internal error\n"))
[server-request] (id:3) Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:section "gopls")])
          :id 3)
[client-reply] (id:3) ERROR Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :id 3 :error
          (:code -32603 :message "Internal error"))
[client-request] (id:2) Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :id 2 :method "textDocument/signatureHelp" :params
          (:textDocument
           (:uri "file:///Users/PROJECT-DIR/pkg/bot/bot.go")
           :position
           (:line 0 :character 0)))
[client-request] (id:3) Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :id 3 :method "textDocument/hover" :params
          (:textDocument
           (:uri "file:///Users/PROJECT-DIR/pkg/bot/bot.go")
           :position
           (:line 0 :character 0)))
[client-request] (id:4) Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :id 4 :method "textDocument/documentHighlight" :params
          (:textDocument
           (:uri "file:///Users/PROJECT-DIR/pkg/bot/bot.go")
           :position
           (:line 0 :character 0)))
[server-reply] (id:2) ERROR Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :error
          (:code 0 :message "no views in session")
          :id 2)
[internal] (id:2) ERROR Sat Jan  9 14:03:15 2021:
(:message "error ignored, status set (no views in session)" :id 2 :error 0)
[server-reply] (id:3) ERROR Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :error
          (:code 0 :message "no views in session")
          :id 3)
[internal] (id:3) ERROR Sat Jan  9 14:03:15 2021:
(:message "error ignored, status set (no views in session)" :id 3 :error 0)
[server-reply] (id:4) ERROR Sat Jan  9 14:03:15 2021:
(:jsonrpc "2.0" :error
          (:code 0 :message "no views in session")
          :id 4)
[internal] (id:4) ERROR Sat Jan  9 14:03:15 2021:
(:message "error ignored, status set (no views in session)" :id 4 :error 0)
@joaotavora
Copy link
Owner

I'm using the latest Eglot with gopls just fine.

❯ go version
go version go1.15.6 linux/amd64

Works fine with Emacs 27.1.

Here's an example log of events:

[client-request] (id:1) Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
          (:processId 58188 :rootPath "...elided..." :rootUri "file:///...also-elided..." :initializationOptions #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                                                                                                                                                     ())
                      :capabilities
                      (:workspace
                       (:applyEdit t :executeCommand
                                   (:dynamicRegistration :json-false)
                                   :workspaceEdit
                                   (:documentChanges :json-false)
                                   :didChangeWatchedFiles
                                   (:dynamicRegistration t)
                                   :symbol
                                   (:dynamicRegistration :json-false)
                                   :configuration t)
                       :textDocument
                       (:synchronization
                        (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
                        :completion
                        (:dynamicRegistration :json-false :completionItem
                                              (:snippetSupport t)
                                              :contextSupport t)
                        :hover
                        (:dynamicRegistration :json-false :contentFormat
                                              ["markdown" "plaintext"])
                        :signatureHelp
                        (:dynamicRegistration :json-false :signatureInformation
                                              (:parameterInformation
                                               (:labelOffsetSupport t)))
                        :references
                        (:dynamicRegistration :json-false)
                        :definition
                        (:dynamicRegistration :json-false)
                        :declaration
                        (:dynamicRegistration :json-false)
                        :implementation
                        (:dynamicRegistration :json-false)
                        :typeDefinition
                        (:dynamicRegistration :json-false)
                        :documentSymbol
                        (:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind
                                              (:valueSet
                                               [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]))
                        :documentHighlight
                        (:dynamicRegistration :json-false)
                        :codeAction
                        (:dynamicRegistration :json-false :codeActionLiteralSupport
                                              (:codeActionKind
                                               (:valueSet
                                                ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"]))
                                              :isPreferredSupport t)
                        :formatting
                        (:dynamicRegistration :json-false)
                        :rangeFormatting
                        (:dynamicRegistration :json-false)
                        :rename
                        (:dynamicRegistration :json-false)
                        :publishDiagnostics
                        (:relatedInformation :json-false))
                       :experimental #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                   ()))))
[server-reply] (id:1) Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :result
          (:capabilities
           (:textDocumentSync
            (:openClose t :change 2 :save nil)
            :completionProvider
            (:triggerCharacters
             ["."])
            :hoverProvider t :signatureHelpProvider
            (:triggerCharacters
             ["(" ","])
            :definitionProvider t :typeDefinitionProvider t :implementationProvider t :referencesProvider t :documentHighlightProvider t :documentSymbolProvider t :codeActionProvider
            (:codeActionKinds
             ["quickfix" "refactor.extract" "refactor.rewrite" "source.fixAll" "source.organizeImports"])
            :codeLensProvider nil :documentLinkProvider nil :workspaceSymbolProvider t :documentFormattingProvider t :documentOnTypeFormattingProvider
            (:firstTriggerCharacter "")
            :renameProvider t :foldingRangeProvider t :executeCommandProvider
            (:commands
             ["gopls.generate" "gopls.fill_struct" "gopls.regenerate_cgo" "gopls.test" "gopls.tidy" "gopls.undeclared_name" "gopls.add_dependency" "gopls.upgrade_dependency" "gopls.remove_dependency" "gopls.vendor" "gopls.extract_variable" "gopls.extract_function" "gopls.gc_details" "gopls.generate_gopls_mod"])
            :callHierarchyProvider t :workspace
            (:workspaceFolders
             (:supported t :changeNotifications "workspace/didChangeWorkspaceFolders")))
           :serverInfo
           (:name "gopls" :version "{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"v0.5.5\",\"sum\":\"h1:YBLs2WCwxx6mBF98Y6/mDIpKhP4Dt4Dz2q6LnMRBpDw=\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.1\",\"sum\":\"h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.3.0\",\"sum\":\"h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20201020160332-67f06af15bc9\",\"sum\":\"h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.0.0-20201204180437-c46b611624b3\",\"sum\":\"h1:uxH+MECLNmX/vsPe4txyeQ1LCmhdUxf7p4hjkHexg+c=\"},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.0.1-2020.1.6\",\"sum\":\"h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.0.0-20200927160801-5bfeb2e70dd6\",\"sum\":\"h1:z+/YqapuV7VZPvBb3GYmuEJbA88M3PFUxaHilHYVCpQ=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.2.0\",\"sum\":\"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\"}]}"))
          :id 1)
[client-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "initialized" :params #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                            ()))
[client-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///...also-elided...main.go" :version 0 :languageId "go" :text "...elided...")))
[client-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///...also-elided...service/response.go" :version 0 :languageId "go" :text "...elided...")))
[client-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///...also-elided...service/games.go" :version 0 :languageId "go" :text "...elided...")))
[client-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///...also-elided...service/service.go" :version 0 :languageId "go" :text "...elided...")))
[client-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params
          (:settings nil))
[server-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 4 :message "Loading packages..."))
[server-request] (id:1) Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///...also-elided..." :section "gopls")])
          :id 1)
[client-reply] (id:1) Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :id 1 :result
          [nil])
[server-request] (id:2) Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "client/registerCapability" :params
          (:registrations
           [(:id "workspace/didChangeWatchedFiles-0" :method "workspace/didChangeWatchedFiles" :registerOptions
                 (:watchers
                  [(:globPattern "**/*.{go,mod,sum}" :kind 7)]))])
          :id 2)
[client-reply] (id:2) Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :id 2 :result nil)
[server-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "window/logMessage" :params
          (:type 3 :message "2021/01/09 12:22:28 go env for /...also-elided...\n(root ...also-elided...)\n(go version go version go1.15.6 linux/amd64)\n(valid build configuration = true)\n(build flags: [])\nGOMOD=/...also-elided...go.mod\nGONOPROXY=\nGOPATH=/home/capitaomorte/.golang\nGOPRIVATE=\nGOROOT=/opt/go\nGO111MODULE=\nGOINSECURE=\nGOMODCACHE=/home/capitaomorte/.golang/pkg/mod\nGONOSUMDB=\nGOSUMDB=sum.golang.org\nGOCACHE=/home/capitaomorte/.cache/go-build\nGOPROXY=https://proxy.golang.org,direct\nGOFLAGS=\n\n"))
[server-notification] Sat Jan  9 12:22:28 2021:
(:jsonrpc "2.0" :method "window/logMessage" :params
          (:type 3 :message "2021/01/09 12:22:28 go/packages.Load\n	snapshot=0\n	directory=...also-elided...\n	query=[builtin ...also-elided.../...]\n	packages=3\n"))
[server-notification] Sat Jan  9 12:22:29 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 3 :message "Finished loading packages."))
[server-request] (id:3) Sat Jan  9 12:22:29 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:section "gopls")])
          :id 3)
[client-reply] (id:3) Sat Jan  9 12:22:29 2021:
(:jsonrpc "2.0" :id 3 :result
          [nil])
[server-request] (id:4) Sat Jan  9 12:22:29 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///...also-elided..." :section "gopls")])
          :id 4)
[client-reply] (id:4) Sat Jan  9 12:22:29 2021:
(:jsonrpc "2.0" :id 4 :result
          [nil])u

@shmul
Copy link
Author

shmul commented Jan 9, 2021

Thanks for the quick response. It might be a Mac thing (I noticed you use Linux). Can you please share your recommended plain vanilla eglot config? Any suggestions regarding logging collection from gopls to try to get to the bottom of this issue?

Cheers,
Shmul

@shmul
Copy link
Author

shmul commented Jan 9, 2021

I investigated it some more and it seems that disabling the workspaceSymbolProvider capability works around this issue while sacrificing some functionality. BTW, the same (?) can be achieved by changing the eglot-client-capabilities code and commenting out the :configuration line. I hope this is helpful.

@joaotavora
Copy link
Owner

plain vanilla eglot config?

See the README. If it's not clear, it's no configuration. For gopls you don't need any configuration, just install Eglot (and its dependencies). The best way to do that is to M-x package-install.

I hope this is helpful.

It might be, it gives me a hint. What would be even more helpful is if you would share (in a snippet) your entire transcript of Eglot's conversation with your gopls server. From the initialization message onwards.

@shmul
Copy link
Author

shmul commented Jan 9, 2021

I'll be damned if it didn't disappeared... I commented out my change (;(setq eglot-ignored-server-capabilites (quote (:workspaceSymbolProvider))) ) and restarted emacs to reproduce the error and it went away 🤷‍♂️ . Luckily I saved a copy of the transcript and it is below. Perhaps some state on gopls side was cleared?

(:jsonrpc "2.0" :id 1 :method "initialize" :params
          (:processId 9831 :rootPath "/Users/shmul/PROJECTDIR/" :rootUri "file:///Users/shmul/PROJECTDIR/" :initializationOptions #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                                                                                                                              ())
                      :capabilities
                      (:workspace
                       (:applyEdit t :executeCommand
                                   (:dynamicRegistration :json-false)
                                   :workspaceEdit
                                   (:documentChanges :json-false)
                                   :didChangeWatchedFiles
                                   (:dynamicRegistration t)
                                   :symbol
                                   (:dynamicRegistration :json-false)
                                   :configuration t)
                       :textDocument
                       (:synchronization
                        (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
                        :completion
                        (:dynamicRegistration :json-false :completionItem
                                              (:snippetSupport :json-false)
                                              :contextSupport t)
                        :hover
                        (:dynamicRegistration :json-false :contentFormat
                                              ["markdown" "plaintext"])
                        :signatureHelp
                        (:dynamicRegistration :json-false :signatureInformation
                                              (:parameterInformation
                                               (:labelOffsetSupport t)))
                        :references
                        (:dynamicRegistration :json-false)
                        :definition
                        (:dynamicRegistration :json-false)
                        :declaration
                        (:dynamicRegistration :json-false)
                        :implementation
                        (:dynamicRegistration :json-false)
                        :typeDefinition
                        (:dynamicRegistration :json-false)
                        :documentSymbol
                        (:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind
                                              (:valueSet
                                               [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]))
                        :documentHighlight
                        (:dynamicRegistration :json-false)
                        :codeAction
                        (:dynamicRegistration :json-false :codeActionLiteralSupport
                                              (:codeActionKind
                                               (:valueSet
                                                ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"]))
                                              :isPreferredSupport t)
                        :formatting
                        (:dynamicRegistration :json-false)
                        :rangeFormatting
                        (:dynamicRegistration :json-false)
                        :rename
                        (:dynamicRegistration :json-false)
                        :publishDiagnostics
                        (:relatedInformation :json-false))
                       :experimental #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                   ()))))
[server-reply] (id:1) Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :result
          (:capabilities
           (:textDocumentSync
            (:openClose t :change 2 :save nil)
            :completionProvider
            (:triggerCharacters
             ["."])
            :hoverProvider t :signatureHelpProvider
            (:triggerCharacters
             ["(" ","])
            :definitionProvider t :typeDefinitionProvider t :implementationProvider t :referencesProvider t :documentHighlightProvider t :documentSymbolProvider t :codeActionProvider
            (:codeActionKinds
             ["quickfix" "refactor.extract" "refactor.rewrite" "source.fixAll" "source.organizeImports"])
            :codeLensProvider nil :documentLinkProvider nil :workspaceSymbolProvider t :documentFormattingProvider t :documentOnTypeFormattingProvider
            (:firstTriggerCharacter "")
            :renameProvider t :foldingRangeProvider t :executeCommandProvider
            (:commands
             ["gopls.generate" "gopls.fill_struct" "gopls.regenerate_cgo" "gopls.test" "gopls.tidy" "gopls.update_go_sum" "gopls.undeclared_name" "gopls.go_get_package" "gopls.add_dependency" "gopls.upgrade_dependency" "gopls.remove_dependency" "gopls.vendor" "gopls.extract_variable" "gopls.extract_function" "gopls.gc_details" "gopls.generate_gopls_mod"])
            :callHierarchyProvider t :workspace
            (:workspaceFolders
             (:supported t :changeNotifications "workspace/didChangeWorkspaceFolders")))
           :serverInfo
           (:name "gopls" :version "{\"path\":\"golang.org/x/tools/gopls\",\"version\":\"v0.6.2\",\"sum\":\"h1:c3zVKbg4zEOayCwgV/RCA3ucNriOyzfTv22fBW+D1EQ=\",\"deps\":[{\"path\":\"github.com/BurntSushi/toml\",\"version\":\"v0.3.1\",\"sum\":\"h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\"},{\"path\":\"github.com/google/go-cmp\",\"version\":\"v0.5.1\",\"sum\":\"h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=\"},{\"path\":\"github.com/sergi/go-diff\",\"version\":\"v1.1.0\",\"sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\"},{\"path\":\"golang.org/x/mod\",\"version\":\"v0.3.0\",\"sum\":\"h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=\"},{\"path\":\"golang.org/x/sync\",\"version\":\"v0.0.0-20201020160332-67f06af15bc9\",\"sum\":\"h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=\"},{\"path\":\"golang.org/x/tools\",\"version\":\"v0.0.0-20201230224654-641242d23425\",\"sum\":\"h1:CknW2gSa6nckpH6mEnvpj26GNhhqKvoru1gHJ2CgPWU=\"},{\"path\":\"golang.org/x/xerrors\",\"version\":\"v0.0.0-20200804184101-5ec99f83aff1\",\"sum\":\"h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=\"},{\"path\":\"honnef.co/go/tools\",\"version\":\"v0.0.1-2020.1.6\",\"sum\":\"h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc=\"},{\"path\":\"mvdan.cc/gofumpt\",\"version\":\"v0.0.0-20200927160801-5bfeb2e70dd6\",\"sum\":\"h1:z+/YqapuV7VZPvBb3GYmuEJbA88M3PFUxaHilHYVCpQ=\"},{\"path\":\"mvdan.cc/xurls/v2\",\"version\":\"v2.2.0\",\"sum\":\"h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=\"}]}"))
          :id 1)
[client-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "initialized" :params #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8125 data
                                                            ()))
[client-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
          (:textDocument
           (:uri "file:///Users/shmul/PROJECTDIR/cmd/ox/ox.go" :version 0 :languageId "go" :text "SOURCE-DOE")))
[client-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params
          (:settings nil))
[server-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 4 :message "Loading packages..."))
[server-request] (id:1) Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///Users/shmul/PROJECTDIR/" :section "gopls")])
          :id 1)
[client-reply] (id:1) ERROR Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :id 1 :error
          (:code -32603 :message "Internal error"))
[server-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 3 :message "Error loading packages: failed to get workspace configuration from client (file:///Users/shmul/PROJECTDIR/): Internal error"))
[server-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 1 :message "Error loading workspace folders (expected 1, got 0)\nfailed to load view for file:///Users/shmul/PROJECTDIR/: failed to get workspace configuration from client (file:///Users/shmul/PROJECTDIR/): Internal error\n"))
[server-notification] Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "window/showMessage" :params
          (:type 4 :message "Loading packages..."))
[server-request] (id:2) Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///Users/shmul/PROJECTDIR/cmd/ox" :section "gopls")])
          :id 2)
[client-reply] (id:2) ERROR Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :id 2 :error
          (:code -32603 :message "Internal error"))

@joaotavora
Copy link
Owner

Eglot is still failing to reply to this server request. I'll have to check this:

[server-request] (id:1) Sat Jan  9 19:24:37 2021:
(:jsonrpc "2.0" :method "workspace/configuration" :params
          (:items
           [(:scopeUri "file:///Users/shmul/PROJECTDIR/" :section "gopls")])
          :id 1)
[client-reply] (id:1) ERROR Sat Jan  9 19:24:37 2021:

@jarreds
Copy link

jarreds commented May 18, 2022

Seeing another different type of failed request to the server w/ gopls:

[server-request] (id:15) Wed May 18 13:11:50 2022:
(:jsonrpc "2.0" :method "client/registerCapability" :params
          (:registrations
           [(:id "workspace/didChangeWatchedFiles-1" :method "workspace/didChangeWatchedFiles" :registerOptions
                 (:watchers
                  [(:globPattern "{/Users/user/src/github.com/acme/services,/Users/user/src/github.com/acme/core/services/widget,/Users/acme/src/github.com/acme/core/services/widget/test}" :kind 7)
                   (:globPattern "**/*.{go,mod,sum,work}" :kind 7)]))])
          :id 15)
[client-reply] (id:15) ERROR Wed May 18 13:11:50 2022:
(:jsonrpc "2.0" :id 15 :error
          (:code -32603 :message "Internal error"))

Eglot version 20220509.1904

@bcmills
Copy link

bcmills commented Aug 19, 2022

I'm running into what I think is the same problem, but manifesting as a deadlock instead of an error, using gopls v0.9.4 and eglot built from source at HEAD (commit 000b7fd).

The specific pathology seems to be:

  • eglot sends an initialize request to gopls.
  • gopls sends its initialize response.
  • eglot sends an initialized notification to gopls.
  • Concurrently:
    • gopls sends a window/showMessage notification, followed by a workspace/configuration request.
    • eglot sends a series of notifications (textDocument/didOpen and workspace/didChangeConfiguration), followed by a textDocument/documentSymbol request for the initially-focused file.

At that point, it appears that gopls is blocked awaiting on the workspace/configuration reply from eglot, but eglot has not read or acknowledged the workspace/configuration message — the message doesn't even appear in the output of M-x eglot-events-buffer!

@bcmills
Copy link

bcmills commented Aug 19, 2022

Attached are the raw JSON bytes read and written by gopls and the corresponding M-x eglot-events-buffer output.
Some things to note:

  • eglot has not responded to request 1 from gopls.
    • In fact, the message isn't recorded in eglot-events-buffer at all.
  • gopls has not responded to requests 2, 3, 4, or 5 from eglot.
    • eglot-events-buffer records timed-out events for requests 3, 4, and 5, but (curiously!) not for request 2. 🤔

1635-gopls-in.json.txt
1635-gopls-out.json.txt
1635-eglot-events-buffer.txt

@bcmills
Copy link

bcmills commented Aug 19, 2022

To be clear: I think that both eglot and gopls are behaving incorrectly here. (gopls is incorrectly blocking its response to the documentSymbol request, and eglot is incorrectly failing to process the configuration request due to its own outstanding request.)

I've filed the corresponding gopls bug as golang/go#54559.

@bcmills
Copy link

bcmills commented Aug 19, 2022

In the interim, I have worked around the bug in a local patch by disabling support for the workspace/configuration feature:

From f1bc2aca99daaa0ebd23a557f6bfac81fcb33cc9 Mon Sep 17 00:00:00 2001
From: "Bryan C. Mills" <[email protected]>
Date: Fri, 19 Aug 2022 17:25:42 -0400
Subject: [PATCH] Work around #587: Disable workspace/configuration support to
 avoid a gopls deadlock

---
 eglot.el | 1 -
 1 file changed, 1 deletion(-)

diff --git a/eglot.el b/eglot.el
index 14e7980..c3eda1d 100644
--- a/eglot.el
+++ b/eglot.el
@@ -676,7 +676,6 @@ treated as in `eglot-dbind'."
                         `(:dynamicRegistration
                           ,(if (eglot--trampish-p s) :json-false t))
                         :symbol `(:dynamicRegistration :json-false)
-                        :configuration t
                         :workspaceFolders t)
             :textDocument
             (list
-- 
2.36.1.838.g23b219f8e3

@sirn
Copy link

sirn commented Oct 7, 2022

I'm running into the same (or similar?) issue as @bcmills. gopls was waiting for a workspace/configuration reply, but workspace/configuration did not appear in eglot event log at all.

I have a reduced configuration at https://gist.github.com/sirn/510fbd9c15c0f85533fdbb62569200c8

In my case, it worked under gopls v0.9.4 but started failing in gopls v0.9.5, and only when Emacs is running in GUI mode under macOS (both Mitsuharu's EmacsMac.app and mainline Emacs.app). gopls+eglot started working correctly again once I run eglot-reconnect.

I initially thought this was a regression with gopls, so I run git bisect, but that led to an even a weirder rabbit hole. I've write up a summary of my findings on the gopls side at https://gist.github.com/sirn/3e37bd4a22d8d30751a139bfd405e4e3 (I've attached two eglot-events-buffer result there as well).

@stapelberg
Copy link

I have lost many hours to this problem, today, too.

The triggering condition for me was editing nftables_test.go (a rather large file) from https://github.com/google/nftables (revision google/nftables@1aef2ba, to be specific).

@bcmills Thanks for your patch, the workaround makes the problem go away on my machine, too.

@sirn How interesting that you went down a similar rabbit hole as I did. For me, go install from a git working copy of https://github.com/golang/tools at gopls/v0.10.1 was broken, but using nix-shell -p gopls, which also contains v0.10.1, was working! Both are built with go 1.19.3 and contain the exact same versions of module dependencies. Very confusing.

I tried git bisect like you did, and also ended up at commit golang/tools@cd31eaa as the culprit. I don’t know what exactly changes when one imports the vulncheck package, but it does seem to trigger the problem.

I tried instead using go:embed to embed the same number of bytes into the binary as gets added when importing the vulncheck package, but that does not trigger the problem.

I also tried instead adding func init() { time.Sleep(1*time.Second) } to reproduce the modified init order/timing, but that does not trigger the problem.

So given the weird bisection results, but also the weird system-vs-nix behavior, I’m thinking it’s not the code change itself, but something else about the binary that just happens to be triggered by a code change.


I uploaded my eglot logs (broken/working) at https://gist.github.com/stapelberg/7ea441dc5bdef1a795cdd7bcb5b5b4cb in case that’s helpful. In the working log, the workspace/configuration request happens before eglot gets a chance to send textDocument/didOpen.

@the42
Copy link

the42 commented Dec 12, 2022

I think am suffering of this same bug, reported as https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59883

The most proper "workaround" is to have a rather small go-file in the workspace, which imports none or only a handful of small core packages. If that file is opened first, gopls probably responds quickly enough not to fall into the deadlock. Opening larger files afterwards will use a then properly initialized gopls.

@stapelberg
Copy link

There is some more investigation by the gopls maintainers in golang/go#54559 (comment), saying that it’s tricky to do something about this bug on the gopls side, and a better/easier fix would be on the eglot side.

Any chance we can fix this in eglot?

@joaotavora
Copy link
Owner

joaotavora commented Dec 14, 2022

Any chance we can fix this in eglot?

Sure, as long as you specify exactly what you want me to fix. This issue has become the bucket for anything anyone doesn't find works OK with Eglot + gopls. There seem to be at three different things reported here.

Reading your linked comment is a bit surreal. Parts of it make sense, but others are odd. Eglot doesn't request semanticTokens for one.

@stapelberg
Copy link

Sure, as long as you specify exactly what you want me to fix.

Is #587 (comment) not specific enough? Which extra information would you like me to gather?

@joaotavora
Copy link
Owner

joaotavora commented Dec 14, 2022

No @stapelberg it is not. It is a hint that something is not working for you. It's fine to give these hints, but if there is something to fix and you want me to put in hours of my effort to do it, then you (or someone else) have to put in some work to make a reproducible error recipe. Something that guarantees that, given enough hours of installing language servers and setting up stuff, I will be able to witness the error in my machine, in front of me. Without this guarantee, I will generally not start to work on a "fix", unless I'm pretty confident I see the problem already. And I don't.

So please read https://joaotavora.github.io/eglot/#Troubleshooting-Eglot and DO NOT skip any steps.

I've also commented in the Gopls issue.

@stapelberg
Copy link

Okay, I’ll try and follow the troubleshooting page over the coming days.

@joaotavora
Copy link
Owner

To be clear: I think that both eglot and gopls are behaving incorrectly here. (gopls is incorrectly blocking its response to the documentSymbol request, and eglot is incorrectly failing to process the configuration request due to its own outstanding request.)

I've filed the corresponding gopls bug as golang/go#54559.

Over at that bug I have reproduced the reported problem, which seems to be one of the problems reported here. I provided a provisional fix there, for those very eager to try it out. The problem, according to my analysis, is not on the gopls side, but on the Emacs/Eglot side. I will file an emacs bug report soon for that specific identified problem.

@joaotavora
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants