Reputation: 3081
Question: How do I get this with syntactic context? i.e. a set of tokens for the line / area I am mousing over, in a way that I can generate the fully scoped name of the type? i.e. how do I hook into the syntactic content of the editor's live evaluation of the syntax of the file?
I'd want something like:
private string GetTypeOfMousedOverToken(EventArgs e)
Upvotes: 0
Views: 48
Reputation: 27910
You can use following code to get syntactic context:
Microsoft.VisualStudio.Text.SnapshotPoint caretPosition = textView.Caret.Position.BufferPosition;
Microsoft.CodeAnalysis.Document document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
document.GetSyntaxRootAsync().Result.FindToken(caretPosition)
See https://vlasovstudio.com/visual-commander/commands.html#CreateTypedVariable for a complete example.
Upvotes: 1