elixir-ts-mode icon indicating copy to clipboard operation
elixir-ts-mode copied to clipboard

Lexical, Eglot and Flymake will clean up every LSP diagnostic right after the report when using elixir-ts-mode

Open fschuindt opened this issue 7 months ago • 0 comments

Hello there,

I spent some time struggling to make elixir-ts-mode to work with Lexical, Eglot and Flymake. It was everything working, the only problem was that every LSP report would happen just "as a flash". Meaning, it would be displayed on the buffer, but less than 200ms afterward it would get removed.

Investigating, I discovered that the reason was that Lexical was sending an empty publishDiagnostics after every diagnostic. That empty diagnostic was being interpreted as "no issues to be reported", and any previous diagnostic was being cleaned.

That was the configuration I had:

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

However, I just discovered that if I remove the treesit support, and replace elixir-ts-mode by elixir-mode alone, it would work. The following configuration works fine:

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

(use-package eglot
  :ensure nil
  :config
  (add-to-list
    'eglot-server-programs `((elixir-mode heex-mode) . ("start_lexical.sh")))
  (add-hook
    'elixir-mode-hook 'eglot-ensure)
  (add-hook
    'heex-mode-hook 'eglot-ensure)
  (add-hook
    'elixir-mode-hook (lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil t))))

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

I have the gut feeling that elixir-ts-mode is compatible with ElixirLS, but might not be compatible with Lexical.

I'm not sure if this is an issue on Lexical's side, but it's a month since I don't get anything from the Lexical's team. So I decided to post it here for any tips and/or guidance.

Thanks!

fschuindt avatar Jul 27 '24 22:07 fschuindt