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

Make sure completion-metadata is fetched when formatting candidates #2875

Merged
merged 2 commits into from Jun 2, 2021

Conversation

gexplorer
Copy link
Contributor

@gexplorer gexplorer commented May 20, 2021

This PR refactors the fetching of completion-metadata closer to it's usage to prevent the formatting of candidates without the expected metadata.

The problem

The minibuffer metadata was being stored in a variable ivy--minibuffer-metadata used by ivy--format. The ivy--format is called from two places:

  • ivy-update-candidates
  • ivy--update-minibuffer

But the value of ivy--minibuffer-metadata was only being set in ivy-update-candidates.

The bonus

I've been using ivy with this change for a few hours and as far as I can see it's now is compatible with marginalia.

Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've been using ivy with this change for a few hours and as far as I can see it's now is compatible with marginalia.

@minad comments?

Does this address #2780?

ivy.el Outdated Show resolved Hide resolved
@minad
Copy link

minad commented May 21, 2021

@minad comments? Does this address #2780?

I have not checked. @gexplorer In #2780 I listed multiple things which didn't work with Marginalia. Are all of these issues fixed?

@gexplorer
Copy link
Contributor Author

I don't think all the problems get solved. The commands I use the most do work out of the box: find-file, switch-buffer, describe-variable, describe-function.

On the other hand describe-face does not set the category right, but it can easily be solved adding it to the symbol-category config in marginalia. Once added it gets recognized by marginalia but I think that counsel's formatter messes with marginalia and some colors are lost in translation. I think it has something to do with the comment about overriding faces. This is probably because some of counsel's format functions are not overlapping with marginalia. It would be nice being able to opt out that formatting and lettong marginalia do its job if desired.

@gexplorer
Copy link
Contributor Author

I tried all the commands with custom format functions and I found out that the ones with problems are:

  • counsel-colors-web
  • counsel-colors-emacs
  • counsel-faces

I managed to get them working properly:

  • counsel-faces with default formatter:

With counsel format

  • counsel-faces with marginalia

With marginalia

The only change needed for this to work is how ivy-completions-annotations face is applied. In order to prevent overriding annotations faces it should be appended. In ivy--format-minibuffer-line:

(add-face-text-property
       olen (length str) 'ivy-completions-annotations t str) 

* ivy.el (ivy--minibuffer-metadata): Remove.  All callers changed.
(ivy--format-minibuffer-line, ivy--wnd-cands-to-str): Arrange for
ivy--format-minibuffer-line to take annotation-function as
argument (PR abo-abo#2875).

Re: abo-abo#2780.
* ivy.el (ivy--format-minibuffer-line): Append
ivy-completions-annotations face (PR abo-abo#2875).
Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@basil-conto basil-conto merged commit 040d458 into abo-abo:master Jun 2, 2021
basil-conto added a commit that referenced this pull request Jul 22, 2021
Other parts of Ivy, specifically ivy--wnd-cands-to-str, use
ivy-state-dynamic-collection to differentiate between programmed
completion functions and Ivy's dynamic collections.  By disabling
ivy-state-dynamic-collection in ivy-restrict-to-matches, we lose
this ability.  This leads to errors when collections are mishandled.

* ivy.el (ivy-restrict-to-matches): When disabling
ivy-state-dynamic-collection, also make sure that
minibuffer-completion-table no longer holds a dynamic collection.

Re: #2875.
Fixes #2893.
basil-conto added a commit that referenced this pull request Feb 14, 2024
* ivy.el (ivy--format-minibuffer-line): Accept result of either
affixation-function or annotation-function.  Don't add
ivy-completions-annotations face to an annotation with an existing
face, as per the documentation of annotation-function (#2875).
(ivy--metadata-get): New function.
(ivy--wnd-cands-to-str): Use it.  Let affixation-function override
annotation-function.  Remove read-only property from candidates
instead of setting it to (or adding it as) nil (#28).

Fixes #2732.
@basil-conto
Copy link
Collaborator

I tried improving how we handle the ivy-completions-annotations face in commit 12803ed, if you'd care to take a look/test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants