castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.87k stars 154 forks source link

No diagnostics? #709

Closed vinn2010 closed 4 months ago

vinn2010 commented 4 months ago

I saw the issue here #655. This person uses eglot, solargraph and flymake.

I use the same stack. I also have no diagnostics.

I have a global config file here: ~/.config/solargraph/config.yml as instructed from this issue #197.

As the person in #655 stated, the online demo also doesn't show diagnostics.

How do we turn diagnostics on?

The lsp is running. In my config I have:

(use-package eglot
  :ensure t
  :config
  (with-eval-after-load 'eglot
        (setq completion-category-defaults nil)
        (add-to-list 'eglot-server-programs
                     '((c-mode c++-mode)
                       . ("clangd"
                          "-j=4"
                          "--malloc-trim"
                          "--log=error"
                          "--background-index"
                          "--clang-tidy"
                          "--cross-file-rename"
                          "--completion-style=detailed"
                          "--pch-storage=memory"
                          "--header-insertion=never"
                          "--header-insertion-decorators=0")))
        (add-to-list 'eglot-server-programs
                     '((php-mode web-mode)
                       . ("intelephense" "--stdio")))
        (add-to-list 'eglot-server-programs
                     '((ruby-mode)
                       . ("solargraph" "stdio")))
        ))

This works. I get documentation popups as expected.

Just no diagnostics. As a point of reference, all other languages get correct diagnostics through eglot. So I am confident that that is not the issue.

Environment

Solargraph version: 0.50.0 RuboCop version: 1.60.2 Emacs version: 28.2 OS: Debian 12 - Bookworm Ruby: 3.1.2

Mate2xo commented 4 months ago

Hi, I know nothing about emacs or eglot, but I had a similar problem in a neovim distro.

You might need to configure it explicitely to show diagnostics, I hear it's off by default on some cases. Available LSP options are https://github.com/castwide/vscode-solargraph?tab=readme-ov-file#extension-settings (which apparently can be found here https://emacs-lsp.github.io/lsp-mode/page/lsp-solargraph/#lsp-solargraph-diagnostics if that maps to anything on your config)

Also I would suggest to check how your PATH and GEM_PATH are used/configured. For example, I would have diagnostics on a custom config, but not on a default neovim distro config, because by default on these distro the solargraph package was installed to and called from a directory specific to that distro.

For example, on the custom config, solargraph would be called from my project folder home/projects/my_project But the distro default went to a place like home/.local/share/lvim/mason/packages/bin (the mason here is the distro's package manager)

So one problem I had for example is that since I use the solargraph-reek plugin, and since it's not managed by mason, solargraph would exit.

So yeah just check from actually where solargraph is called in your config, so that you know what config is given to solargraph

castwide commented 4 months ago

@Mate2xo is almost certainly on the right track. Diagnostics are disabled by default and need to be enabled in LSP options. I plan to change the default in the next release.

Related: https://github.com/castwide/solargraph/issues/703

vinn2010 commented 4 months ago

I understand. How do I switch it on? I am not 100% sure yet if eglot is reading the global config file. But assuming it is, what is the correct way to switch diagnostics on?

castwide commented 4 months ago

I'm not familiar with eglot, but in general terms, you need to modify the server's initializationOptions to set "diagnostics": true.

Possibly helpful: https://joaotavora.github.io/eglot/#index-initializationOptions

vinn2010 commented 4 months ago

Okay, I got this working. Thank you both.

The correct steps are:

  1. put the rubocop config in ~/.rubocop

  2. Add a global config for solargraph in ~/.config/solargraph/config.yml

In this file, add rubocop under reporters:

reporters:
- rubocop  # diagnostics
  1. Inside emails, within the eglot install, add solargraph with diagnostics set to t.
(use-package eglot
  :ensure t
  :config
  (with-eval-after-load 'eglot
          (add-to-list 'eglot-server-programs
                     '((ruby-mode)
                       . ("solargraph" "stdio" :initializationOptions
                          (:diagnostics t))))
           ))

If you tell me where, I can add this (plus more context) to the docs? @castwide

castwide commented 4 months ago

Glad you got it working. This is specific to the client implementation, so it might be better to document it somewhere in the eglot project. However, it's probably not strictly necessary, as diagnostics will be enabled by default in the next gem release.

vinn2010 commented 4 months ago

Fair point. Thanks for the help.