-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Don't compute the information for the code definition window if not open #57307
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
@@ -23,6 +24,9 @@ internal sealed class VisualStudioCodeDefinitionWindowService : ICodeDefinitionW | |
private readonly IAsyncServiceProvider _asyncServiceProvider; | ||
private readonly IThreadingContext _threadingContext; | ||
|
||
[DisallowNull] | ||
private IVsCodeDefView? _lazyCodeDefView; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public VisualStudioCodeDefinitionWindowService(SVsServiceProvider asyncServiceProvider, IThreadingContext threadingContext) | ||
|
@@ -31,6 +35,29 @@ public VisualStudioCodeDefinitionWindowService(SVsServiceProvider asyncServicePr | |
_threadingContext = threadingContext; | ||
} | ||
|
||
private async Task<IVsCodeDefView> GetVsCodeDefViewAsync() | ||
{ | ||
if (_lazyCodeDefView is not null) | ||
{ | ||
return _lazyCodeDefView; | ||
} | ||
|
||
_lazyCodeDefView = await _asyncServiceProvider.GetServiceAsync<SVsCodeDefView, IVsCodeDefView>().ConfigureAwait(true); | ||
|
||
return _lazyCodeDefView; | ||
} | ||
|
||
public async Task<bool> IsWindowOpenAsync(CancellationToken cancellationToken) | ||
{ | ||
var vsCodeDefView = await GetVsCodeDefViewAsync().ConfigureAwait(true); | ||
|
||
// Switch to the UI thread before using the IVsCodeDefView service | ||
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 This method will be more efficient if this call is moved to the start of the method (removes two thread context switches that would occur if the caller is on a background thread and the window is not already initialized, and no penalty for the other cases). |
||
|
||
// IsVisible returns S_FALSE if it's not visible | ||
return vsCodeDefView.IsVisible() == VSConstants.S_OK; | ||
} | ||
|
||
public async Task SetContextAsync(ImmutableArray<CodeDefinitionWindowLocation> locations, CancellationToken cancellationToken) | ||
{ | ||
// If the new context has no location, then just don't update, instead of showing the | ||
|
@@ -40,7 +67,7 @@ public async Task SetContextAsync(ImmutableArray<CodeDefinitionWindowLocation> l | |
return; | ||
} | ||
|
||
var vsCodeDefView = await _asyncServiceProvider.GetServiceAsync<SVsCodeDefView, IVsCodeDefView>().ConfigureAwait(false); | ||
var vsCodeDefView = await GetVsCodeDefViewAsync().ConfigureAwait(true); | ||
|
||
// Switch to the UI thread before using the IVsCodeDefView service | ||
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 This should also be moved up to before the call to GetServiceAsync (same reason) |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ How much penalty is there for calling
SetContextAsync
with an empty set of locations for this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the goal of doing that? Its entirely possible the service will throw away the call, I'm not certain.