Skip to content

Remove workarounds for the Running Document Table threading issues #78993

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Threading;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;

Expand Down Expand Up @@ -62,9 +63,6 @@ public OpenTextBufferProvider(

_runningDocumentTable = new(() =>
{
/* NOTE: REMOVE ONCE https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2441480 IS FIXED */
_threadingContext.ThrowIfNotOnUIThread();

// The running document table since 18.0 has limited operations that can be done in a free threaded manner, specifically fetching the service and advising events.
// This is specifically guaranteed by the shell that those limited operations are safe and do not cause RPCs, and it's important we don't try to fetch the service
// via a helper that will "helpfully" try to jump to the UI thread.
Expand Down Expand Up @@ -101,24 +99,15 @@ private void RaiseEventForEachListener(Action<IOpenTextBufferEventListener> acti

private async Task CheckForExistingOpenDocumentsAsync()
{
/*
* NOTE: UNCOMMENT ONCE https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2441480 IS FIXED
* AND REMOVE THE THREAD CHECK FROM THE INITIALIZATION OF _runningDocumentTable

// Yield the thread, so the caller can proceed immediately.
await Task.Yield();

// Ensure we obtain the RDT before transitioning to the main thread
_ = _runningDocumentTable.Value;
// Yield the thread, so the calling constructor can proceed immediately
await Task.Yield().ConfigureAwait(false);

*/
// Ensure we obtain the RDT before transitioning to the main thread
_ = _runningDocumentTable.Value;

// Now switch to the main thread since document enumeration does require it
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();

/* NOTE: REMOVE ONCE https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2441480 IS FIXED */
// Temporarily ensure we obtain the RDT from the main thread
_ = _runningDocumentTable.Value;

foreach (var (filePath, textBuffer, hierarchy) in EnumerateDocumentSet())
{
// We might or might not have seen this file be opened if it was opened between when we subscribed to the running document table and when
Expand Down
Loading