[PATCH]: store a range as position for a context import instead of a cursor

David Nolden david.nolden.kdevelop at art-master.de
Sun Aug 9 12:45:01 UTC 2009


Am Sonntag 09 August 2009 14:22:41 schrieb Milian Wolff:
> require __DIR__ . '/../../' . SOME_CONSTANT;
>
> That would be possible to support. But I doubt doing string-comparison is
> feasable here... It will really get kind of complicated, I see only the
> following solution using just the cursor:
>
> - get a token stream up to the position of the cursor
> - check if we are in an include statement
> - check if there is an import in the range between the start of the include
> statement and the cursor position
>
> Not trivial at all... but well.
You could also attach the AST of the file to the top-context using 
IASTContainer, and then use that directly.

> I would appreciate if you could get it working one day. I really hate
> replicating stuff again and again instead of storing the information one
> gets once and using that later on. I personally think it would make sense
> to have something similar to a declaration for imports:
>
> - you associate a range with it
> - when entering the range it gets highlighted
> - when requesting a tooltip it gets shown
>
> again, make sure the tooltips can stack (see above).
>
> Would that be possible? Or is there anything which speaks against it? Size
> of the repo or something?

I guess the best and most generic solution would be this:

At the beginning of each top-context, add an empty-range NamespaceDeclaration, 
and give it the file-name as identifier. This would be useful for other 
languages as well, and could become a standard mechanism.

Then, just build a use of that declaration with the correct range, whenever 
importing/including that top-context.

Should work, no?

Greetings, David





More information about the KDevelop-devel mailing list