Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support having a file be both a document and additional file. #20558

Conversation

Pilchie
Copy link
Member

@Pilchie Pilchie commented Jun 30, 2017

Ask Mode

Customer scenario
If a single filepath is included in both the Compile and the AdditionalFiles item groups, the project system would fail to add the second of those two, and throw, leaving things in a bad state. In the legacy project system, that seemed to be caught and ignored, and likely you just didn't have the AdditionalFile in your compilations. In CPS a dialog would be displayed, and the file would end up in Miscellaneous files (however, this can happen during a transient state in CPS due to it's async nature). In Lightweight solution load, VS would crash.

Bugs this fixes: Fixes #19968
Workarounds, if any: Not have the item in both Compile and AdditionalFiles. Hard, because they may not realize they do, or it may be a transient case in CPS.
Risk: Medium - plumbs through new ids for additional items, etc.
Performance impact: Low - most significant change is ref counting instead of mere entry in a dictionary.
Is this a regression from a previous update?: No, this behavior has been since additional files were added.
Root cause analysis:: We never expected an item to be in both groups.
How was the bug found?: Customers reported files ending up in "Miscellaneous files" in CPS after changing the build action.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

I recommend reading commit-by-commmit.

Note that we can debate about whether the public API changes are warranted or not.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

Note: @davkean with this changed, if I renamed such a file in solution explorer in a CPS project I got tons of ugly exceptions from the project system...

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

I'd be up for debating the public API change. I get that the parameter was meaningless, but removing it seems an unnecessary binary breaking change.

var moniker = document.Key.Moniker;
if (_documentMonikers.TryGetValue(moniker, out var value))
{
_documentMonikers[moniker] = (value.document, value.refCount++);
Copy link
Member

Choose a reason for hiding this comment

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

I assume the post-increment happens before the assignment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh. I'll separate it just to not have to think about this.

private void RemoveMoniker(IVisualStudioHostDocument document)
{
var moniker = document.Key.Moniker;
var value = _documentMonikers[moniker];
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to protect against the moniker not being in the Dictionary? If it's not, this will throw.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, the code previously just had _documentMonikers.Remove(), which wouldn't throw. I'll guard.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

Re: public API - going to take a look at removing all the internal bits, but leaving the public entry points with comments saying that they are ignored. I sort of agree that it's not worth breaking.

@Pilchie Pilchie mentioned this pull request Jun 30, 2017
5 tasks
Pilchie added 6 commits June 29, 2017 19:04
Turns out we could end up with the same IVisualStudioHostDocument
for both, if they are both added.

Fixes dotnet#19968.
This is a breaking API change.  Need to decide if we want to take it or
not.
@Pilchie Pilchie force-pushed the Fix19968-DuplicateSourceAndAdditionalFiles-DistinctIds branch from 81bc054 to 818b0a7 Compare June 30, 2017 02:04
@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

@DustinCampbell care to take another look? Also - do you think I should squash the last two commits?

@davkean
Copy link
Member

davkean commented Jun 30, 2017

@Pilchie What kind of ugly errors?

@davkean
Copy link
Member

davkean commented Jun 30, 2017

Oh you mean if you renamed a file that was both a compile and additional file you got ugly errors? ie Not a regression introduced by this change?

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

@davkean Right - with this change, if you F2 and rename a file in solution explorer that is both source and additional files there are a bunch of exceptions from the project system about the tree not being consistent.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

retest windows_debug_vs-integration_prtest please

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

Hit the vsix installer error.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

Tagging @MattGertz for approval here.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

retest windows_debug_vs-integration_prtest please

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

retest windows_debug_vs-integration_prtest please

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

The overall approach seems sound. Some detail questions about the deprecated parameter (the comment doesn't make sense to me) and other questions.

/// Puts the specified additional document into the open state.
/// </summary>
/// <param name="documentId">The <see cref="DocumentId"/> to open.</param>
/// <param name="activate">Ignored - not necessary for additional documents.</param>
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the statement for the param here more "this doesn't matter in the preview workspace?"

}

UninitializeAdditionalDocument(document);
}

private void AddMoniker(IVisualStudioHostDocument document)
Copy link
Member

Choose a reason for hiding this comment

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

"AddToMonikerToDocumentMap"?

if (_documentMonikers.TryGetValue(moniker, out var value))
{
value.refCount++;
_documentMonikers[moniker] = (value.document, value.refCount);
Copy link
Member

Choose a reason for hiding this comment

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

I must admit: using tuples here seems really terrifying and really likely to make a mistake....

Copy link
Member

Choose a reason for hiding this comment

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

Can't the right hand side just be "value" since you already have the tuple in hand though?

}
else
{
_documentMonikers[moniker] = (value.document, value.refCount);
Copy link
Member

Choose a reason for hiding this comment

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

Can't the right hand side just be "value" since you already have the tuple in hand though?

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

retest windows_debug_vs-integration_prtest please

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

A bunch of tests failed in https://ci.dot.net/job/dotnet_roslyn/job/dev15.3.x/job/windows_debug_vs-integration_prtest/15/ with remoting exceptions.

@Pilchie
Copy link
Member Author

Pilchie commented Jun 30, 2017

retest windows_debug_vs-integration_prtest please

@Pilchie Pilchie merged commit 6f5b2d4 into dotnet:dev15.3.x Jun 30, 2017
@Pilchie Pilchie deleted the Fix19968-DuplicateSourceAndAdditionalFiles-DistinctIds branch June 30, 2017 23:09
rchande pushed a commit to rchande/roslyn that referenced this pull request Jul 6, 2017
…teSourceAndAdditionalFiles-DistinctIds"

This reverts commit 6f5b2d4, reversing
changes made to 66362df.
rchande pushed a commit that referenced this pull request Jul 6, 2017
Pilchie added a commit to Pilchie/roslyn that referenced this pull request Jul 24, 2017
…-DuplicateSourceAndAdditionalFiles-DistinctIds""

This reverts commit d03cde8.
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.

6 participants