EasyClangComplete icon indicating copy to clipboard operation
EasyClangComplete copied to clipboard

[Bug] Completions loaded from cache after file save.

Open jerrykal opened this issue 9 years ago • 37 comments

I have this problem since I installed EasyClangComplete. Here's an example:

problem

the weird thing is that after change test to ::test the completion is work very well

weird

jerrykal avatar Mar 20 '17 05:03 jerrykal

Ok, I know the reason. It should be easy to fix too. We cache the completions in a specific position of the document. We just need to invalidate this cache on file save.

niosus avatar Mar 20 '17 07:03 niosus

To make sure you understand my problem, here's Xcode version of my first gif: 2017-03-20 21_15_36

jerrykal avatar Mar 20 '17 13:03 jerrykal

Yep, I totally understand the issue. I hope I will have the time to fix this during this week. It should not be too hard.

niosus avatar Mar 20 '17 13:03 niosus

Ugh. It appeared to be harder than I expected. I have changed what I assumed was the error, but it seems that in case of the completion being triggered by " " or in case of "autocomplete_all": true libclang does not do a proper job at completing.

I invalidate the cache on file save just to be sure, but libclang generates the completions with old function nevertheless. The strange part is that it generates correct completions if I trigger them with "." or "->".

I have no idea why this happens for now... :confused:

UPD: I think I will have to put it in the backlog for now. Fixing something that is wrong inside of libclang is definitely out of score for me for now. :(

niosus avatar Mar 20 '17 22:03 niosus

The only way I see to fix this is to invalidate the whole translation unit, forcing it to be parsed as opposed to being reparsed only. The problem with this is that it takes twice the time and as it only happens when there is no trigger before the input, I would just leave this as it is now.

niosus avatar Mar 20 '17 22:03 niosus

So the problem fixed??

jerrykal avatar Mar 21 '17 00:03 jerrykal

Nope. Unfortunetely not. But it is unfixable at this point as it comes from libclang itself and not from the plugin.

niosus avatar Mar 21 '17 00:03 niosus

But why some IDE like Xcode doesn't have this problem ?

jerrykal avatar Mar 21 '17 00:03 jerrykal

I don't really know. I should probably keep this issue open though.

What I am sure of is that the completions come from libclang itself. Just the way they do when I complete with a dot, but they don't get updated properly.

niosus avatar Mar 21 '17 00:03 niosus

Seems autocomplete-clang from atom doesn't have this problem, maybe you should take a look.

2017-03-21 09_11_23

jerrykal avatar Mar 21 '17 01:03 jerrykal

I have an idea, maybe you can just add an command to tell ECC check every function, if have any function modified, then reload the completion of that function.

jerrykal avatar Mar 21 '17 08:03 jerrykal

Or reload all completion when file save.

jerrykal avatar Mar 21 '17 08:03 jerrykal

I will look into the atom's plugin, thanks for reference. As for your suggestions that is essentially what I thought. I thought, that we skip interfacing with libclang at all when this happens, so I thought that reloading all completions would help. It doesn't as it is libclang that gives us the wrong completions. I have one more idea on what we can do, but I don't expect too much as it should work as it is.

niosus avatar Mar 21 '17 09:03 niosus

The plugin you refer to in Atom does not use libclang. It uses clang and parses the output from it. The bug seems to be related to the upstream of libclang. I will try to create a minimal example to submit a bug report there. There is really nothing else I can do now.

There is a workaround I can suggest - add a quick panel action to hard clean the translation unit. This can take some time if your code is heavy on headers and will take roughly twice the time needed for a reparse of the translation unit on save. Would you need this functionality?

niosus avatar Mar 21 '17 09:03 niosus

Yes.

jerrykal avatar Mar 21 '17 09:03 jerrykal

Ok, will happen soon.

niosus avatar Mar 21 '17 10:03 niosus

So It could be twice slower, right?

jerrykal avatar Mar 21 '17 10:03 jerrykal

I will add an option that will be callable through Ctrl+Shift+P called smth like "Hard Reparse". It will essentially delete current translation unit and will recreate it. This way you will get the proper completions when completing after a space. It will take twice the time of an ordinary reparse that is currently done on file save.

niosus avatar Mar 21 '17 10:03 niosus

Okay, I get it.

jerrykal avatar Mar 21 '17 10:03 jerrykal

Here's more example:

EasyClangComplete:

2017-03-21 22_47_28 2017-03-21 22_47_03 2017-03-21 22_45_53

In the case, completion all work well when file saved, but it should be work well without file saving.

Xcode:

2017-03-21 22_57_33 2017-03-21 22_57_26 2017-03-21 22_57_19

jerrykal avatar Mar 21 '17 14:03 jerrykal