go-langserver icon indicating copy to clipboard operation
go-langserver copied to clipboard

textDocument/didOpen leads to empty file contents

Open beyang opened this issue 7 years ago • 2 comments

I'm trying out a new edition of the emacs-lsp extension (https://github.com/sourcegraph/emacs-lsp/pull/9) and am encountering a scenario where a textDocument/didOpen notification seems to lead to the Go langserver to store empty contents for a file.

Repro steps:

  • Install the version of the emacs-lsp plugin at https://github.com/sourcegraph/emacs-lsp/pull/9.
  • Run go-langserver -addr :4445 -trace -mode tcp
  • Open emacs to your local copy of github.com/gorilla/mux
  • Run M-x lsp-mode-init-conn setting host to "localhost" and port to 4445
  • Run M-x lsp-mode-symbol and issue "newrouter" as your query.
  • This yields the following trace in the LS:
--> request #991207229632190845: initialize: {"rootPath":"/home/beyang/src/github.com/gorilla/mux/"}
<-- result #991207229632190845: initialize: {"capabilities":{"textDocumentSync":1,"hoverProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"referencesProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"documentFormattingProvider":true,"xworkspaceReferencesProvider":true,"xdefinitionProvider":true,"xworkspaceSymbolByProperties":true}}
--> request #503727145293595937: textDocument/didOpen: {"textDocument":{"uri":"file:///home/beyang/src/github.com/gorilla/mux/route.go"}}
<-- result #503727145293595937: textDocument/didOpen: null
--> request #278696121372792140: workspace/symbol: {"query":"newrouter"}
<-- result #278696121372792140: workspace/symbol: []
  • Additional printfing shows the error that causes the subsequent symbol request to return the empty list is err: /home/beyang/src/github.com/gorilla/mux/route.go:1:1: expected 'package', found 'EOF'

My best guess is that it tries to relativize the textDocument/didOpen URI (file:///home/beyang/src/github.com/gorilla/mux/route.go) against the workspace rootPath (/home/beyang/src/github.com/gorilla/mux/route.go), but that yields a non-existent file like /home/beyang/src/github.com/gorilla/mux/route.go/home/beyang/src/github.com/gorilla/mux/route.go. It takes this to mean the file contents are now empty, so on the subsequent workspace/symbol request, it finds an empty file.

beyang avatar Mar 11 '17 08:03 beyang

didOpen seems to be sending an invalid notification. You are missing most of the fields as described in TextDocumentItem (notably the content of the document). The spec doesn't seem to indicate the field as optional, although in practice maybe we can make it optional? cc my favourite LSP person @felixfbecker

FYI when we are unmarshalling your TextDocumentItem, text is set as the empty string.

keegancsmith avatar Mar 13 '17 11:03 keegancsmith

The whole point of the didOpen notification is to initialise in-memory file content so it can be modified with subsequent didChange notifications. The behaviour of the Go LS seems correct here, besides that it could throw an error because of an invalid message.

felixfbecker avatar Mar 13 '17 11:03 felixfbecker