lexical-lsp / lexical

Lexical is a next-generation elixir language server
885 stars 82 forks source link

Empty "publishDiagnostics" follows every diagnostic #782

Open fschuindt opened 4 months ago

fschuindt commented 4 months ago

I'm noticing that if I introduce an error to the code, the error will quickly flash in red (indicating an error), but right after it will go back to normal, as if the error was removed. Upon investigating, it seems that the LSP server is sending two publishDiagnostics notifications, one followed by the other.

The first one contains the message about the error introduced in the diagnostics, the second one will contain the diagnostics as an empty list.

Here is the log:

[client-notification] Sat Jun 29 17:35:14 2024:
(:jsonrpc "2.0" :method "workspace/didChangeWatchedFiles" :params
  (:changes
    [(:uri "file:///home/fschuindt/apps/mine/testing_elixir_lsp/testing_lsp/lib/.%23testing_lsp.ex" :type 3)]))
[stderr] warning: variable "this_is_not_valid" does not exist and is being expanded to "this_is_not_valid()", please use parentheses to remove the ambiguity or change the variable name
[stderr]   lib/testing_lsp.ex:18: TestingLSP.hello/0
[stderr] 
[server-notification] Sat Jun 29 17:35:14 2024:
(:jsonrpc "2.0" :method "$/progress" :params
  (:token 386 :value
    (:kind "end")))
[server-notification] Sat Jun 29 17:35:14 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
  (:diagnostics
    [(:message "** (CompileError) lib/testing_lsp.ex:18: undefined function this_is_not_valid/0 (expected TestingLSP to define such a function or for it to be imported, but none are available)\n\n" :range
       (:end
     (:character 0 :line 18)
     :start
     (:character 4 :line 17))
       :severity 1 :source "Elixir")]
    :uri "file:///home/fschuindt/apps/mine/testing_elixir_lsp/testing_lsp/lib/testing_lsp.ex" :version nil))
[server-notification] Sat Jun 29 17:35:15 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
  (:diagnostics
    []
    :uri "file:///home/fschuindt/apps/mine/testing_elixir_lsp/testing_lsp/lib/testing_lsp.ex" :version nil))

Highlight for that part:

[server-notification] Sat Jun 29 17:35:15 2024:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
  (:diagnostics
    []
    :uri "file:///home/fschuindt/apps/mine/testing_elixir_lsp/testing_lsp/lib/testing_lsp.ex" :version nil))

:point_up: This will instruct Flymake to remove the error highlight from my editor buffer.

TBH I'm not sure if this is considered a bug on Lexical's side. Probably there's an Eglot/Flymake configuration somewhere, but I'm wondering what you folks think about it. Any tips?

The relevant part of my init.el:

(straight-use-package 'elixir-mode)

(use-package treesit
  :init
  (setq treesit-language-source-alist
        '((bash "https://github.com/tree-sitter/tree-sitter-bash")
          (cmake "https://github.com/uyha/tree-sitter-cmake")
          (css "https://github.com/tree-sitter/tree-sitter-css")
          (elisp "https://github.com/Wilfred/tree-sitter-elisp")
          (elixir "https://github.com/elixir-lang/tree-sitter-elixir")
          (go "https://github.com/tree-sitter/tree-sitter-go")
          (heex "https://github.com/phoenixframework/tree-sitter-heex")
          (html "https://github.com/tree-sitter/tree-sitter-html")
          (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
          (json "https://github.com/tree-sitter/tree-sitter-json")
          (make "https://github.com/alemuller/tree-sitter-make")
          (markdown "https://github.com/ikatyang/tree-sitter-markdown")
          (python "https://github.com/tree-sitter/tree-sitter-python")
          (toml "https://github.com/tree-sitter/tree-sitter-toml")
          (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
          (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
          (yaml "https://github.com/ikatyang/tree-sitter-yaml")))
  :config
  (setq major-mode-remap-alist
        '((bash-mode . bash-ts-mode)
          (elixir-mode . elixir-ts-mode))))

(use-package eglot
  :ensure nil
  :config
  (add-to-list
    'eglot-server-programs `((elixir-ts-mode heex-ts-mode elixir-mode) . ("start_lexical.sh"))))

(use-package elixir-ts-mode
 :straight t
  :hook ((elixir-ts-mode . eglot-ensure)
        (before-save . eglot-format)))

(use-package sideline-flymake
  :straight t
  :hook (flymake-mode . sideline-mode)
  :init
  (setq sideline-flymake-display-mode 'point)
  (setq sideline-backends-right '(sideline-flymake)))

(setq eglot-events-buffer-size 1000000)  ; Increase buffer size for logs
(setq eglot-ignored-server-capabilites nil)  ; Don't ignore any server capabilities

Thank you!

fschuindt commented 3 months ago

Apparently, everything works normal if I don't use treesit and elixir-ts-mode. If I just use elixir-mode, everything behaves as expected.

scohen commented 3 months ago

@fschuindt that's incredibly strange. Should we get the author of elixir-ts-mode in on this? I talk to him on slack a bit.

fschuindt commented 3 months ago

@scohen indeed. I have opened an issue on the project: https://github.com/wkirschbaum/elixir-ts-mode/issues/49