9fans / acme-lsp

Language Server Protocol tools for the acme text editor
MIT License
195 stars 25 forks source link

Always insert first suggestion in L comp -e #56

Closed farhaven closed 1 year ago

farhaven commented 1 year ago

When using L comp -e, if there is more than one match for the pattern under the cursor, the matches are printed out. It'd be nice to have the first match inserted and selected so that it can be easily removed again.

I'd find this useful especially for Go code using generated protobuf packages, because those often have multiple matches for patterns where the first match is almost always the right thing since the generated code contains a GetFoo function for every field Foo, so that running L comp -e on

x := foo.bar|

(with | being the cursor position)

yields suggestions like

Something.Bar string
GetSomething().Bar string

Does this make sense? If so, I think I can prepare a PR.

fhs commented 1 year ago

I'm not sure how I'd like that feature turned on by default and it'd also change the current behavior which might come as a surprise to the users. Maybe it should be a new flag (-E?).

farhaven commented 1 year ago

I've submitted a PR that addresses this request, if only to have some actual code to talk about. I've done what you suggested: kept the old -e behaviour (almost) as it is at the moment (except that the "no completion" text is now also printed to stdout instead of stderr, it was just a bit easier to juggle text output this way), and a new flag -E triggers this new kind of completion.