Skip to content

VisualStudioActiveDocumentTracker doesn't handle all element IDs #57203

@mavasani

Description

@mavasani

While investigating the UX for BackgroundAnalysisScope.ActiveFile analysis mode, I ran into an issue in VisualStudioActiveDocumentTracker that causes it to intermittently end up with no active document while switching document tabs, i.e. TryGetActiveDocumentId returns null even when you are editing a source document. The root cause seems to be in the below code:

int IVsSelectionEvents.OnElementValueChanged([ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSSELELEMID")] uint elementid, object varValueOld, object varValueNew)
{
AssertIsForeground();
if (elementid == (uint)VSConstants.VSSELELEMID.SEID_DocumentFrame)
{
// Remember the newly activated frame so it can be read from another thread.
if (varValueNew is IVsWindowFrame frame)
{
TrackNewActiveWindowFrame(frame);
}
}
return VSConstants.S_OK;
}

We currently handle SEID_DocumentFrame. However, sometimes we receive this callback with VSSELELEMID.SEID_WindowFrame instead of VSSELELEMID.SEID_DocumentFrame, such that the underlying frame type is still WINDOWFRAMETYPE_Document indicating it is a document being activated. I verified that handling this element ID and adding the check for frame type resolves this issue. I'll create a PR with this fix for review.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions