Skip to content

Make sure we always subscribe to shared hierarchy eventing#26215

Merged
jasonmalinowski merged 1 commit intodotnet:dev15.7.xfrom
jasonmalinowski:fix-sharedproject-contexts
Apr 20, 2018
Merged

Make sure we always subscribe to shared hierarchy eventing#26215
jasonmalinowski merged 1 commit intodotnet:dev15.7.xfrom
jasonmalinowski:fix-sharedproject-contexts

Conversation

@jasonmalinowski
Copy link
Copy Markdown
Member

In d9e3002 I restored the code that was subscribing to IVsHierarchy event notifications to know when shared contexts change. Unfortunately it was put in the event handler for IVisualStudioHostDocument.Opened, which only runs when the document is being opened that was already part of the workspace. If the reverse order happens: a file is already open, and only then added to the workspace, the code was skipped.

Curiously, Workspace has an overridable method OnDocumentClosing which you can use to hook calls, but not an equivalent OnDocumentOpening. It's unclear to me if this design was something we want to extend (it's a bit strange) and so I'm not touching that for now.

Fixes dotnet/project-system#3467.

Ask Mode template

Customer scenario

Open a CPS-based project in 15.7 that does multitargeting, or uses shared projects. If you open a file prior to the project system having fully updated the language (an operation that happens asynchronously), the project switcher won't work.

Bugs this fixes

dotnet/project-system#3467

Workarounds, if any

Close and reopen the affected file. There's no hint to the user that this workaround would work.

Risk

Low: just moving some code around to cover some missed cases.

Performance impact

None: code just moving around.

Is this a regression from a previous update?

Yes, code was refactored since 15.6 and this was introduced.

Root cause analysis

We connect to an open text buffer through two different codepaths:

  1. The user opened a file that we knew was in a project.
  2. A file is added to a project that was already opened.

We ran some additional connection code only in the first case, but not the second. The second now happens regularly in CPS, because CPS is now deferring informing the language service about files until much later in the load process, so it's easy to open a file before the project information has been wired up.

For preventing regressions, this area of code is being entirely refactored to address a number of issues; I'm not going to write tests that would soon be deleted.

How was the bug found?

Customer reported.

In d9e3002 I restored the code that was subscribing to IVsHierarchy
event notifications to know when shared contexts change. Unfortunately
it was put in the event handler for IVisualStudioHostDocument.Opened,
which only runs when the document is being opened that was already
part of the workspace. If the reverse order happens: a file is already
open, and only _then_ added to the workspace, the code was skipped.

Curiously, Workspace has an overridable method OnDocumentClosing which
you can use to hook calls, but not an equivalent OnDocumentOpening. It's
unclear to me if this design was something we want to extend (it's a bit
strange) and so I'm not touching that for now.

Fixes dotnet/project-system#3467.
@jasonmalinowski jasonmalinowski self-assigned this Apr 17, 2018
@jasonmalinowski jasonmalinowski requested review from a team, Pilchie and jinujoseph April 17, 2018 22:38
if (project.PushingChangesToWorkspace)
{
project.ProjectTracker.NotifyWorkspace(workspace => workspace.OnDocumentOpened(document.Id, document.GetOpenTextBuffer().AsTextContainer(), isCurrentContext));
project.ProjectTracker.NotifyWorkspace(workspace =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting something like VisualStudioProjectTracker.NotifyWorkspaceOfOpenedDocument that does this, instead of adding it in 3 places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but then I'm spending time refactoring code I'm already deleting in a branch. 😄

@jasonmalinowski
Copy link
Copy Markdown
Member Author

@Pilchie @jinujoseph is this something we want to take for 15.7? The original bug was tagged as such. If so, I'll make the escrow bug.

@jasonmalinowski jasonmalinowski requested a review from a team April 19, 2018 00:10
@jasonmalinowski jasonmalinowski merged commit dba06e3 into dotnet:dev15.7.x Apr 20, 2018
@jasonmalinowski jasonmalinowski deleted the fix-sharedproject-contexts branch April 20, 2018 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants