this post was submitted on 29 Nov 2023
0 points (50.0% liked)

Emacs

305 readers
3 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

Hi guys, sometimes I try something new to compare with already used packages, this weekend I wanted to try Eglot, however, I ran into a number of problems. One of them is autocomplete.

For example, when I write in vue, I want to autocomplete a watch function. This function is available in the following packages

import { watch } from 'vue';
import { watch } from 'fs';
import { watch } from 'fs/promises'
... etc

But when I use autocomplete in eglot I only see the first candidate - importing from the fs package. Is there any possibility or workaround to display all possible candidates?

Example of autocomplete with eglot

https://preview.redd.it/tlgtg5imw43c1.jpg?width=2930&format=pjpg&auto=webp&s=7f0cd2ff1b6733ec26021b77b6e5e392f26921df

Example of autocomplete with lsp-mode

https://preview.redd.it/rcntp2vow43c1.jpg?width=1224&format=pjpg&auto=webp&s=a246d790c47b4d48a3fba5e5f1cb361841eccc02

​

I also know that lsp-mode in conjunction with corfu has a similar problem, but it is impossible to solve it there as the authors of both packages think that the problem is not on their side πŸ˜… Is the situation with eglot the same?

top 10 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 9 months ago (1 children)

I don't know how that would even work. How do you differentiate between the funcions? Do you do fs.watch, vue.watch and so on? If so, maybe try doing fs.? Shouldn't it popup then?

[–] [email protected] 1 points 9 months ago

This implies that I need to know each module and the exact path to it. I would like to be able to see where potential candidates are placed.

[–] [email protected] 1 points 9 months ago (1 children)

As long as the completions have the same annotation (the text in green) and same kind (the icon on the left), they are deduplicated.

Looks like perhaps lsp-mode generates annotations that are more useful for your scenario than the ones that eglot does. If that is the case (and not, maybe, that you have configured lsp-mode/eglot to use different language servers), I suggest filing an issue. This shouldn't take too much time to change.

[–] [email protected] 1 points 9 months ago (2 children)

/u/hvis Would you consider changing this, since this way of deduplication in the frontend is quite inefficient? Given that the default completion UI demands that candidates are unique with respect to equal and even deletes equal duplicates, the backend should better produce unique candidates.

Deduplicating in the backend is not difficult, all that is needed is adding a suffix like (1), (2), (3), ... In fact, this is what I am doing in my Consult package, which also is a backend and provides completion tables. For example for the consult-line command I was facing the same issue, that candidates must be unique with respect to equal and not to eq.

cc /u/JDRiverRun

[–] [email protected] 1 points 9 months ago (3 children)

I’d also worry that an eq test is a bit fragile, and could go mysteriously wrong if any step in the chain decided down the road to copy or duplicate the string.

[–] [email protected] 1 points 9 months ago

Something like that would be generally easy to see very soon (completion popup without both icons and annotations). This approach has worked for years for both Emacs's default UI and company-mode, so it's hard to call it fragile.

I suppose it might have been a cause for investigation for some backend authors at some point, but backends would generally avoid internal copying anyway, for performance reasons if nothing else.

[–] [email protected] 1 points 9 months ago

It is not only fragile, it is also wrong, since the default completion UI even deletes duplicate candidates.

[–] [email protected] 1 points 9 months ago (1 children)

Actually, I forgot how this works in most cases X-D.

And it happens through text properties, which backends add to their completion strings. Then the annotation and kind operations look them up.

[–] [email protected] 1 points 9 months ago

Makes sense. I thought in the past the default completion system stripped out text properties? But I dimly recall that situation changed recently (v29?).

[–] [email protected] 1 points 9 months ago

Would you consider changing this, since this way of deduplication in the frontend is quite inefficient?

I simply consider it part of the requirements (see the other message). And there has been some effort made to ensure that the annotation/kind functions are only called when equal strings are encountered.

Indeed, when the list is long deduplication does show up on the graph, but the impact also depends on the shape of the data, and there probably are some untapped code optimizations still.

Deduplicating in the backend is not difficult, all that is needed is adding a suffix like (1), (2), (3), ...

I'm not sure this is very easy (e.g. for LSP clients), and in general it would require a scan across all completions of comparable complexity. Also, showing method overloads with suffixes like 1/2/3 would look rather odd, I think.