How to make autocompletion for IDE?

unDEFER via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 25 03:06:47 PDT 2017


Hello!
I have written my text editor with highlighting, and now I want 
to add IDE features to it.
I want to make autocompletion, but not only complete members of 
class/struct, but also all functions which maybe used with type, 
if the first argument of the function is this type. I.e. in 
"a".fromStringz() style instead of fromStringz(a).

For it I will take editable now sources, add to it lines like 
this:

   foreach(d; __traits(allMembers, std.string))
   {
       if (is(typeof(mixin("\"abc\"."~d~"()"))))
	  pragma(msg, "\"abc\"."~d~"()" );
   }

So it will print all methods which can be called for strings as 
"abc".function().
And I want to compile this file with options "-c -o-".
The problem that compilation for files with avarage count of 
imports may take e.g. 7 seconds..

7 seconds is too long to wait autocompletion.
But compiler really do this "task" with autocompletion requests 
very fast.

And I think how to implement the next:
Add the task to some other file task.d. import it to the first 
file with mixin(import("task.d")). Change syscall open() to my 
function which if will see that it opens "task.d" waiting the 
time when user will ask autocomplete (press Ctrl-space), and then 
write the task to "task.d" and continue execution of compiler...

The problem that I see in this conception is that seems not 
possible write such import which will be imported only when 
compiler starts handle templates and simultaneously in the place 
where will be accessed all local variables of a function.

Any ideas?


More information about the Digitalmars-d-learn mailing list