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

C-M-i: with a single candiate snippet completion doesn't work #311

Closed
nemethf opened this issue Oct 2, 2019 · 1 comment
Closed

C-M-i: with a single candiate snippet completion doesn't work #311

nemethf opened this issue Oct 2, 2019 · 1 comment

Comments

@nemethf
Copy link
Collaborator

nemethf commented Oct 2, 2019

def fun_aa(a, b): pass
def fun_bb(a, b): pass

C-M-i after fun_ pops up a Completion buffer with

Possible completions are:
fun_aa(a, b) __main__ (snippet)
fun_bb(a, b) __main__ (snippet)

and snippets work if I select one of the candidates.

However, C-M-i after fun_a inserts a(a, b) without the possibility to edit a and b with yasnippet.

Reading the protocol messages doesn't help me, but the answer in the fist case:

          (:isIncomplete :json-false :items
                         [(:insertText "fun_aa(${1:a}, ${2:b})$0" :sortText "afun_aa" :kind 3 :documentation "fun_aa(a, b)" :detail "__main__" :label "fun_aa(a, b)" :insertTextFormat 2)
                          (:insertText "fun_bb(${1:a}, ${2:b})$0" :sortText "afun_bb" :kind 3 :documentation "fun_bb(a, b)" :detail "__main__" :label "fun_bb(a, b)" :insertTextFormat 2)]))

The answer in the second case:

          (:isIncomplete :json-false :items
                         [(:insertText "fun_aa(${1:a}, ${2:b})$0" :sortText "afun_aa" :kind 3 :documentation "fun_aa(a, b)" :detail "__main__" :label "fun_aa(a, b)" :insertTextFormat 2)]))
nemethf added a commit to nemethf/eglot that referenced this issue Oct 5, 2019
The :exit-function of the completion command doesn't get called under
special circumstances.  Fix this by altering the completion candidate.

Closes joaotavora#311.

* eglot.el (eglot--tailor-completions): New function.
(eglot-completion-at-point): Use it.
@nemethf
Copy link
Collaborator Author

nemethf commented Oct 6, 2019

This is a duplicate of #279. Although it's not necessary to have textEdit in the reply as the example above shows. And the bug is triggered only when the server returns just a single completion item. But the analysis there is correct.

nemethf added a commit to nemethf/eglot that referenced this issue Oct 6, 2019
The :exit-function of the completion command doesn't get called under
special circumstances.  Fix this by altering the completion candidate.

Closes joaotavora#311.  Closes joaotavora#279.

* eglot.el (eglot--tailor-completions): New function.
(eglot-completion-at-point): Use it.
nemethf added a commit to nemethf/eglot that referenced this issue Oct 6, 2019
* eglot-tests.el (snippet-completions): New test.
joaotavora added a commit that referenced this issue Oct 12, 2019
Fixes #313, fixes #311, fixes #279

As is well known, LSP's and Emacs's completion mechanics don't fit
very well together, mostly because Emacs expects completion to be a
something of a pure function of a string argument and LSP treats as a
function of a concrete buffer position.

A further complication arises because some completion frontends like
"bare" completion-at-point make Emacs modify the buffer's contents
during the completion process, while other (notably company-mode)
don't do that.  Thus eglot-completion-at-point must take extra care
not to inadvertently garble its (quite hacky) "completions", which is
used to cache the last LSP response and retrieve much more than just
the completion text in the :exit-function callback.

In yet another related problem, :exit-function won't be called at all
with completion-at-point if the completion table doesn't answer
properly to test-completion.  completion-table-dynamic is not enough
to save us here so we must answer that 'lambda' request separately.

* eglot.el (eglot-completion-at-point): Rework.
joaotavora pushed a commit that referenced this issue Oct 12, 2019
* eglot-tests.el (snippet-completions): New test.
joaotavora pushed a commit that referenced this issue Oct 14, 2019
* eglot-tests.el (snippet-completions): New test.
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 18, 2022
Fixes joaotavora/eglot#313, fixes joaotavora/eglot#311, fixes joaotavora/eglot#279

As is well known, LSP's and Emacs's completion mechanics don't fit
very well together, mostly because Emacs expects completion to be a
something of a pure function of a string argument and LSP treats as a
function of a concrete buffer position.

A further complication arises because some completion frontends like
"bare" completion-at-point make Emacs modify the buffer's contents
during the completion process, while other (notably company-mode)
don't do that.  Thus, 'eglot-completion-at-point' must take extra care
to answer to the questions listed in the "(elisp)Programmed
Completion" info node based on its (quite hacky) "completions" local
var and _not_ based on the intermediate buffer contents.  That var is
also used to cache the last LSP response and allow the :exit-function
callback to retrieve much more than just the completion text in

In yet another related problem, :exit-function won't be called at all
with completion-at-point if the completion table doesn't answer
properly to test-completion.  A previous use of
completion-table-dynamic was found to be unsuitable here: we must
answer all the requests separately.

* eglot.el (eglot-completion-at-point): Rework.
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
Fixes joaotavora/eglot#313, fixes joaotavora/eglot#311, fixes joaotavora/eglot#279

As is well known, LSP's and Emacs's completion mechanics don't fit
very well together, mostly because Emacs expects completion to be a
something of a pure function of a string argument and LSP treats as a
function of a concrete buffer position.

A further complication arises because some completion frontends like
"bare" completion-at-point make Emacs modify the buffer's contents
during the completion process, while other (notably company-mode)
don't do that.  Thus, 'eglot-completion-at-point' must take extra care
to answer to the questions listed in the "(elisp)Programmed
Completion" info node based on its (quite hacky) "completions" local
var and _not_ based on the intermediate buffer contents.  That var is
also used to cache the last LSP response and allow the :exit-function
callback to retrieve much more than just the completion text in

In yet another related problem, :exit-function won't be called at all
with completion-at-point if the completion table doesn't answer
properly to test-completion.  A previous use of
completion-table-dynamic was found to be unsuitable here: we must
answer all the requests separately.

* eglot.el (eglot-completion-at-point): Rework.
bhankas pushed a commit to bhankas/emacs that referenced this issue Sep 19, 2022
Fixes #313, fixes #311, fixes #279

As is well known, LSP's and Emacs's completion mechanics don't fit
very well together, mostly because Emacs expects completion to be a
something of a pure function of a string argument and LSP treats as a
function of a concrete buffer position.

A further complication arises because some completion frontends like
"bare" completion-at-point make Emacs modify the buffer's contents
during the completion process, while other (notably company-mode)
don't do that.  Thus, 'eglot-completion-at-point' must take extra care
to answer to the questions listed in the "(elisp)Programmed
Completion" info node based on its (quite hacky) "completions" local
var and _not_ based on the intermediate buffer contents.  That var is
also used to cache the last LSP response and allow the :exit-function
callback to retrieve much more than just the completion text in

In yet another related problem, :exit-function won't be called at all
with completion-at-point if the completion table doesn't answer
properly to test-completion.  A previous use of
completion-table-dynamic was found to be unsuitable here: we must
answer all the requests separately.

* eglot.el (eglot-completion-at-point): Rework.

#313: joaotavora/eglot#313
#311: joaotavora/eglot#311
#279: joaotavora/eglot#279
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this issue Oct 12, 2022
Fixes joaotavora/eglot#313, fixes joaotavora/eglot#311, fixes joaotavora/eglot#279

As is well known, LSP's and Emacs's completion mechanics don't fit
very well together, mostly because Emacs expects completion to be a
something of a pure function of a string argument and LSP treats as a
function of a concrete buffer position.

A further complication arises because some completion frontends like
"bare" completion-at-point make Emacs modify the buffer's contents
during the completion process, while other (notably company-mode)
don't do that.  Thus, 'eglot-completion-at-point' must take extra care
to answer to the questions listed in the "(elisp)Programmed
Completion" info node based on its (quite hacky) "completions" local
var and _not_ based on the intermediate buffer contents.  That var is
also used to cache the last LSP response and allow the :exit-function
callback to retrieve much more than just the completion text in

In yet another related problem, :exit-function won't be called at all
with completion-at-point if the completion table doesn't answer
properly to test-completion.  A previous use of
completion-table-dynamic was found to be unsuitable here: we must
answer all the requests separately.

* eglot.el (eglot-completion-at-point): Rework.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant