sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.64k stars 182 forks source link

`gopls` initialized but not returning data within Sublime Text #586

Closed weelillad closed 5 years ago

weelillad commented 5 years ago

gopls server seems to be initialized properly but it is not returning any information at all from within Sublime Text. Calling from the command line works, though:

➜  tga-backend git:(1757f4e) ✗ gopls query definition /home/andy/ESTL/tga-backend/main.go:34:20
/home/andy/ESTL/tga-backend/store/db.go:12:6-20: defined here as func store.OpenConnection(host string, port string, name string, user string, password string, maxConn int, connMaxLifetime int) (*sql.DB, error)%                                                                                                       

elementaryOS Juno (built on Ubuntu 18.04 LTS)

➜  apt list sublime-text
Listing... Done
sublime-text/apt/dev,now 3208 amd64 [installed]

gopls (installed 3 May 2019)

Package Control

  1. Add config from https://github.com/tomv564/LSP/pull/561/commits/044ff5619f58f7a95d6f5a23a48d282baf2512c5 to user settings
  2. Use full path for command in above config else gopls cannot be found: "command": ["/home/andy/ESTL/go/bin/gopls"]
  3. Open a Sublime Project with Go code.
  4. Enable the gopls LSP for the project.
  5. Hover the mouse over any go function or variable name.
LSP: global configs ['phpls=False', 'gopls=True', 'cquery=False', 'javascript-typescript-langserver=False', 'jdtls=False', 'rls=False', 'eslint=False', 'typescript-language-server=False', 'reason=False', 'polymer-ide=False', 'pyls=False', 'haskell-ide-engine=False', 'ocaml=False', 'clangd=False', 'golsp=False', 'lsp-tsserver=False', 'jsts=False']
LSP: window 2 has override for gopls {'enabled': True}
LSP: window 2 starting 1 initial views
LSP: window 2 requests gopls for /home/andy/ESTL/tga-backend/main.go
LSP: starting in /home/andy/ESTL/tga-backend
LSP: starting ['/home/andy/ESTL/go/bin/gopls']
LSP:  --> initialize
LSP: window 2 added session gopls
LSP:      {'capabilities': {'typeDefinitionProvider': True, 'documentFormattingProvider': True, 'definitionProvider': True, 'completionProvider': {'triggerCharacters': ['.']}, 'hoverProvider': True, 'textDocumentSync': {'openClose': True, 'change': 1}, 'signatureHelpProvider': {'triggerCharacters': ['(', ',']}, 'codeActionProvider': True, 'documentRangeFormattingProvider': True, 'documentSymbolProvider': True, 'documentHighlightProvider': True}, 'custom': None}
LSP:  --> initialized
LSP:  --> textDocument/didOpen
LSP:  --> textDocument/hover
LSP:      None
LSP:  --> textDocument/hover
LSP:      None

Meanwhile, status bar will flash this message briefly: no file information for file:///home/andy/ESTL/tga-backend/main.go, with the open file as a URL instead of a file path.

weelillad commented 5 years ago

The LSP works if I start Sublime Text from a terminal, instead of from the dock. This clued me in that maybe it's missing some env variables, that it would inherit from the terminal but not from the dock. After a bit of trial and error, I found that adding the following to the gopls client config made the difference:

"env": {
    "GOPATH": "/home/andy/ESTL/go",
    "PATH": "/home/andy/ESTL/go/bin:/usr/local/go/bin"
}

Hope this will help anyone else who encounters similar issues.

weelillad commented 5 years ago

Dug into this further and figured out that updates to env variables in Linux should be done in ~/.profile for it to apply to desktop-launched applications. I'd put them in ~/.zshrc, which meant that Sublime Text and its plugins couldn't see them unless I launch it from a zsh terminal. :sweat:

Eventually I added the GOPATH and PATH updates to my ~/.profile, and I could use the config from #561 as it was. Took me 4 hours to get here; Googling for the symptoms provided no immediate answer. Hope this helps other poor souls who've made similar mistakes.