Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty "publishDiagnostics" follows every diagnostic #782

Open
fschuindt opened this issue Jun 29, 2024 · 3 comments
Open

Empty "publishDiagnostics" follows every diagnostic #782

fschuindt opened this issue Jun 29, 2024 · 3 comments

Comments

@fschuindt
Copy link

  • Erlang 25.3.2.12
  • Elixir 1.14.3-otp-25
  • Manjaro Linux
  • Emacs 29.3
  • built-in Eglot
  • built-in Flymake

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))

☝️ 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
Copy link
Author

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
Copy link
Collaborator

scohen commented Jul 29, 2024

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants