helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.78k stars 2.51k forks source link

LSP Quickfix line #5466

Open linde12 opened 1 year ago

linde12 commented 1 year ago

Hi!

I'm trying out Helix and thought it'd be nice with a quickfix code action. Currently there is code_action but itd be nice to have something like a code_action_quickfix_line which would retrieve quickfixes, for the current line, from the LSP and apply the topmost (being sorted by quickfix and is_preferred i think) fix.

I frequently use this for imports among other things. E.g. in nvim, with the coc-nvim plugin, i sometimes get wild and start typing something like let a = fn_not_imported_yet(); without actually triggering auto-complete and importing it. Afterwards i usually do ,af which i have bound to code action autofix. This imports the function as expected without any popup. I can also keep the cursor anywhere on the same line, and it will work, which is nice because i dont have to navigate the cursor to fn_not_imported_yet

Both with Helix and nvims built-in LSP i have to: 1) navigate to the word, in this case fn_not_imported_yet 2) space+a and then press enter

Another example is in a React application (typescript) i could type something like this:

const App = () => {
  const [count, setCount] = useState(0)
}

After this, i would simply move my cursor up one line (so it is on line 2) and type the quickfix command to automatically add import { useState } from 'react' above the first line.

pascalkuthe commented 1 year ago

The code action menu already shows quickfizes and prefferes items first.

This usecase seems a bit nieche to include in core. I think you can already create a keybdining by

I haven't tried this so I don't know if it actually works.

gabydd commented 1 year ago

I think you would need the macro keybindings for this cause the <ret> wouldn't work

linde12 commented 1 year ago

The code action menu already shows quickfizes and prefferes items first.

This usecase seems a bit nieche to include in core. I think you can already create a keybdining by

  • goto next definition
  • open code action menu
  • enter
  • jump back I believe you could create a keymao for this as follows ["goto_next_diag", "code_action", "<ret>","jump_backward"].

I haven't tried this so I don't know if it actually works.

I think the suggestion with goto_next_diag is something else. I dont necessarily want to go to the next diagnostic - the error in question might be before the cursor but on the same line. I just want to quickfix the current line.

I don't know if i would call in a niche. This is a UX thing that coc-nvim got right.

The editor already knows, and shows me, whats wrong with the line (e.g. useState not being imported) but in order to fix it i have to navigate not only to the line but the actual word, toggle completion and choose the action resulting in way more keystrokes than necessary. Might sound like a petty thing, but when you're importing things from different modules all the time it quickly adds up and this feature will save you tons of time in the long run.