d-language-server / dls

A Language Server implementation for D
http://dls.dub.pm
106 stars 15 forks source link

Emacs/Vim: server doesn't update text changes #22

Closed BorisCarvajal closed 5 years ago

BorisCarvajal commented 5 years ago

First thanks for this awesome tool!

I'm using emacs with lsp-mode. For example, if I create a file:

void main() {
    int[] v;
}

then add a line: v. and try code completion. I get this error from server (set lsp-print-io variable to get client/server messages):

{
  "error": {
    "code": -32602,
    "data": "dls.protocol.errors.InvalidParamsException@protocol/source/dls/protocol/errors.d(27): Invalid parameters: invalid position: file:///tmp/d/hello.d 2,6\n----------------\n??:? [0x7493c0]\n??:? [0x75238a]\n??:? [0x73a30d]\n??:? [0x4e6e70]\n??:? [0x413109]\n??:? [0x48ddea]\n??:? [0x46105e]\n??:? [0x460b6a]\n??:? [0x733201]",
    "message": "Invalid parameters"
  },
  "id": 118,
  "jsonrpc": "2.0"
}

but if I save the file to disk right at that point and try again it works, completion for alignof, dup, idup, length, etc. appears. Now editing and trying completion again:

    int[] v;
    v.dup;
    v.

same error. Looking at the logs there are indeed some "textDocument/didChange" messages with my edits but the server just sees the file as it is on disk. I also tried Vim with the recommended config but the same behavior happens.

LaurentTreguier commented 5 years ago

Found the source of the problem: lsp-mode (and neovim-languageclient when opening a single file) don't set a language id when sending requests to open files. DLS internally only keeps contents of files with a language id of d or D, which is why it doesn't save any changes afterwards and only uses the on-disk files. I'll simply lift the language id requirement, it's no big deal to be saving the contents of a few non D files.

EDIT: it seems that language clients usually only send document opening request for files that the server can handle anyway, for example lsp-mode and vscode-language-client only notify DLS about D files.