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

Public API analyzer only works in Roslyn.sln if the API file is opened in the editor #42168

Closed
mavasani opened this issue Mar 4, 2020 · 3 comments · Fixed by #42521
Closed
Assignees
Labels
Area-IDE Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@mavasani
Copy link
Contributor

mavasani commented Mar 4, 2020

Version Used: Latest 16.6 dogfood build

Steps to Reproduce:

  1. Open Roslyn.sln
  2. Open any file, say Workspace.cs and add a new public API. You should see RS0016 error.
  3. Ctrl + Dot to see that public code fix is shown and the preview also shows the correct change
  4. Hit enter to attempt to apply the fix

Expected Behavior:
Unshipped public API file is changed

Actual Behavior:
Unshipped public API file is not changed. If you repeat the above steps with the public API already open in the editor, code fix does work. NOTE: I am unable to repro this behavior with couple other solutions I tried, but it does repro consistently on Roslyn.sln on both my machines.

I debugged this a bit, and it finally comes down the below code:

if (IsDocumentOpen(documentId))
{
var textBuffer = this.CurrentSolution.GetTextDocument(documentId).GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None).Container.TryGetTextBuffer();
if (textBuffer != null)
{
TextEditApplication.UpdateText(newText, textBuffer, EditOptions.DefaultMinimalChange);
return;
}
}
// The document wasn't open in a normal way, so invisible editor time
using var invisibleEditor = OpenInvisibleEditor(documentId);
TextEditApplication.UpdateText(newText, invisibleEditor.TextBuffer, EditOptions.None);

It seems something from the InvisibleEditor code path is causing the scenario to fail, I don't see any exceptions - just the file change does not seem to get saved to disk. I am not sure which component or API does the actual write to disk in invisible editor code path.

@mavasani
Copy link
Contributor Author

mavasani commented Mar 4, 2020

Tagging @jasonmalinowski, in case your upcoming PR is fixing anything on this code path.

@jasonmalinowski
Copy link
Member

@mavasani I guess the changes I had in mind were the ones in 99dc680 which I guess isn't in that path. Hmm.

@sharwell
Copy link
Member

This is caused by dotnet/project-system#2160 (failure of the SDK to add AdditionalFiles to AvailableItemName). I implemented a workaround for dotnet/roslyn in #42521.

@sharwell sharwell added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Mar 28, 2020
@sharwell sharwell modified the milestones: Backlog, Next Mar 28, 2020
@sharwell sharwell modified the milestones: Next, temp, 16.6.P3 Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
4 participants