Skip to content

Commit

Permalink
Merge pull request #34182 from dotnet/merges/dev16.0-to-dev16.0-vs-deps
Browse files Browse the repository at this point in the history
Merge dev16.0 to dev16.0-vs-deps
  • Loading branch information
dotnet-automerge-bot authored Mar 18, 2019
2 parents df5f5d8 + 4fd64f8 commit f92995a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11317,9 +11317,12 @@ .maxstack 5
}");
}

[Fact]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/34198")]
public void DecimalBinaryOp_03()
{
// Test temporarily disabled as it fails CI on Linux in master branch
// Tracked by https://github.com/dotnet/roslyn/issues/34198

string source = @"
class C
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private void OnBatchScopeDisposed()
}

// Check for those files being opened to start wire-up if necessary
_workspace.CheckForOpenDocuments(documentFileNamesAdded.ToImmutable());
_workspace.QueueCheckForFilesBeingOpen(documentFileNamesAdded.ToImmutable());
}
}

Expand Down Expand Up @@ -1078,7 +1078,7 @@ public DocumentId AddFile(string fullPath, SourceCodeKind sourceCodeKind, Immuta
else
{
_project._workspace.ApplyChangeToWorkspace(w => _documentAddAction(w, documentInfo));
_project._workspace.CheckForOpenDocuments(ImmutableArray.Create(fullPath));
_project._workspace.QueueCheckForFilesBeingOpen(ImmutableArray.Create(fullPath));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public sealed class OpenFileTracker
/// </summary>
private readonly object _gate = new object();
private HashSet<string> _fileNamesToCheckForOpenDocuments;
private bool _justEnumerateTheEntireRunningDocumentTable;

/// <summary>
/// Tracks whether we have decided to just scan the entire running document table for files that might already be in the workspace rather than checking
/// each file one-by-one. This starts out at true, because we are created asynchronously, and files might have already been added to the workspace
/// that we never got a call to <see cref="QueueCheckForFilesBeingOpen(ImmutableArray{string})"/> for.
/// </summary>
private bool _justEnumerateTheEntireRunningDocumentTable = true;

private bool _taskPending;

Expand Down Expand Up @@ -103,22 +109,6 @@ private void ConnectToRunningDocumentTable()
runningDocumentTable.AdviseRunningDocTableEvents(new RunningDocumentTableEventSink(this), out var docTableEventsCookie);
}

public void CheckForOpenDocumentsByEnumeratingTheRunningDocumentTable()
{
_foregroundAffinitization.AssertIsForeground();

lock (_gate)
{
// Since we're scanning the full RDT, we can skip any explicit names we already have queued
ClearPendingFilesForBeingOpen_NoLock();
}

foreach (var cookie in GetInitializedRunningDocumentTableCookies())
{
TryOpeningDocumentsForNewCookie(cookie);
}
}

private IEnumerable<uint> GetInitializedRunningDocumentTableCookies()
{
// Some methods we need here only exist in IVsRunningDocumentTable and not the IVsRunningDocumentTable4 that we
Expand Down Expand Up @@ -377,7 +367,7 @@ private void TryClosingDocumentsForCookie(uint cookie)
/// <summary>
/// Queues a new task to check for files being open for these file names.
/// </summary>
public void CheckForFilesBeingOpen(ImmutableArray<string> newFileNames)
public void QueueCheckForFilesBeingOpen(ImmutableArray<string> newFileNames)
{
_foregroundAffinitization.ThisCanBeCalledOnAnyThread();

Expand Down Expand Up @@ -419,37 +409,43 @@ public void CheckForFilesBeingOpen(ImmutableArray<string> newFileNames)

if (shouldStartTask)
{
var asyncToken = _asyncOperationListener.BeginAsyncOperation(nameof(CheckForFilesBeingOpen));
var asyncToken = _asyncOperationListener.BeginAsyncOperation(nameof(QueueCheckForFilesBeingOpen));

Task.Run(async () =>
{
await _foregroundAffinitization.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();

CheckForFilesBeingOpenOnUIThread();
ProcessQueuedWorkOnUIThread();
}).CompletesAsyncOperation(asyncToken);
}
}

private void CheckForFilesBeingOpenOnUIThread()
public void ProcessQueuedWorkOnUIThread()
{
_foregroundAffinitization.AssertIsForeground();

// Just pulling off the values from the shared state to the local funtion...
// Just pulling off the values from the shared state to the local function.
HashSet<string> fileNamesToCheckForOpenDocuments;
bool justEnumerateTheEntireRunningDocumentTable;
lock (_gate)
{
fileNamesToCheckForOpenDocuments = _fileNamesToCheckForOpenDocuments;
justEnumerateTheEntireRunningDocumentTable = _justEnumerateTheEntireRunningDocumentTable;

ClearPendingFilesForBeingOpen_NoLock();
_fileNamesToCheckForOpenDocuments = null;
_justEnumerateTheEntireRunningDocumentTable = false;

_taskPending = false;
}

if (justEnumerateTheEntireRunningDocumentTable)
{
CheckForOpenDocumentsByEnumeratingTheRunningDocumentTable();
foreach (var cookie in GetInitializedRunningDocumentTableCookies())
{
TryOpeningDocumentsForNewCookie(cookie);
}
}
else
else if (fileNamesToCheckForOpenDocuments != null)
{
foreach (var filename in fileNamesToCheckForOpenDocuments)
{
Expand All @@ -462,14 +458,6 @@ private void CheckForFilesBeingOpenOnUIThread()
}
}

private void ClearPendingFilesForBeingOpen_NoLock()
{
_fileNamesToCheckForOpenDocuments = null;
_justEnumerateTheEntireRunningDocumentTable = false;

_taskPending = false;
}

private class RunningDocumentTableEventSink : IVsRunningDocTableEvents3
{
private readonly OpenFileTracker _openFileTracker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,17 @@ public async System.Threading.Tasks.Task ConnectToOpenFileTrackerOnUIThreadAsync
_openFileTrackerOpt = openFileTracker;
}

openFileTracker.CheckForOpenDocumentsByEnumeratingTheRunningDocumentTable();
openFileTracker.ProcessQueuedWorkOnUIThread();
}

public void CheckForOpenDocuments(ImmutableArray<string> newFileNames)
public void QueueCheckForFilesBeingOpen(ImmutableArray<string> newFileNames)
{
_openFileTrackerOpt?.CheckForFilesBeingOpen(newFileNames);
_openFileTrackerOpt?.QueueCheckForFilesBeingOpen(newFileNames);
}

public void ProcessQueuedWorkOnUIThread()
{
_openFileTrackerOpt?.ProcessQueuedWorkOnUIThread();
}

internal void AddProjectToInternalMaps(VisualStudioProject project, IVsHierarchy hierarchy, Guid guid, string projectSystemName)
Expand Down
9 changes: 9 additions & 0 deletions src/VisualStudio/Core/Impl/CodeModel/FileCodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ internal bool TryGetDocument(out Document document)
}
else
{
// HACK HACK HACK: Ensure we've processed all files being opened before we let designers work further.
// In https://devdiv.visualstudio.com/DevDiv/_workitems/edit/728035, a file is opened in an invisible editor and contents are written
// to it. The file isn't saved, but it's added to the workspace; we won't have yet hooked up to the open file since that work was deferred.
// Since we're on the UI thread here, we can ensure those are all wired up since the analysis of this document may depend on that other file.
// We choose to do this here rather than in the project system code when it's added because we don't want to pay the penalty of checking the RDT for
// all files being opened on the UI thread if we really don't need it. This uses an 'as' cast, because in unit tests the workspace is a different
// derived form of VisualStudioWorkspace, and there we aren't dealing with open files at all so it doesn't matter.
(State.Workspace as VisualStudioWorkspaceImpl)?.ProcessQueuedWorkOnUIThread();

document = Workspace.CurrentSolution.GetDocument(GetDocumentId());
}

Expand Down

0 comments on commit f92995a

Please sign in to comment.