Get function declaration location from context

SyntaxEditor Python Language Add-on for WPF Forum

Posted 9 years ago by tal
Version: 16.1.0631
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

Hey,

I’m experimenting on the Python Language demo and I’m trying to get the declaration (path + line number + column offset) of a function from the current selection.
I got the path but I couldn’t retrieve the rest of the information – is it possible?

var context = new PythonContextFactory().CreateContext(codeEditor.ActiveView.Selection.EndSnapshotOffset, PythonContextKind.Self);
if (context == null)
{
    return;
}
if ((context.Location != null) && ((context.Location == PythonContextLocations.Comment) || (context.Location == PythonContextLocations.LiteralString)))
{
    return;
}
IResolverResultSet set = context.Resolve();
if (((set == null) || (set.Results == null)) || (set.Results.Count == 0))
{
    return;
}
IFunctionResolverResult result = set.Results[0] as IFunctionResolverResult;
if ((result == null) || (result.Function == null))
{
    return;
}
bool isBuiltin = result.Function.DeclaringModule.IsBuiltin;
string path = result.Function.DeclaringModule.Path;

 (I'm looking into implementing a GoToDefinition functionality)

Thanks,

Tal

Comments (4)

Answer - Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tal,

We don't currently store the declaration line/column.  We could possibly add something for that in a future version though.  Would you want to see the start offset of the declaration Name, or the text range of the entire declaration?


Actipro Software Support

Posted 9 years ago by tal
Avatar

Hi,

Thanks for the fast reply, I would like at least the start offset, though the text range of the entire declaration would be a very nice addition if it is not too much trouble.

It would be very much appreciated if you could also add the same functionality for the Function.DeclaringType when the function is a method (that way, it will be possible to get the entire text range of the container class of a specific method).

Thanks again,

Tal

Answer - Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tal,

Ok we will add a TextRange to both ITypeDefinition and IFunctionDefinition.  If you'd like to try a preview build of this functionality, please write our support address and mention this thread.


Actipro Software Support

Posted 9 years ago by tal
Avatar

Thank you!

The latest build of this product (v24.1.3) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.