microsoft / VSExtensibility

A repo for upcoming changes to extensibility in Visual Studio, the new extensibility model, and language server protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Editor only provides GetActiveTextView, how to get the ActiveFile or a Design/WPF View?

luislhg opened this issue · comments

Hello I'm trying to create a MVVM extension to help in MAUI/WPF/WinUI projects
I'm using this code to check if I'm inside a .xaml file var textView = await Extensibility.Editor().GetActiveTextViewAsync(context, cancellationToken);

However, it will return null, if the user does have a xaml file opened but never clicked in the text editor, and is actually focusing on the design area.
Is there any other way for me to check which file is currently active/selected instead of the TextEditor only?

I managed to get this working by using context.GetSelectedPathAsync(cancellationToken)).LocalPath instead of the ActiveTextView.

The hiccup is that the path is formatted differently (all lowercase: d:/users/project/test.xaml) whereas other classes from the API give the path properly (D:/Users/Project/Test,xaml).

But this works for any opened file, not requiring the actual text editor to be focused.