Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP completions only affect first selection in multiple selection #2016

Closed
aral opened this issue Apr 8, 2022 · 11 comments · Fixed by #4496
Closed

LSP completions only affect first selection in multiple selection #2016

aral opened this issue Apr 8, 2022 · 11 comments · Fixed by #4496
Labels
A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@aral
Copy link
Contributor

aral commented Apr 8, 2022

Summary

If you have multiple selections, language completion only affects the first one.

Reproduction Steps

Create a simple JS file and ensure JS LSP is installed.

const be

console.log('to', foo, 'or not to', foo)
  1. g3g (goto line 3)
  2. x (select line)
  3. s + foo return (select both foo instances)
  4. c (change)
  5. b ctrl x (autocomplete: select “be” constant – note: tab doesn’t seem to work with a two-letter autocompletion. Note: behaviour is the same if you use tab with a longer completion.)

What should happen

Both foo instances should autocomplete to be:

const be

console.log('to', be, 'or not to', be)

What actually happens

Only the first foo autocompletes to be:

const be

console.log('to', be, 'or not to', b)

Helix log

n/a

Platform

Linux (elementary OS 6; based on Ubuntu)

Terminal Emulator

io.elementary.t

Helix Version

helix 22.05-dev (2d4f94e)

@aral aral added the C-bug Category: This is a bug label Apr 8, 2022
@kirawi kirawi added the A-language-server Area: Language server client label Apr 16, 2022
@ghost
Copy link

ghost commented May 11, 2022

I've had this exact same issue right now coding with Go.

@aral
Copy link
Contributor Author

aral commented May 20, 2022

@crdpa I just ran into it again myself. This is something that you can easily find yourself wanting to do quite often. It’s one of those things that I realise has made me quite tense when using Helix with multiple selections as I’m not entirely sure when it’s going to garble what I’m doing (the other is the auto completion of quotes not acting intelligently #2400) :)

@the-mikedavis
Copy link
Member

@aral would you mind moving the workaround from the FAQ to this issue? I think that workaround fits better on this issue than the faq

@aral
Copy link
Contributor Author

aral commented May 25, 2022

@the-mikedavis Sure. I just thought it might help folks if it was more visible as it’s such a common thing.

@aral
Copy link
Contributor Author

aral commented May 25, 2022

Use LSP autocomplete with multiple selections (temporary workaround)

Until the bug with LSP autocomplete with multiple selections is fixed, you can use this workaround:

import assert from 'assert'
import test from 'tape'

test ('stuff', t => {
  assert(x)
  assert(y)
  assert(z)
})

To move from basic asserts to tape’s asserts:

  1. Select and start changing the first assert wc and start typing t.tr tab and select true from the list to auto-complete.

  2. Select the completed text (t.true) (alt to select previous adjacent sibling) and yank it (y)

  3. Select the lines with the two remaining assert statements using x and select the asserts using s assert

  4. Replace the selected text with the yanked text (R) to get:

import assert from 'assert'
import test from 'tape'

test ('stuff', t => {
  t.true(x)
  t.true(y)
  t.true(z)
})

Once the bug is fixed you will simply be able to select all three asserts and replace them all using auto-complete.

@aral
Copy link
Contributor Author

aral commented May 25, 2022

PS. Above copy/pasted from the Wiki which uses asciidoc. Not sure why when markdown is used everywhere else. Don’t have time to look into converting it now.

@the-mikedavis
Copy link
Member

Yeah we should probably convert the faq to markdown at some point to be consistent. I'll give the comment an edit and see if I can fix the display

@mtoohey31
Copy link
Contributor

I've made an attempt at fixing this here: https://github.com/mtoohey31/helix/tree/feat/multi-selection-autocomplete. It seems to work, but I'm pretty sure I've made some unsafe assuptions about what the different offsets might be, so I don't think it's ready for a PR yet. Maybe someone who's more familiar with this code can use my attempt as a starting point.

@gf3
Copy link

gf3 commented Sep 26, 2022

just in case it's helpful here's an asciinema of the issue → https://asciinema.org/a/523860

@Jasha10
Copy link

Jasha10 commented Dec 11, 2022

The FAQ says "Note: If you use LSP autocomplete, only the first match will be auto-completed. If you want to auto-complete all matches, you currently have to use this workaround." Now that this issue is closed, can the FAQ can be updated?

@the-mikedavis
Copy link
Member

Yep, I just pushed a change to remove that note 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants