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

Weird behavior with merged backends involving company-yasnippet #485

Closed
akirakyle opened this issue Mar 11, 2016 · 8 comments
Closed

Weird behavior with merged backends involving company-yasnippet #485

akirakyle opened this issue Mar 11, 2016 · 8 comments
Labels

Comments

@akirakyle
Copy link
Contributor

I'm experiencing unexpected behavior when I have a merged backend involving company-yasnippet. The issue seems to generally happen whenever there is a special completion case where the backend merged yasnippet (call backend-x) returns (PREFIX . t) overriding company-minimum-prefix-length When this happens, if yasnippet is after backend-x, then I will see every snippet in yas-describe-tables as a possible completion. However if yasnippet is before backend-x, then I will not see any completion candidates until after company-minimum-prefix-length characters have been typed.

The specific cases in which I have experienced this is with company-ycmd and company-semantic where the special completion cases are after the triggers . or :: or -> have been typed.

@dgutov
Copy link
Member

dgutov commented Mar 11, 2016

Hi!

Is that a problem in practice? company-yasnippet is basically designed to augment other backends, so it makes sense to put it later in a group (and also put :with before it).

The prefix action of a grouped backend is implemented as the first non-nil value returned by any of the elements of the group. So if the first one returns not a cons, the whole group's completions are treated accordingly. It may be fixable, but I'd like a good reason to do that, first.

@akirakyle
Copy link
Contributor Author

Perhaps there is some way of configuring the backends that I am overlooking. The issue I'm having arrises when writing a program in c and using a struct, after typing . or -> to access a member of the struct. ycmd correctly gives me just the completion candidates which are appropriate (members of just that struct), however since I'd like to also be able to generally use yasnippets in my code, I have a merged backend with company yasnippet. The issue is that I'm shown all the yasnippet candidates when I only want to see the ycmd candidates after typing a struct operator. (I imagine similar issues are encountered in c++ but I haven't tried it yet). I currently have my backends set as the following in cc-mode:
((:sorted company-ycmd :with company-yasnippet))

@dgutov
Copy link
Member

dgutov commented Mar 15, 2016

How do you figure company-yasnippet should choose which snippets to show and when?

@akirakyle
Copy link
Contributor Author

I suppose now that I think about it, and after looking through the code a bit, this behavior does make the most sense in the context of the way grouped backends are operating. I don't think it makes sense to change the way company-yasnippet chooses its completions and responds to the prefix command. While I could fix my issue by simply making company-yasnippet return nil for . or -> prefixes, this would potentially conflict with other user's snippets. I think the functionality I was hoping for would allow each backend in a grouped backend to be queried independently for their prefix commands and subsequent completions, that way when one backend in the grouped backend wanted to begin completion early by overriding company-minimun-prefix-length the others would not be pulled along. After looking at the code for this, I see that it would not be easy to implement, and not necessarily improved behavior as there are probably equally number valid use cases where the current grouped backend completion method is better. Ideally there might be another keyword to implement this letting users have the options, but it seems with the current way the code is written, this may require more than it would be worth.

Anyways, thanks for bearing with me as I try to figure this out (I'm still a bit of a noob with lisp), but I hope the bug I came across (and hopefully fixed with #491) might make up for it :)

@dgutov
Copy link
Member

dgutov commented Mar 20, 2016

So what you wanted is to track the backends that think company-minimun-prefix-length is satisfied, and only show completions from them until the user interacts with the popup explicitly.

I don't know. It makes some kind of sense, but then, won't be user be surprised when completions from the rest of the backends show up right after she uses some completion command?

@akirakyle
Copy link
Contributor Author

Yeah that would be another aspect to having grouped backends behave this way that would make the experience less consistent, as one typically expects the candidates to be narrowed as they enter in more text, however this kind of functionality would potentially increase the number of candidates presented as more text is entered which would be counterintuitive.

Now that I think about this more, I don't see much sense in trying to implement it, and to be honest, I am fine with my current setup, that uses :sorted so that the all the yasnippet candidates appear at the bottom of the completion popup. What prompted me to want this in the first place was being surprised at having all possible yasnippet completions after company-minimun-prefix-length was overridden by company-ycmd when completing after the . and -> triggers in c. Having the default alphabetical sorting of the candidates at that time made yasnippet completely overwhelm the candidates I wanted from ycmd, but the :sorted keyword fixes that.

(I am fine with having this closed if you see nothing more that might need to be addressed)

@dgutov
Copy link
Member

dgutov commented Mar 20, 2016

Yes, the topic seems exhausted. Thanks for the discussion.

@dgutov dgutov closed this as completed Mar 20, 2016
dgutov added a commit that referenced this issue Oct 4, 2023
…eparately

This should help with
#1398,
#641,
#553,
#485,
#1147,
#840

With some of the above already closed, and some describing more serious
scenarios than others.

Anyway, this is a halfway step to dropping framework-level caching (or moving it to
backends).  For now this seems like an adequate solution, given that the most
"heavy" backend these days is `company-capf`, which disables caching already.
Though `company-dabbrev-code` is a close next.
dgutov added a commit that referenced this issue Oct 9, 2023
…eparately (#1405)

* company--multi-backend-adapter: Consider min prefix in 'candidates' separately

This should help with
#1398,
#641,
#553,
#485,
#1147,
#840

With some of the above already closed, and some describing more serious
scenarios than others.

Anyway, this is a halfway step to dropping framework-level caching (or moving it to
backends).  For now this seems like an adequate solution (resetting the cache
sometimes when the new chars are typed), given that the most "heavy" backend
these days is `company-capf`, which disables caching already.
Though `company-dabbrev-code` is a close next.

Uses new semi-private backend action called 'set-min-prefix', to keep the merging function's backward compatibility, for the sake of external callers.
@dgutov
Copy link
Member

dgutov commented Oct 9, 2023

Turns out this could be managed inside the framework.

Check out the latest master.

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

No branches or pull requests

2 participants