Autocompletion from stdin with clang

2019-06-24 04:20发布

问题:

I have set up an environment for autocompletion in Emacs, using clang 2.8 as the parser. It works well, but relies on saving the currently edited buffer to file before completion. This is slow, so I am trying to get clang to parse a file given to it via stdin instead, without luck so far.

The command line I feed clang when parsing a file is as follows:

clang -cc1 -fsyntax-only -Iinclude/ -code-completion-at foo.cpp:10:20 foo.cpp

This works well. But attempts to read from stdin fail. I've tried this:

cat foo.cpp | clang -xc++ -cc1 -fsyntax-only -Iinclude/ -code-completion-at -:10:20 -

But that makes clang terminate without making any completions and prints the warnings:

clang: warning: argument unused during compilation: '-cc1'
clang: warning: argument unused during compilation: '-code-completion-at'
clang: warning: argument unused during compilation: '-:10:20'

Any ideas?

回答1:

Does it work if you specify -cc1 before -x c++?