Question about injectContext

Sven Brauch svenbrauch at googlemail.com
Tue Mar 22 18:35:38 UTC 2011


Hi, me again. :)

I'd like to create a member variable declaration for a class if an
attribute is written at any instance of that class, for example (A is
a class): "instance = A(); instance->x = 3" -- then I'd like to create
a class member declaration for x, if none exists yet.
Isn't this the use case injectContext is meant for? I would like to
temporarily open the class context, insert the declaration, and then
close it again. However, using injectContext, that does not work
properly. The declaration is inserted into the right context, but:
A. when hovering the mouse over it, it's not found (i.e. no
navigation-widget, no highlighting); I think that's because the
context under the cursor is searched for the declaration under the
cursor, and -- although opened when creating the declaration -- the
context opened with injectContext() does not wrap around the range of
the declaration
B. when invoking autocompletion, the declarations created with a
context opened by injectContext as parent are deleted while the
completion-widget is active, leading to blank / nonfunctional
completion entries.

Looking at the implementation of injectContext, I was wondering,
because it is said to take a parameter "range" in the docstring (which
I would expect to be necessary, no?) but it doesn't. Furthermore, it
just calls openContext and does nothing else. The declaration is
located at language/duchain/abstractcontextbuilder.h:458.
PHP also uses this function, but I couldn't find something equivalent
to my special case, probably things are a bit different there.

It would be great to have some more information on this, especially
I'd be interested in how to set a correct range and owner context (so
it isn't suddenly deleted) for such a declaration which is created
after the context it should be in already has been closed.

Bye,
Sven




More information about the KDevelop-devel mailing list