You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue
The ITextViewOpenClosedListener is only providing its offsets (textView.Selection.ActivePosition.Offset, textView.Selection.ActivePosition.Offset, textView.Selection.ActivePosition.Offset) for the first time the method TextViewOpenedAsync is called.
All subsequente calls, all the offsets are always 0, regardless of the file opened.
Project Setup
Create an empty extension template
Create a class "MyListener" with the content below
usingMicrosoft.VisualStudio.Extensibility;usingMicrosoft.VisualStudio.Extensibility.Editor;usingMicrosoft.VisualStudio.Extensibility.Shell;usingSystem.Diagnostics;namespaceExtensibilityTextListenerBadOffset;[VisualStudioContribution]publicclassMyListener:ExtensionPart,ITextViewOpenClosedListener{publicTextViewExtensionConfigurationTextViewExtensionConfiguration=>new(){AppliesTo=[DocumentFilter.FromGlobPattern("**/*",true)],};publicTaskTextViewClosedAsync(ITextViewSnapshottextView,CancellationTokencancellationToken){returnTask.CompletedTask;}publicasyncTaskTextViewOpenedAsync(ITextViewSnapshottextView,CancellationTokencancellationToken){// TODO: API BUG?// Offsets only get a value at the first time it's ever called.// After positions always have 0, thus this is not working as expected.Debug.WriteLine($"ActivePosition {textView.Selection.ActivePosition.Offset}");Debug.WriteLine($"InsertionPosition {textView.Selection.InsertionPosition.Offset}");Debug.WriteLine($"AnchorPosition {textView.Selection.AnchorPosition.Offset}");awaitExtensibility.Shell().ShowPromptAsync($"Offset: {textView.Selection.ActivePosition.Offset}",PromptOptions.OK,cancellationToken);}}
@olegtk, thanks, just wanted to provide you some more guidance on how to repro and how useful this is.
After the first time TextViewOpenedAsync is fired, in all subsequent calls the textview.Selection values are always 0.
Below is a video with an Extensibility project at the left, and the Visual Studio debug session reproducing the bug at the right.
Why this deeply affects me and the extension:
This issue is preventing my extension from working properly. The goal of this extension feature is to fix the Visual Studio "Go To Definition (F12)" not opening the expected file when using Source Generators, as everytime you press F12 for a property or command that was source generated, VS will open the Source Generated file instead of the actual class and method you want.
My extension is using ITextViewOpenClosedListener to detect VS opened a source generated file, extracting the binding value based on the caret/selection position and then opening the correct file (usually a ViewModel) and closing the source generated file.
Issue and extension in action:
GoToBinding-Full01.mp4
You can see it worked fine - but that was the first call, since the textview isn't providing the selection values for all the next calls, I couldn't find any workaround for this...
It's a timing issue, Go To Definition command first opens the file (at this point we call TextViewOpenedAsync) and then, slightly later, moves the caret to the target location in the file...
Actually looks like VS Code behaves the same way - first I get onDidChangeVisibleTextEditors with selection at 0 and then onDidChangeTextEditorSelection with correct selection.
VS currently doesn't fire TextViewChangedAsync for caret moves though, but it should.
Would it help your extension, @luislhg? It sounds kinda tricky to detect file open this way, but probably doable?
Issue
The
ITextViewOpenClosedListener
is only providing its offsets (textView.Selection.ActivePosition.Offset, textView.Selection.ActivePosition.Offset, textView.Selection.ActivePosition.Offset) for the first time the methodTextViewOpenedAsync
is called.All subsequente calls, all the offsets are always 0, regardless of the file opened.
Project Setup
Project Sample is attached.
ExtensibilityTextListenerBadOffset.zip
Repro Steps
https://github.com/microsoft/VSExtensibility/assets/16278387/23193039-5a71-4ba5-9b5e-9446656b282a
The text was updated successfully, but these errors were encountered: