Skip to content

Commit 5936530

Browse files
Remove more workspace registration hookup code. (#78910)
Followup to #78909
2 parents 7087d2d + 840d235 commit 5936530

File tree

4 files changed

+6
-38
lines changed

4 files changed

+6
-38
lines changed

src/EditorFeatures/Core/Suggestions/SuggestedActionsSource.State.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using Microsoft.CodeAnalysis.Text;
76
using Microsoft.VisualStudio.Text;
87
using Microsoft.VisualStudio.Text.Editor;
98

@@ -20,9 +19,6 @@ private sealed class State : IDisposable
2019
public readonly SuggestedActionsSourceProvider Owner;
2120
public readonly ITextView TextView;
2221
public readonly ITextBuffer SubjectBuffer;
23-
public readonly WorkspaceRegistration Registration;
24-
25-
public Workspace? Workspace => Registration.Workspace;
2622

2723
public State(SuggestedActionsSource source, SuggestedActionsSourceProvider owner, ITextView textView, ITextBuffer textBuffer)
2824
{
@@ -31,7 +27,6 @@ public State(SuggestedActionsSource source, SuggestedActionsSourceProvider owner
3127
Owner = owner;
3228
TextView = textView;
3329
SubjectBuffer = textBuffer;
34-
Registration = Workspace.GetWorkspaceRegistration(textBuffer.AsTextContainer());
3530
}
3631

3732
void IDisposable.Dispose()

src/EditorFeatures/Core/Suggestions/SuggestedActionsSource.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,10 @@ public bool TryGetTelemetryId(out Guid telemetryId)
6363

6464
using var state = _state.TryAddReference();
6565
if (state is null)
66-
{
67-
return false;
68-
}
69-
70-
var workspace = state.Target.Workspace;
71-
if (workspace == null)
72-
{
73-
return false;
74-
}
75-
76-
var documentId = workspace.GetDocumentIdInCurrentContext(state.Target.SubjectBuffer.AsTextContainer());
77-
if (documentId == null)
78-
{
79-
return false;
80-
}
81-
82-
var project = workspace.CurrentSolution.GetProject(documentId.ProjectId);
83-
if (project == null)
84-
{
8566
return false;
86-
}
8767

88-
switch (project.Language)
68+
var document = state.Target.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
69+
switch (document?.Project.Language)
8970
{
9071
case LanguageNames.CSharp:
9172
telemetryId = s_CSharpSourceGuid;
@@ -171,10 +152,6 @@ private void OnTextViewClosed(object sender, EventArgs e)
171152
range.Snapshot.TextBuffer.Equals(state.Target.SubjectBuffer),
172153
$"Invalid text buffer passed to {nameof(HasSuggestedActionsAsync)}");
173154

174-
var workspace = state.Target.Workspace;
175-
if (workspace == null)
176-
return null;
177-
178155
using var asyncToken = state.Target.Owner.OperationListener.BeginAsyncOperation(nameof(GetSuggestedActionCategoriesAsync));
179156
var document = range.Snapshot.GetOpenTextDocumentInCurrentContextWithChanges();
180157
if (document == null)

src/EditorFeatures/Core/Suggestions/SuggestedActionsSource_Async.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,16 @@ private async Task GetSuggestedActionsWorkerAsync(
7373
if (state is null)
7474
return;
7575

76-
var workspace = state.Target.Workspace;
77-
if (workspace is null)
76+
var document = range.Snapshot.GetOpenTextDocumentInCurrentContextWithChanges();
77+
if (document is null)
7878
return;
7979

8080
var selection = TryGetCodeRefactoringSelection(state, range);
81-
await workspace.Services.GetRequiredService<IWorkspaceStatusService>().WaitUntilFullyLoadedAsync(cancellationToken).ConfigureAwait(false);
81+
await document.Project.Solution.Services.GetRequiredService<IWorkspaceStatusService>()
82+
.WaitUntilFullyLoadedAsync(cancellationToken).ConfigureAwait(false);
8283

8384
using (Logger.LogBlock(FunctionId.SuggestedActions_GetSuggestedActionsAsync, cancellationToken))
8485
{
85-
var document = range.Snapshot.GetOpenTextDocumentInCurrentContextWithChanges();
86-
if (document is null)
87-
return;
8886

8987
// Create a single keep-alive session as we process each lightbulb priority group. We want to
9088
// ensure that all calls to OOP will reuse the same solution-snapshot on the oop side (including

src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ public TagSource(
150150
_nonFrozenComputationCancellationSeries = new(_disposalTokenSource.Token);
151151
_tagSpanSetPool = new ObjectPool<HashSet<TagSpan<TTag>>>(() => new HashSet<TagSpan<TTag>>(this), trimOnFree: false);
152152

153-
Workspace.GetWorkspaceRegistration(subjectBuffer.AsTextContainer());
154-
155153
// PERF: Use AsyncBatchingWorkQueue<_, VoidResult> instead of AsyncBatchingWorkQueue<_> because the latter
156154
// has an async state machine that rethrows a very common cancellation exception.
157155
_eventChangeQueue = new AsyncBatchingWorkQueue<TagSourceQueueItem, VoidResult>(

0 commit comments

Comments
 (0)