redguardtoo / company-ctags

Fastest Emacs auto-completion using Company and Ctags
GNU General Public License v3.0
56 stars 3 forks source link

fix: clean cache between completion sessions #6

Closed AmaiKinono closed 4 years ago

AmaiKinono commented 4 years ago

The company-ctags-cached-candidates is composed of the prefix company gives us, and the rlt, which is the candidates we hand over to company later. Since rlt is just a reference to the actual value, company can do anything it wants to the candidates, and that affects our cache.

This shows the problem:

Peek 2020-02-04 15-04

company-ctags gives me the right candidates the first time, but when I want to complete func again, it only gives me func_03. Then we printed the cache, you can see only "func_03" is left there. This is caused by company. If you insert a print statement in the end of company-ctags--candidates, you'll see it has all the candidates.

So, we have to cleanup the cache after a completion session finishes, or actually copy the candidates when building the cache. Since the main usage of the cache is limited to current completion session, I took the former approach. Please see if the implementation is reasonable.

redguardtoo commented 4 years ago

Could you give me a minimum example and exact steps to reproduce the issue?

AmaiKinono commented 4 years ago

Sure.

  1. Make sure you checkout 0.0.3 tag in this repository. I found later versions seem to break things.

  2. Put this TAGS file in an empty directory: TAGS.tar.gz

  3. emacs -Q, require company and company-ctags.

  4. Create a file in that directory, open it using this Emacs session. Make sure you are in some prog-mode. Type M-x company-mode.

  5. Type fu, then M-x company-ctags, you'll see the candidates. They are func_01, func_02 and func_03.

  6. Cancel it using C-g. Call company-ctags again, there will be only one candidate func_03. Now if you complete anything like func, func_ which starts with fu, same thing happens.

  7. Checkout my branch and do the same test, the problem is fixed.

redguardtoo commented 4 years ago

anyway, I already solved the issue in fuzzy match. It's actually just one line fix.