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

Error when using completion-preview-mode and completion-preview-complete #664

Open
verdammelt opened this issue Jan 17, 2025 · 13 comments
Open

Comments

@verdammelt
Copy link

verdammelt commented Jan 17, 2025

Minimal replication with emacs -Q (assuming sly installed at "~/.emacs/elpa/sly-20240809.2119")

Evaluate

(global-completion-preview-mode 1)
(toggle-debug-on-error)
(push "~/.emacs.d/elpa/sly-20240809.2119" load-path)
(load-library "sly")
(sly "sbcl")

Then type (form into the REPL - completion-preview-mode will show first possible match, use completion-preview-complete (bound to M-i by default) to list all completions and get the following backtrace:

Debugger entered--Lisp error: (invalid-function ("format" "formatter" "force-output"))
  ("format" "formatter" "force-output")(nil nil sly--identify)
  sly--completion-in-region-function(#<marker at 463 in *sly-mrepl for sbcl*> 466 ("format" "formatter" "force-output") nil)
  apply(sly--completion-in-region-function (#<marker at 463 in *sly-mrepl for sbcl*> 466 ("format" "formatter" "force-output") nil))
  #f(compiled-function (oldfun &rest args) #<bytecode -0x257aee4dacd0d45>)(#[128 "\301\302\300!\2\"\207" [completion-in-region-function apply default-value] 4 advice--forward] #<marker at 463 in *sly-mrepl for sbcl*> 466 ("format" "formatter" "force-output") nil)
  apply(#f(compiled-function (oldfun &rest args) #<bytecode -0x257aee4dacd0d45>) #[128 "\301\302\300!\2\"\207" [completion-in-region-function apply default-value] 4 advice--forward] (#<marker at 463 in *sly-mrepl for sbcl*> 466 ("format" "formatter" "force-output") nil))
  #f(advice #f(compiled-function (oldfun &rest args) #<bytecode -0x257aee4dacd0d45>) :around #[128 "\301\302\300!\2\"\207" [completion-in-region-function apply default-value] 4 advice--forward] ((name . sly--setup-completion)))(#<marker at 463 in *sly-mrepl for sbcl*> 466 ("format" "formatter" "force-output") nil)
  completion-in-region(#<marker at 463 in *sly-mrepl for sbcl*> 466 ("format" "formatter" "force-output") nil)
  completion-at-point()
  completion-preview-complete()
  funcall-interactively(completion-preview-complete)
  call-interactively(completion-preview-complete nil nil)
  command-execute(completion-preview-complete)

It appears that sly--completion-in-region-function expects a function as its third argument but is given a list of matches here.

What is the responsibility of this function argument? I am thinking I might at least hack together a fix with an advice...

@verdammelt
Copy link
Author

I see in the documentation to completion-at-point-functions that such functions should expect the args (START END COLLECTION . PROPS) so perhaps if sly--completion-in-region-function is meant to be such a function it needs to be changed?

@monnier
Copy link
Collaborator

monnier commented Jan 17, 2025 via email

@joaotavora
Copy link
Owner

@monnier or @aadcg feel free to apply the patch with a suitable commit message, if this is successfully tested. It seems function should be renamed collection in sly--completion-in-region-function

@aadcg
Copy link
Collaborator

aadcg commented Jan 17, 2025

@monnier since it's your patch, I'd suggest you moving forward. Let me know.

@verdammelt
Copy link
Author

I applied this change locally and it will keep things from erroring.

However won't this circumvent all the nice features of sly-symbol-completion-mode?

@joaotavora
Copy link
Owner

However won't this circumvent all the nice features of sly-symbol-completion-mode?

It might. You're the only one testing it, afaik. Can you tell us which features you suspect or observe being circumvented?

@verdammelt
Copy link
Author

I gave it a quick test:

  1. modified function does not signal error
  2. modified function results in standard completion behavior (for me that includes popping up *Completions* buffer.
  3. modified function does not produced *sly-completions* buffer which has the additional information about the the type of the symbol etc.

It seems to me that the modified function is good, as it allows for completion to work well with completion-preview-mode.

@joaotavora
Copy link
Owner

joaotavora commented Jan 20, 2025

modified function does not produced sly-completions buffer which has the additional information about the the type of the symbol etc.

This is a no-go, unless this behaviour is recovered when completion-preview-mode is turned off again.

@joaotavora
Copy link
Owner

IOW, people using SLY as they have been for many years shall not be impacted by this patch.

@verdammelt
Copy link
Author

modified function does not produced sly-completions buffer which has the additional information about the the type of the symbol etc.

This is a no-go, unless this behaviour is recovered when completion-preview-mode is turned off again.

Sorry to cause confusion. The behavior appears to be the normal *sly-completions* behavior when not using completion-preview-mode.

monnier added a commit that referenced this issue Feb 3, 2025
* lib/sly-completion.el (sly--setup-completion): Move the advice's
wrapper into `sly--completion-in-region-function`.
(sly--completion-in-region-function): Add `orig-fun` and `rest` args.
Rename `function` to `collection`.  Test `sly-symbol-completion-mode`
and make sure `collection` is a function before using it as such.
@monnier
Copy link
Collaborator

monnier commented Feb 3, 2025 via email

@aadcg
Copy link
Collaborator

aadcg commented Feb 4, 2025

@monnier why did you push to sly/master instead of master?

@monnier
Copy link
Collaborator

monnier commented Feb 4, 2025 via email

@aadcg aadcg mentioned this issue Feb 4, 2025
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

No branches or pull requests

4 participants