Work progress has been slow this week as I spent my time learning about the code completion feature in the code editor. The previous intern has done some work on it with basic functions.  However, there is much to be done until it becomes fully operable and up to my boss’ expectation.

Starting with Clang

I started with examining the clang code-completion which was implemented. It’s amazing to see how it works by returning related keywords from the C++ library.

clang -fsyntax-only  -Xclang -code-completion-brief-comments  -Xclang -code-completion-at=<cfile>:<line>:<column> <cfile> -I <headerFile>  | awk -F: '/^COMPLETION:/ {print $2}' 

‘awk’ works like a text processor and allows us to extract certain words. In the usage above, awk returns the second column from the results obtained from clang.  However, after testing it, I found out that it gave too many results, including class data, enumerators and so on.

To solve this, I used a grep to exclude and include certain patterns because I only need the object functions being shown in the code completion.

CodeMirror Show-hint

So after I managed to get a more accurate array of code hints, I moved on to the implementation part in CodeMirror. It turned out to be harder than I expected. There is only a few examples showing the autocomplete feature in CodeMirror and they differ greatly from my desired implementation. Even the autocomplete demos did not have a tutorial showing how it actually works.

To CodeMirror understand the user input, I would need to create my own javascript file that acts as a tokenizer for my library.  For now, I would be studying this to understand how the whole thing works and how I can use it for my code completion feature. I do hope I can get some part of it to work next week.