Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
907 stars 99 forks source link

Updating of code completion db #364

Open lobstaj opened 7 years ago

lobstaj commented 7 years ago

Hi,

I got company-irony to work quite nicely today in a c-project using a compile_commands.json generated by bear. Thanks for the nice work.

One thing though, I find the code completion candidate list is not updated unless I re-open my c-file (might be I also need to touch compile_commands.json? Not sure about this though). This is somewhat annoying, since I'd like to have my own project's (and the same file's) functions to be suggested to me for code completion.

Is this how it is supposed to work at the moment?

If yes, is there any way to force the re-generation of that completion candidate list, so that I could e.g. add a hook to save-file?

If not, do you have any pointers on how to debug this problem?

Thanks in advance.

J

UPDATE: At this moment, I can't get the completion list to be updated by any means anymore. None of closing/re-opening file, re-entering irony-mode and company-mode seem to do the job. Only rebooting emacs does the trick.

lobstaj commented 7 years ago

Ok, I'm getting somewhere. Now that I enabled also flycheck with flycheck-irony, it does re-parse the file when I insert a new function, etc. But it's still not quite right. For example, after I insert (i.e. type character by character) the function

int test_my_f(int abc)
{
    return 1;
}

and then in another function I type test_, company-irony will suggest test_my_f -> int, but without the parameter. Only after I go back and edit the parameter (i.e. delete c) from the end and re-type it), it'll end up correctly in the completion list (test_my_f(int abc) -> int).

Is my machine just too slow or am I typing too fast? ;-)

J

Sarcasm commented 7 years ago

I can reproduce the issue when the file is not saved on disk. When I open a new buffer.

If I touch file.c before opening, I don't have the issue for example.

Is it the same for you?

lobstaj commented 7 years ago

Without flycheck, it doesn't matter if the file is saved or not. It won't update the completion data.

With flycheck, I'm not sure now. I'll test and report tomorrow when I'm back at work.

Can you reproduce the problem I have without flycheck (no updating at all) or the issue I have with flycheck (partial updating)?

Sarcasm commented 7 years ago

I would say partial updating. If I trigger some characters, such as . it seems to trigger an update somehow.

A quick try without flycheck on a buffer where I did touch file.c before opening seems to work the same as without flycheck for me.

lobstaj commented 7 years ago

For me, typing . does not make a difference. If flycheck-mode is not active, it does not seem to take the newly created function into the completion list ever. No matter whether the file already existed or not.

If flycheck-mode is active, I get those partial updates. But usually I don't get the function parameters unless I once delete the ) from the function definition and re-type ). Sometimes the parameter type is taken into the completion list immediately after typing the function, but not the parameter name.

My emacs version is 25.1.50.2, irony-mode, company-mode, and flycheck-mode all installed from melpa. I btw also have electric-pair-mode active, I assume that might affect the situation.

Do you know how updating the completion list is supposed to work? When exactly should the list of completions be updated? I guess irony does not run clang across the whole buffer for every character inserted.

Sarcasm commented 7 years ago

Oh I see, I can also some weirdness, the parameter is not always found.

This is a bug, probably in the use the the libclang API (TUManager.cpp and/or Irony.cpp).

lobstaj commented 7 years ago

Ok, good that you found a lead :-)

Do you have any hint what I could check to find out more about that first problem (no completion updates at all when flycheck-mode is not active)? Is there some debug output / emacs variables I could check to find out why it's not working for me?

This probably isn't really high priority, since I and presumably the vast majority of users are happy to use flycheck-irony at the same time.

Sarcasm commented 7 years ago

I think it may have to do with flycheck who does "reparse" operations, while completion do "codeCompleteAt".

A quick test, could be to change the line here: https://github.com/Sarcasm/irony-mode/blob/284ca00b48d8261106efc6c6ac128ebec608c86f/server/src/Irony.cpp#L205

- CXTranslationUnit tu = tuManager_.getOrCreateTU(file, flags, unsavedFiles);
+ CXTranslationUnit tu = tuManager_.parse(file, flags, unsavedFiles);

The other thing to test, is the parse tu options:

https://github.com/Sarcasm/irony-mode/blob/284ca00b48d8261106efc6c6ac128ebec608c86f/server/src/TUManager.cpp#L19

It is always a bit sensible to set one of these options (such as CXTranslationUnit_DetailedPreprocessingRecord), the kind of issue you notice is typical of these for example.

RomeuG commented 7 years ago

I do have the same problem.

When I include, imagine, the string.h header, the completion DB is not updated and functions like strlen or strcat do not appear.

Unless i have flycheck-irony, because, when I do, it updates the completion DB.