Golevka / emacs-clang-complete-async

An emacs plugin to complete C and C++ code using libclang
360 stars 71 forks source link

Incremental completion not working #38

Open elemakil opened 11 years ago

elemakil commented 11 years ago

Hi, I've setup emacs-clang-complete-async and it is working nicely with some annoyances, see this issue and of course the one I'm opening right now.

Consider this snippet:

    #include <vector>
    int main(){
        std::vector<int> var;
        var.|
    }

where | symbolises point. When I start completion all the member functions of std::vector show up, however, if I type a (for restricting the completions to all functions starting with a), the completion menu is empty (it vanishes).

Edit: I just wanted to state that I know about using C-s for narrowing the list of completion candidates, however, it would be more consistent if ac-clang could complete a function in any situation, meaning even after the first letters of a function name are already typed.

My config is (I omitted the require statements and everything that is not related to configuring it for c-mode):

    ;; ac common settings
    (setq ac-quick-help-delay 0.5)
    (setq ac-auto-start 4) ;; so it starts after the firth letter
    (setq ac-auto-show-menu 1)
    (setq ac-menu-height 10)
    (setq ac-ignore-case nil)
    (setq ac-use-menu-map t)
    (global-auto-complete-mode t)
    (setq ac-dwim t)

    (defun ac-cc-mode-clang-setup ()
      (message " * calling ac-cc-mode-clang-setup")
      (setq ac-clang-complete-executable "~/.emacs.d/site-lisp/emacs-clang-complete-async/clang-complete")
      (setq ac-clang-cflags
        (mapcar (lambda (item)(concat "-I" item))
            (split-string
             "
               /usr/include/c++/4.7
               /usr/include/c++/4.7/x86_64-linux-gnu
               /usr/include/c++/4.7/backward
               /usr/lib/gcc/x86_64-linux-gnu/4.7/include
               /usr/local/include
               /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
               /usr/include/x86_64-linux-gnu
               /usr/include
               "
             )))
      (setq ac-clang-flags ac-clang-cflags)
      ;; (setq ac-sources (append '(ac-source-clang-async ac-source-yasnippet) ac-sources))
      (setq ac-sources '(ac-source-clang-async))
      (ac-clang-launch-completion-process)
      (ac-clang-update-cmdlineargs))

    (defun ac-cc-mode-clang-config ()
      (message " * calling ac-cc-mode-clang-config")
      (add-hook 'c-mode-common-hook 'ac-cc-mode-clang-setup)
      (add-hook 'auto-complete-mode-hook 'ac-common-setup))

    (ac-cc-mode-clang-config)
toojays commented 11 years ago

FWIW, I was unable to reproduce this, even using just your config with some small adjustments to have the correct packages on my system.

When I follow your reproduction steps, once I press 'a', the menu changes to only have "assign" and "at" in it.

I was using: GNU Emacs 24.3.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) of 2013-05-25 on gkar, modified by Debian auto-complete 20130503.201 installed via melpa emacs-clang-complete-async 5eb63c8 (a.k.a v0.5) libclang installed via the llvm snapshots for Debian, version 1:3.4~svn182715-1~exp1

I also tried the above but with the auto-complete-el 1.3.1-2 installed via Debian's packages, rather than the bleeding edge melpa version. It still works fine.

hoknamahn commented 11 years ago

I have the same problem. It does't auto complete this

#include <vec

But it does suggest vector when I type

std::vec

And even gives a hint

vector<typename _Tp{#, typename _Alloc#}>

But doesn't give the members of vector class. llvm I'm using is version 3.4svn and clang is 3.4 (trunk 182865). .emacs related to auto-complete[-async] is below. Any hints on troubleshooting it? I really want to make it work.

;; Turn on auto completion
(add-to-list 'load-path "~/.emacs.d/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/ac-dict")
(ac-config-default)

;; Turn on auto-complete-clang-async
(add-to-list 'load-path "~/.emacs.d/auto-complete-clang-async")
(require 'auto-complete-clang-async)
(setq clang-completion-suppress-error 't)

(defun ac-cc-mode-setup ()
  (setq ac-clang-complete-executable "~/.emacs.d/auto-complete-clang-async/clang-complete")
  (setq ac-clang-cflags
    (mapcar (lambda (item)(concat "-I" item))
            (split-string
              "/usr/include/c++/4.4.6
               /usr/include/c++/4.4.6/x86_64-redhat-linux/.
               /usr/include/c++/4.4.6/backward
               /usr/lib/gcc/x86_64-linux-gnu/4.4.6/include
               /usr/local/include
               /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include
               /usr/include
               /opt/sidefx/hfs-12.5.316/toolkit/include")))
  (setq ac-sources '(ac-source-clang-async))
  (ac-clang-launch-completion-process)
)

(defun my-ac-config ()
   (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
   (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
   (add-hook 'auto-complete-mode-hook 'ac-common-setup)
   (global-auto-complete-mode t))

(my-ac-config)
toojays commented 11 years ago

Any hints on troubleshooting it? I really want to make it work.

One tip is to try starting emacs with the -q argument, so it doesn't load your init file. Then use M-x load-file to have emacs load just the code you have shown here. That's a way to rule out any bad interaction with other parts of your emacs config. You will probably need to add (require 'yasnippet) and enable yas-minor-mode as well.

It does't auto complete this

include <vec

I don't expect that to be auto-completed by emacs-clang-complete-async. But completion of method names does work for me.

But it does suggest vector when I type

std::vec

And even gives a hint

vector<typename _Tp{#, typename _Alloc#}>

But doesn't give the members of vector class.

I don't find this particularly clear. At the point you describe, showing the class members doesn't make sense, because you don't have object yet.

hoknamahn commented 11 years ago

I don't expect that to be auto-completed by emacs-clang-complete-async

Okay. Any idea how it is done in many videos on Youtube? Is it some sort of an additional dictionary for auto-complete?

I don't find this particularly clear. At the point you describe, showing the class members doesn't make sense, because you don't have object yet.

Sorry for not being clear. The code supposed to be like this

std::vector<int> vec;
vec.push

But now I see what I was doing wrong. I was testing the auto completion not inside of the function body so the code itself was incorrect! I didn't take into account that code has to be correct in order to make auto completion work. It works fine inside of main() or any other function which is awesome. But there is another question. Is it possible to configure auto completion in the way it completes not to something like

blah.push_back(const value_type &__x);

But rather to:

blah.push_back();

?

toojays commented 11 years ago

But there is another question. Is it possible to configure auto completion in the way it completes not to something like

blah.push_back(const value_type &__x);

But rather to:

blah.push_back();

?

Do you have the yasnippet package enabled and yas-minor-mode enabled?

For me, after I type vec.pu, I can see the suggestion for push_back. If I press TAB, then I can choose between the two overloads. At this point, if I press RET, it completes vec.push_back(const value_type &__x), but selects the text between parentheses. This part is called "snippet expansion" and is done via yasnippet. I start typing to write the argument I want to pass, and the const value_type &__x bit is replaced with what I type. When the method has multiple arguments, TAB can be used to move to the next argument.

Does this explanation of how things work help you get the behaviour you want? I had a similar problem when I first started using this package, but I think it was because I didn't originally have yasnippet enabled properly.

hoknamahn commented 11 years ago

Do you have the yasnippet package enabled

I had it previously but commented it out for testing purposes. Now with enabled yasnippet it's working exactly as you described. Awesome. Thanks a lot and sorry for dumb questions. The whole emacs thingie is new to me.

toojays commented 11 years ago

Thanks a lot and sorry for dumb questions. The whole emacs thingie is new to me.

No problem. I've been using emacs for a while but have only got this auto-completion stuff setup in the last few weeks. It's got some rough edges but is very cool once you get it working.

elemakil commented 11 years ago

I'm sorry I've hadn't had time to look further into this after posting the issue.

It seems that you're right @toojays , incremental completion works. However, there are problems if you have other ac-sources such as ac-source-files-in-current-dir or ac-source-words-in-same-mode-buffers enabled. In that case the other sources kind of "overtake" the completion menu.

Consider this case: You have a number of object types which start with the same letters, for example something like TH1F, TH2F, TH3F ... And you have already created object of that type in the current file/buffers of the same major mode. You have the aforementioned sources enabled and type TH. In this case the non-clang sources take over and let you complete TH to the above types and you lose the ability to use clang (both for incremental as well as for normal completion).

I'd say that one should disable any additional ac-sources because they screw with the completion list. Can you think of a fix for this?