ale icon indicating copy to clipboard operation
ale copied to clipboard

Add support for sending ALE's output to Neovim's diagnostics API

Open dbalatero opened this issue 3 years ago • 24 comments

Hi @w0rp,

Here is a PR for the changes we discussed in #4005.

Changes

  • g:ale_send_to_neovim_diagnostics = 0 | 1 as a configuration option
  • When g:ale_send_to_neovim_diagnostics is enabled, we send ALE output to Neovim diagnostics
  • A version check for Neovim 0.6+. We print an error if the config is set to 1 and the user is on an unsupported Vim version
  • Documentation

TODOs

  • [ ] Fix off by 1 issue reported by @daliusd below
  • [ ] Maybe good idea to add a test test_linting_sets_signs.vader or test_sign_placement.vader that tests ALE signs are disabled when neovim diagnostics are enabled.
  • [ ] Also maybe add a test to test_cursor_warnings.vader that tests cursor messages is not echoed when neovim diagnostics are enabled.
  • [ ] Figure out if it's OK to disable loclist/quickfix like we do currently
  • [ ] Fix issue with g:ale_virtualtext_cursor reported below

Screenshots

Error on startup if you're not running Neovim 0.6+ image

ALE in the diagnostics API image

ALE in trouble.nvim's fix list image

Testing

dbalatero avatar Apr 01 '22 19:04 dbalatero

Here's an example of ALE now unified with nvim-lsp's diagnostics (in this case Sorbet) inside of trouble.nvim:

image

image

dbalatero avatar Apr 01 '22 19:04 dbalatero

@bluz71 Since you were the original requester for this, would you be down to test this branch out on your end as well, and see if this config works for you?

dbalatero avatar Apr 02 '22 13:04 dbalatero

Cool stuff :) I actually never used ALE before, and started with nvim's LSP and diagnostics. But some old plugins still not supporting nvim's diagnostics, but do support ALE. And I was missing some diagnostic's features, like virtual text (partially support with ale_virtualtext_cursor, but not exactly what I was used to).

So I decide to switch to your branch :)

Here is first thing that jumps into my eyesight:

image

Duplication happens if ale_virtualtext_cursor is on.

ajukraine avatar Apr 03 '22 14:04 ajukraine

I think it behaves like because of auto command

https://github.com/dense-analysis/ale/blob/d3df00b89803f1891a772c47fc8eda6a1e9e1baa/autoload/ale/events.vim#L142-L148

ajukraine avatar Apr 03 '22 14:04 ajukraine

@ajukraine Is this because diagnostics and ALE are both using virtualtext?

Is the right solution simply to call this out in the docs as something you might want to disable with g:ale_virtualtext_cursor = 0?

dbalatero avatar Apr 03 '22 15:04 dbalatero

@dbalatero yes, they both use virtual text.

But the problem is even a bit deeper. your current implementation takes care only of ale#engine#SetResults part of the logic. However virtual text feature is also used in events.vim. Which means that after your change the behaviour is not consistent. It also applies to "echo cursor" functionality.

So I think there at least 3 ways of moving forward:

  • Let ALE's users decide whether to disable ALE's virtual text functionality or not; Is OK for power users, but will be confusing for beginners
  • Make the current change consistent and follow the same logic everywhere around ALE's code base (from what I can see it should be at least repeated in events.vim; maybe somewhere else, needs to be investigated)
  • Make the current change consistent, but move the logic into deeper levels of code base (virtualtext.vim and cursor.vim)

ajukraine avatar Apr 03 '22 16:04 ajukraine

So I think there at least 3 ways of moving forward:

Makes sense! I think I'd defer to @w0rp for preferences here, but I'm happy to follow any of these paths!

dbalatero avatar Apr 03 '22 16:04 dbalatero

@bluz71 Since you were the original requester for this, would you be down to test this branch out on your end as well, and see if this config works for you?

Apologies, I am not in a position to test this since I did switch over to null-ls about 4 or so months back.

Thankfully there are other testers available.

Cheers.

bluz71 avatar Apr 04 '22 08:04 bluz71

Thanks for this PR!! This is a killer feature for me.

I am still using ALE due to these reasons for phpcs and phpstan. I was maintaining a whole separate UI for ALE errors in virtual text, floating windows, sign column, tabs, keymaps, etc. With your PR I can get rid of all that hacky code.

Hopefully I can eventually switch these last few tools over to null-ls too, but not until these problems are fixed.

mikedfunk avatar Apr 17 '22 01:04 mikedfunk

@w0rp any feedback so far on this PR? I can address any items that jump out to you. Also curious about your thoughts on @ajukraine's comments!

dbalatero avatar Apr 17 '22 03:04 dbalatero

Actually on further testing it seems that the cursor echo and virtual text are still enabled even with neovim diagnostics enabled:

image

The red "E" and virtual text I believe are rendered by neovim diagnostics. The virtual text and echo at the bottom of the screenshot are rendered by ALE.

I do not use neovim diagnostics but from this screenshot I belive it handles "Signs" and "Virtual Text"? If this is the case then I would only disable those two in ALE and leave everything else untouched (e.g. echo cursor, loclist/quicklist, highlights, etc).

hsanson avatar May 01 '22 12:05 hsanson

I have tried this and it is great. Please rebase from master as master has important fixes.

daliusd avatar May 02 '22 10:05 daliusd

@hsanson Thanks for looking at the PR! Would it be possible to add Neovim 0.6+ to the test matrix in CI? If so I could rebase this branch on top of that change and add more tests in that specifically use the new 0.6 APIs that this PR is based off of.

dbalatero avatar May 02 '22 15:05 dbalatero

I'm sure this is good. I'll have a look through soon when I can.

w0rp avatar May 02 '22 15:05 w0rp

@daliusd I have rebased this branch on master again, so it should be up to date as of now.

dbalatero avatar May 02 '22 20:05 dbalatero

Thanks @w0rp. Curious what your thoughts are about the issue reported by @ajukraine!

dbalatero avatar May 02 '22 20:05 dbalatero

@hsanson Thanks for looking at the PR! Would it be possible to add Neovim 0.6+ to the test matrix in CI? If so I could rebase this branch on top of that change and add more tests in that specifically use the new 0.6 APIs that this PR is based off of.

Latest master already tests againt neovim 0.6.1 and this new branch #4180 that needs review tests against 0.7.

hsanson avatar May 03 '22 01:05 hsanson

@dbalatero So it's easy to understand, what I try to do with the tests is run them in CI with:

  1. The oldest Vim version supported.
  2. The oldest NeoVim version supported.
  3. The latest Vim version.
  4. The latest NeoVim version.

I try not to ever drop support for any versions at will, but instead very carefully. I'm waiting for the day when NeoVim hits 1.0. I actually won't use NeoVim myself until it does. I have become... a 30 year old boomer. I run extremely bog standard Linux software these days and rarely use anything that isn't completely stable. I'm just very conscious of how I spend my time these days. :smiley:

w0rp avatar May 07 '22 04:05 w0rp

Thanks for the review @w0rp! Appreciate the approval but it sounds like there are changes I need to make, so you might want to just mark it as Pending changes/comments until I've addressed everything.

dbalatero avatar May 08 '22 02:05 dbalatero

@bluz71 Since you were the original requester for this, would you be down to test this branch out on your end as well, and see if this config works for you?

@dbalatero,

I have had time to have a look at this impressive work.

Well done; especially since I am mulling switching back to ALE from null-ls (due to some quirks of null-ls).

Though I have encountered a bug with with the mdl Markdown linter and this PR.

My rough ALE + Neovim diagnostics setup:

local g = vim.g

g.ale_linters = {
  markdown = {'mdl'},
}

g.ale_completion_enabled = 0
g.ale_echo_cursor = 0
g.ale_hover_cursor = 0
g.ale_lint_on_enter = 0
g.ale_lint_on_filetype_changed = 0
g.ale_lint_on_insert_leave = 0
g.ale_lint_on_save = 1
g.ale_lint_on_text_changed = 'never'
g.ale_linters_explicit = 1
g.ale_send_to_neovim_diagnostics = 1

local map = vim.keymap.set
map("n", "]d", "<cmd>lua vim.diagnostic.goto_next()<CR>")
map("n", "[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>")

Load up a Markdown files such as this one and delete the black line at line 3, this should now produce a lint warning (correctly).

Now hit ]d to go to the next warning. That produces this failure for me:

failure

I am using Neovim 0.7.0 (official release).

My quick testing with Standard Ruby and Standard JS linters (via this PR) does not produce the same issue.

So linter specific.

bluz71 avatar May 14 '22 08:05 bluz71

@dbalatero hey, how are you doing? I am using your branch for a month and its awesome. Do you need helping hand with fixing minor issues?

daliusd avatar Jun 14 '22 17:06 daliusd

This pull request has been automatically marked as stale because it has not been updated recently. Make sure to write tests and document your changes. See :help ale-dev for information on writing tests. If your pull request is good to merge, bother w0rp or another maintainer again, and get them to merge it.

stale[bot] avatar Aug 10 '22 04:08 stale[bot]

☹️

mikedfunk avatar Sep 20 '22 23:09 mikedfunk

Can this be re-opened?

bluz71 avatar Sep 21 '22 02:09 bluz71

@daliusd I'm still interested in getting this merged. Sorry to everyone for not being around. If you can make the adjustments I left in my review back in May, we can merge this into master. There wasn't all that much I wanted to change. I just haven't had the time to adjust it myself and test it in NeoVim. You might have a better idea as a regular NeoVim user. (I'm still using Vim until I am pretty sure NeoVim is tagged as 1.0.0 and there's a semi-official GUI client.)

w0rp avatar Oct 19 '22 16:10 w0rp

@daliusd I'm still interested in getting this merged. Sorry to everyone for not being around. If you can make the adjustments I left in my review back in May, we can merge this into master. There wasn't all that much I wanted to change. I just haven't had the time to adjust it myself and test it in NeoVim. You might have a better idea as a regular NeoVim user. (I'm still using Vim until I am pretty sure NeoVim is tagged as 1.0.0 and there's a semi-official GUI client.)

@w0rp sorry, I have migrated to null-ls.nvim. I can't help with this.

daliusd avatar Oct 24 '22 05:10 daliusd

I'll try and take this over…I'm interested in it enough at least.

mathstuf avatar Oct 28 '22 12:10 mathstuf

See #4345 for my resurrection of this PR. Thanks for the base @daliusd!

mathstuf avatar Oct 28 '22 14:10 mathstuf

Hey @mathstuf thanks for taking this over–life took over on my end and I lost the bandwidth to get this one done. Should I close this PR in lieu of yours?

dbalatero avatar Oct 28 '22 16:10 dbalatero

Yeah, I think that'd be fine. I wish there was a way to get those Cc'd here Cc'd on a superceding issue/PR, but that's a long-standing feature request from my end here anyways :) .

mathstuf avatar Oct 28 '22 17:10 mathstuf