mattn / efm-langserver

General purpose Language Server
MIT License
1.35k stars 61 forks source link

didChange with stdin = false specifies the filename of the (potentially unsaved) file #59

Open aktau opened 4 years ago

aktau commented 4 years ago

Hi! My use case is running shellcheck(1) with efm-langserver (using the nvim-lsp client). I noticed that after I made a change to my document the returned diagnostics did not match the new content, but the old one (reference: https://github.com/nvim-lua/diagnostic-nvim/issues/40).

The reason is: nvim-lsp sends a textDocument/didChange whenever the user makes a change. This does not mean that the document is saved.

My configuration is essentially copied from the README:

# Cut down version of https://github.com/mattn/efm-langserver.
version: 2

tools:
  sh-shellcheck: &sh-shellcheck
    lint-command: 'shellcheck -f gcc -x'
    lint-formats:
      - '%f:%l:%c: %trror: %m'
      - '%f:%l:%c: %tarning: %m'
      - '%f:%l:%c: %tote: %m'

languages:
  sh:
    - <<: *sh-shellcheck

I traced the shellcheck invocation made by efm-langserver before and after the edit of a shell file:

shellcheck -f gcc -x /home/aktau/tmp/glop.sh # When opening file
shellcheck -f gcc -x /home/aktau/tmp/glop.sh # After editing, but the file isn't saved yet so this is identical to before.

Reading the code I also noticed that f.Text is only used when stdin is false. This means that I'd need to use shellcheck in stdin mode to get this to work. A couple of notes:

mattn commented 4 years ago

Okay, please send pull-request.

aktau commented 4 years ago

I'll likely only have time for something small. But also: any thoughts on the last paragraph?

mattn commented 4 years ago

There are not any meaning about that current README.md does not have lint-stdin in shellcheck section. So Iet's change it to use.