more code completion fun!

Eva Brucherseifer eva at kde.org
Fri Mar 9 13:24:31 GMT 2001


Hi all,

I don't know the ANTLR thing or what LL(k) is, but here is my contribution to 
this, maybe it is of help:

this morning I talked to our professor here at the TU Darmstadt about this 
problem and I got some interesting hints.

There is an algorithm by Donald Knuth (yes, the latex guy) that uses a finite 
state machine, which is widely used for problems of this type. 
You either can test for matches while the user writes and complete as soon as 
there is a unique match, or you can give choices before. For both cases you 
need a dictionary of valid words.

If I remember correctly in Visual C++ there is no continuous code completion 
while typing, but only, when the user enters a delimiter like "::", ".", "->" 
etc. that indicates there a function name has to be entered. Then all 
possible choices are given to the user, so this seams to be a pretty fast 
method.

> > So the goal is to find out what the user is trying to do. Then what
> > happens if the current file is full of nonsense e.g.
> > I start a method definition:
> >
> > namespace mynamespace {
> >
> > myclass::mymethod (int myarg1, int myarg2) {
> >    myarg2=myarg1-3
> >
> >
> > and i forget to close the damn function scope and maybe also forget the
> > semicolon in the function or make other errors.
> >
> > Then i go on with next method
> >
> > myclass::mymethod2 (int myarg1, int myarg2) {
> >    myarg2=myarg1;
> >
> >
> > }
> >
> >
> > Will this all then work in myclass::mymethod2 at all?
>

In every case you always need parse information, so you only can complete 
what you parsed before. 
The easy way is to use the reduced parsed information as it exists now in 
kdevelop 1.4, that is, the code is parsed when a project is opened and when 
the user selects the Refresh-option. (Q: Does it also re-parse when the code 
is saved?)

The other possibility that I see is to have a full parse tree as the compiler 
has it and then work with incremental changes, as the incremental compilers 
like the MVSC++ does it. There exists an optimized algorithm for this as 
well. These algorithm have the invariant of completeness, that is the parse 
tree always has to be complete in order to be valid. 

If anyone is interested in this, I can point to a publication, where this 
algorithm is described.


Finally I got a wish ;-)
If you implement code complition (which is a great thing), please add also a 
button to turn it off.... 
>From the GUI point of view, the code completion is not necessarily a good 
thing, since it is often faster to type and it interrupts your working flow. 
I think all the other IDEs have it implemented, because it is a small and 
fast algorithm, if you have the parse information anyway, and it is another 
feature on the feature list...
Actually, I would turn it off ;-)

Greetings,
eva






-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list