gagbo / consult-lsp

LSP-mode and consult.el helping each other
MIT License
95 stars 11 forks source link

no modes enabled when a file is previewed upon calling `consult-lsp-diagnostics` #32

Open dppascual opened 1 year ago

dppascual commented 1 year ago

Bug description

I found out an odd behaviour and I don't know if it is expected or, on the other case, it should be categorized as a bug.

When running consult-lsp-diagnostics, it shows all errors reported by the lsp server; moving down between such errors, a preview of the file is loaded and the cursor is focused on the error. These preview doest not load any mode, neither column numbers, so flycheck starts checking with other checkers (like gofmt, etc) instead of lsp (which is normal because the lsp-mode is not actived yet); it causes the icon of the flycheck in the modeline reports a different number of errors when previewed than loaded.

Example

An example that clarifies better the above explanation. When calling consult-lsp-diagnostics and selecting a file that has not been loaded previously, flycheck starts running during the preview of such file and reports no errors (it can be seen in the modeline) because one of the linters has failed.

Screenshot 2022-08-24 at 17 50 50

Once the same file is loaded into a buffer, flycheck runs again but this time, the checker is lsp because the mode lsp has been enabled. Now, flycheck reports errors.

Screenshot 2022-08-24 at 17 51 04

The preview should either activate lsp or avoid activating any other packages (e. g. flycheck), shouldn't it? If possible both options, I would prefer to enable modes when a file is previewed instead of avoiding activating other packages.

Also, I found that the errors reported by consult-lsp-diagnostics and lsp-treemacs-error-list are not equal. The first one reports 71 errors and the second one 123 errors. Shouldn't they bring from lsp the same value?

Screenshot 2022-08-24 at 18 21 16 Screenshot 2022-08-24 at 18 35 50 Screenshot 2022-08-24 at 18 21 05
gagbo commented 1 year ago

Hello,

Thanks for the effort in the report :)

I didn't thoroughly checked the preview code in consult, but it will also probably depend on whether lsp-mode is hooked to the major-mode hooks of the file you are previewing, the core issue is a little too vague as is.

(I think I had some issues with lsp-treemacs showing duplicate categories like that as well, but never bothered to look into it yet, I'll try to at some point.)

flycheck is probably always active because you probably activated the global minor mode, whereas lsp-mode might not be hooked everywhere in the same way, unsure though it depends a lot on your buffer hooks and your config

dppascual commented 1 year ago

Thanks for your reply. I've reviewed the doc from consult repo and just found a function to enable modes during a preview. Another way to solve the problem is turning off global flycheck mode.

What do you mean with some issues with lsp-treemacs? Does the problem comes from this repo https://github.com/emacs-lsp/lsp-treemacs?

gagbo commented 1 year ago

What do you mean with some issues with lsp-treemacs? Does the problem comes from this repo https://github.com/emacs-lsp/lsp-treemacs?

I meant that you should probably not have main.go twice in the lsp-treemacs window

gagbo commented 1 year ago

I didn't forget (completely) about this, it's just that to fix that I'd need to go deep in consult inner workings again and I need to find a large enough "deep work" span to do this. I'll try to make preview work correctly