A Question regarding the use of clang API for IDE

Hi,

I’m developing an IDE which uses clang API (clang-c/Index.h). Eventually I intend to implement
Syntax highlighting, indentation, diagnostics and code completion. So clang is just perfect.

My 2 questions are :

Its seems that in the API, the only option is clang_parseTranslationUnit/clang_reparseTranslationUnit.
The thing is, that those functions receive as a parameter either a file name on a disk or a file name
in memory in a form of const char* pointer and length. The open file in my IDE is not stored in that
straightforward way in the memory (or I guess any other text editor) so is there a way to feed the parser from a byte stream of any sort?

The second question is: Currently I try to implement syntax highlighting, which means that
for every press of a key (pretty much) in the editor I need to re parse and tokenize the entire file, so that I’ll get the updated information on how and what to highlight. While clang performs those action
quite fast, and for diagnostics and code completion this totally acceptable, I do feel that its a bit of an overkill for syntax lighting where simple (and maybe partial or incremental) tokinizing of an input
buffer would be sufficient.
Is there something I’m missing? Are t there are other clang methods that I can use ?

Thank you very much,
Yossi.

Are you aware of
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-June/022028.html ?

(As far as I know it is still at the design/discussion stage.)

Dave.

Hi Yossi,

Hi,

I’m developing an IDE which uses clang API (clang-c/Index.h). Eventually I intend to implement
Syntax highlighting, indentation, diagnostics and code completion. So clang is just perfect.

My 2 questions are :

Its seems that in the API, the only option is clang_parseTranslationUnit/clang_reparseTranslationUnit.
The thing is, that those functions receive as a parameter either a file name on a disk or a file name
in memory in a form of const char* pointer and length. The open file in my IDE is not stored in that
straightforward way in the memory (or I guess any other text editor) so is there a way to feed the parser from a byte stream of any sort?

Not sure what you mean, you’d like to supply a buffer with any text encoding ?

The second question is: Currently I try to implement syntax highlighting, which means that
for every press of a key (pretty much) in the editor I need to re parse and tokenize the entire file, so that I’ll get the updated information on how and what to highlight. While clang performs those action
quite fast, and for diagnostics and code completion this totally acceptable, I do feel that its a bit of an overkill for syntax lighting where simple (and maybe partial or incremental) tokinizing of an input
buffer would be sufficient.

Is there something I’m missing? Are t there are other clang methods that I can use ?

Reparsing is currently a requirement; for tokenizing you can specify a source range as well.

Hi,

I’m developing an IDE which uses clang API (clang-c/Index.h). Eventually I intend to implement
Syntax highlighting, indentation, diagnostics and code completion. So clang is just perfect.

My 2 questions are :

Its seems that in the API, the only option is clang_parseTranslationUnit/clang_reparseTranslationUnit.
The thing is, that those functions receive as a parameter either a file name on a disk or a file name
in memory in a form of const char* pointer and length. The open file in my IDE is not stored in that
straightforward way in the memory (or I guess any other text editor) so is there a way to feed the parser from a byte stream of any sort?

No, there isn’t. You’ll need to copy your data into a const char* buffer to use libclang.

The second question is: Currently I try to implement syntax highlighting, which means that
for every press of a key (pretty much) in the editor I need to re parse and tokenize the entire file, so that I’ll get the updated information on how and what to highlight. While clang performs those action
quite fast, and for diagnostics and code completion this totally acceptable, I do feel that its a bit of an overkill for syntax lighting where simple (and maybe partial or incremental) tokinizing of an input
buffer would be sufficient.
Is there something I’m missing? Are t there are other clang methods that I can use ?

There aren’t any other libclang methods to use. Generally, we suggest that you implement a bit more logic on the client side to avoid calling clang_reparseTranslationUnit that often. For example, wait until the user has typed enter/return or some closing character like }, ), or ].

  • Doug