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

Feature Request: Allow Filtering yasnippet completions when triggered by trigger sequence #840

Closed
wberrier opened this issue Nov 2, 2018 · 7 comments

Comments

@wberrier
Copy link

wberrier commented Nov 2, 2018

This seems somewhat related to #485 , but the idea is that I'm grouping company-lsp/cquery (c++) and company-yasnippet together via:

(push '(company-lsp :with company-yasnippet) company-backends)

Completing without input (prefix) shows all globals and snippets as expected.

But, when I have completions from a trigger character ('.' or '->') then all the snippets show up in the completions, which is never desired behavior in this setup.

It would be great to only show snippets in completions if completion list isn't triggered by a trigger sequence.

I've considered trying to set up company-transformers to perform this filter, and maybe that's a way to implement this? Not sure...

Thoughts?

@wberrier
Copy link
Author

wberrier commented Nov 2, 2018

Also note, using :separate as suggested in #485 does indeed help by putting all the snippets at the bottom, but I think it would be preferable if the snippets weren't in the list at all.

@dgutov
Copy link
Member

dgutov commented Nov 3, 2018

Try this:

(defun company-yasnippet-unless-member-access (command &optional arg &rest ignore)
  (if (eq command 'prefix)
      (let ((prefix (company-yasnippet 'prefix)))
        (and prefix
             (save-excursion
               (forward-char (- (length prefix)))
               (not (looking-back (rx (or "." "->")) (line-beginning-position))))
             prefix))
    (company-yasnippet command arg)))

And use this backend instead of company-yasnippet directly.

@wberrier
Copy link
Author

wberrier commented Nov 4, 2018

That works great, thanks!

Some questions:

Is there a way to automatically use all the "triggers" specified for that particular language? Seems like different languages are going to have their particular cases when it's not appropriate to show snippets...

For example, here's some additional cases for c++ where snippets probably shouldn't be shown:

  • std::
  • #include <
  • #include "

Also, is this something that would be provided with company-yasnippet (and have the lookback chars be a defcustom, or language specific alist, etc...), or should I just put it in my local config?

@dgutov
Copy link
Member

dgutov commented Nov 4, 2018

Is there a way to automatically use all the "triggers" specified for that particular language?

If there were an existing convention to specify them in language mode definitions, we could. I'm not aware of one, though.

or should I just put it in my local config?

This, at least for now. And I also think it works better as a wrapper backend, because whether we want to avoid snippets after trigger characters depends on the presence of other backends (and whether they provide snippets for completions).

@wberrier
Copy link
Author

wberrier commented Nov 6, 2018

Sounds good, and thanks, it works much better.

I'll leave it up to you whether you want to close this issue or not...

@dgutov
Copy link
Member

dgutov commented Nov 20, 2018

Let's leave it open for now.

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

Check out the latest master, the behavior should be improved.

@dgutov dgutov closed this as completed Oct 9, 2023
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

2 participants