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

unexpected completion item list #553

Closed
netjune opened this issue Jul 13, 2016 · 13 comments
Closed

unexpected completion item list #553

netjune opened this issue Jul 13, 2016 · 13 comments
Labels

Comments

@netjune
Copy link

netjune commented Jul 13, 2016

mode: c-mode
backends: (setq company-backends '((company-clang company-dabbrev-code)))
other setting: (setq company-minimum-prefix-length 3)
version: 0.9.0 and above

  1. create a c-mode buffer
  2. yank the following code into buffer
  3. goto end of buffer(after "st"), insert the char '.' to trigger completion
  4. all symbols in the buffer is in the compeletion item list

struct st_test
{
int long_name_var1;
int long_name_var2;
};

void test()
{
struct st_test st;

st
@dgutov
Copy link
Member

dgutov commented Jul 13, 2016

What did you expect?

@netjune
Copy link
Author

netjune commented Jul 13, 2016

I expect all items in completion list be A+B.
A: all items when (setq company-backends '(company-clang)). 2
B: all items when (setq company-backends '(company-dabbrev-code)). 0
A+B=2+0=2.

But it is not. Too many items in B(I guess).

@dgutov
Copy link
Member

dgutov commented Jul 13, 2016

B: all items when (setq company-backends '(company-dabbrev-code)). 0

What does that mean? Do you get no completions with company-dabbrev-code alone? That's not what I'm seeing here.

@netjune
Copy link
Author

netjune commented Jul 13, 2016

Yes. I set company-minimum-prefix-length to 3. So after '.' there is no completions, because it is not a symbol-char.

@dgutov
Copy link
Member

dgutov commented Jul 13, 2016

OK, so your problem is that with company-dabbrev-code you get no idle compeltion after st.. And with company-clang, you do.

This is working as expected. See the description of prefix in company-backends. Also try M-x company-complete-common to see how many completions the current backend actually returns.

@netjune
Copy link
Author

netjune commented Jul 14, 2016

I think there may be something wrong.

My problem:
A. (setq company-backends '(company-clang)). The completion items are as expected (2 items).
B. (setq company-backends '(company-dabbrev-code)). The completion items are also as expected (0 items because company-minimum-prefix-length is 3).
C. (setq company-backends '((company-clang company-dabbrev-code))). The completion items are NOT as expected (A + all symbol in buffer).

A and B is right. C is not. C != A + B.

The problem seems to be that: company-minimum-prefix-length is ignored In C case.

@dgutov
Copy link
Member

dgutov commented Jul 14, 2016

Go to step B and type M-x company-complete-common. There will be completions.

@netjune
Copy link
Author

netjune commented Jul 14, 2016

In B, there should be no completions because company-minimum-prefix-length is 3.
Command company-complete-common ignores company-minimum-prefix-length?

@dgutov
Copy link
Member

dgutov commented Jul 14, 2016

Like its docstring says, company-minimum-prefix-length only affects idle completion.

To put it differently, it affects whether the completion tooltip is displayed. Not how many completions a backend returns.

@netjune
Copy link
Author

netjune commented Jul 14, 2016

I understand now.

At that point, company first checks company-clang. It passes the prefix check. So company completion starts. Then it activates all backends in the same group and gathers their candidates, without checking company-minimum-prefix-length.

But I would it to check company-minimum-prefix-length or I will need to modify company-abbrev-code and more backends like that.

@dgutov
Copy link
Member

dgutov commented Jul 14, 2016

Maybe you could manage that with only adding an advice to e.g. company--multi-backend-adapter-candidates.

I could consider this as a feature request if more people wanted it, but so far you're the first, IIRC.

@netjune
Copy link
Author

netjune commented Jul 14, 2016

OK. I will try. Thank you.

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.

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