Skip to content
Merged
Show file tree
Hide file tree
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 @@ -20,6 +20,6 @@ internal sealed class DefaultExternalDefinitionItemProvider() : IExternalDefinit
/// Provides an extension point that allows for other workspace layers to add additional
/// results to the results found by the FindReferences engine.
/// </summary>
public Task<DefinitionItem?> GetThirdPartyDefinitionItemAsync(Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken)
=> SpecializedTasks.Null<DefinitionItem>();
public async ValueTask<DefinitionItem?> GetThirdPartyDefinitionItemAsync(Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken)
=> null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace Microsoft.CodeAnalysis.FindUsages;

internal interface IExternalDefinitionItemProvider : IWorkspaceService
{
Task<DefinitionItem?> GetThirdPartyDefinitionItemAsync(
ValueTask<DefinitionItem?> GetThirdPartyDefinitionItemAsync(
Solution solution, DefinitionItem definitionItem, CancellationToken cancellationToken);
}
4 changes: 1 addition & 3 deletions src/VisualStudio/CSharp/Impl/CSharpPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override void RegisterInitializeAsyncWork(PackageLoadTasks packageInit
packageInitializationTasks.AddTask(isMainThreadTask: false, task: PackageInitializationBackgroundThreadAsync);
}

private Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks packageInitializationTasks, CancellationToken cancellationToken)
private async Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks packageInitializationTasks, CancellationToken cancellationToken)
{
try
{
Expand All @@ -90,8 +90,6 @@ private Task PackageInitializationBackgroundThreadAsync(PackageLoadTasks package
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, ErrorSeverity.General))
{
}

return Task.CompletedTask;
}

protected override void RegisterObjectBrowserLibraryManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CSharpCodeStyleSettingsProvider(
Update();
}

protected override Task UpdateOptionsAsync(
protected override async Task UpdateOptionsAsync(
TieredAnalyzerConfigOptions options, ImmutableArray<Project> projectsInScope, CancellationToken cancellationToken)
{
var varSettings = GetVarCodeStyleOptions(options, SettingsUpdater);
Expand Down Expand Up @@ -65,8 +65,6 @@ protected override Task UpdateOptionsAsync(

var unusedValueSettings = GetUnusedValueCodeStyleOptions(options, SettingsUpdater);
AddRange(unusedValueSettings);

return Task.CompletedTask;
}

private static IEnumerable<CodeStyleSetting> GetVarCodeStyleOptions(TieredAnalyzerConfigOptions options, OptionUpdater updater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CSharpWhitespaceSettingsProvider(IThreadingContext threadingContext, stri
Update();
}

protected override Task UpdateOptionsAsync(
protected override async Task UpdateOptionsAsync(
TieredAnalyzerConfigOptions options, ImmutableArray<Project> projectsInScope, CancellationToken cancellationToken)
{
var spacingOptions = GetSpacingOptions(options, SettingsUpdater);
Expand All @@ -39,8 +39,6 @@ protected override Task UpdateOptionsAsync(
AddRange(indentationOptions.ToImmutableArray());
var wrappingOptions = GetWrappingOptions(options, SettingsUpdater);
AddRange(wrappingOptions.ToImmutableArray());

return Task.CompletedTask;
}

private static IEnumerable<Setting> GetSpacingOptions(TieredAnalyzerConfigOptions options, OptionUpdater updaterService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace Microsoft.VisualStudio.LanguageServices.CSharp;
internal sealed class SemanticSearchDocumentNavigationService(SemanticSearchToolWindowImpl window)
: AbstractDocumentNavigationService
{
public override Task<bool> CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
=> SpecializedTasks.True;
public override async Task<bool> CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
=> true;

public override Task<INavigableLocation?> GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
public override async Task<INavigableLocation?> GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
{
Debug.Assert(workspace is SemanticSearchWorkspace);
Debug.Assert(documentId == window.SemanticSearchService.GetQueryDocumentId(workspace.CurrentSolution));

return Task.FromResult<INavigableLocation?>(window.GetNavigableLocation(textSpan));
return window.GetNavigableLocation(textSpan);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private sealed class ResultsObserver(IFindUsagesContext presenterContext, IOptio
private readonly Lazy<ConcurrentStack<(DocumentId documentId, ImmutableArray<TextChange> changes)>> _lazyDocumentUpdates = new();
private readonly Lazy<ConcurrentDictionary<string, string?>> _lazyTextFileUpdates = new();

public ValueTask<ClassificationOptions> GetClassificationOptionsAsync(Microsoft.CodeAnalysis.Host.LanguageServices language, CancellationToken cancellationToken)
=> new(options.GetClassificationOptions(language.Language));
public async ValueTask<ClassificationOptions> GetClassificationOptionsAsync(Microsoft.CodeAnalysis.Host.LanguageServices language, CancellationToken cancellationToken)
=> options.GetClassificationOptions(language.Language);

public ValueTask OnDefinitionFoundAsync(DefinitionItem definition, CancellationToken cancellationToken)
=> presenterContext.OnDefinitionFoundAsync(definition, cancellationToken);
Expand All @@ -48,16 +48,14 @@ public ValueTask OnUserCodeExceptionAsync(UserCodeExceptionInfo exception, Cance
=> presenterContext.OnDefinitionFoundAsync(
new SearchExceptionDefinitionItem(exception.Message, exception.TypeName, exception.StackTrace, (queryDocument != null) ? new DocumentSpan(queryDocument, exception.Span) : default), cancellationToken);

public ValueTask OnLogMessageAsync(string message, CancellationToken cancellationToken)
public async ValueTask OnLogMessageAsync(string message, CancellationToken cancellationToken)
{
logMessage(message);
return ValueTask.CompletedTask;
}

public ValueTask OnDocumentUpdatedAsync(DocumentId documentId, ImmutableArray<TextChange> changes, CancellationToken cancellationToken)
public async ValueTask OnDocumentUpdatedAsync(DocumentId documentId, ImmutableArray<TextChange> changes, CancellationToken cancellationToken)
{
_lazyDocumentUpdates.Value.Push((documentId, changes));
return ValueTask.CompletedTask;
}

private ImmutableArray<(DocumentId documentId, ImmutableArray<TextChange> changes)> GetDocumentUpdates()
Expand Down Expand Up @@ -94,10 +92,9 @@ public async ValueTask<Solution> GetUpdatedSolutionAsync(Solution oldSolution, C
public ImmutableArray<(string filePath, string? newContent)> GetFileUpdates()
=> _lazyTextFileUpdates.IsValueCreated ? _lazyTextFileUpdates.Value.SelectAsArray(static entry => (entry.Key, entry.Value)) : [];

public ValueTask OnTextFileUpdatedAsync(string filePath, string? newContent, CancellationToken cancellationToken)
public async ValueTask OnTextFileUpdatedAsync(string filePath, string? newContent, CancellationToken cancellationToken)
{
_lazyTextFileUpdates.Value.TryAdd(filePath, newContent);
return ValueTask.CompletedTask;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ public sealed class MockFixer : CodeFixProvider

public sealed override ImmutableArray<string> FixableDiagnosticIds => [Id];

public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
Called = true;
ContextDiagnosticsCount = context.Diagnostics.Length;
return Task.CompletedTask;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ protected override void CancelBuildProject()
CancelBuildProjectCount++;
}

protected override Task<bool> BuildProjectAsync()
protected override async Task<bool> BuildProjectAsync()
{
BuildProjectCount++;
return Task.FromResult(_buildSucceeds);
return _buildSucceeds;
}

protected override bool GetProjectProperties(
Expand All @@ -86,8 +86,8 @@ protected override IUIThreadOperationExecutor GetUIThreadOperationExecutor()
return _uiThreadOperationExecutor;
}

protected override Task<IEnumerable<string>> GetNamespacesToImportAsync(IEnumerable<string> namespacesToImport, IInteractiveWindow interactiveWindow)
protected override async Task<IEnumerable<string>> GetNamespacesToImportAsync(IEnumerable<string> namespacesToImport, IInteractiveWindow interactiveWindow)
{
return Task.FromResult((IEnumerable<string>)NamespacesToImport);
return (IEnumerable<string>)NamespacesToImport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public void Dispose()
{
}

public Task<ExecutionResult> InitializeAsync()
=> Task.FromResult(ExecutionResult.Success);
public async Task<ExecutionResult> InitializeAsync()
=> ExecutionResult.Success;

public Task<ExecutionResult> ResetAsync(bool initialize = true)
=> Task.FromResult(ExecutionResult.Success);
public async Task<ExecutionResult> ResetAsync(bool initialize = true)
=> ExecutionResult.Success;

public bool CanExecuteCode(string text)
=> true;

public Task<ExecutionResult> ExecuteCodeAsync(string text)
public async Task<ExecutionResult> ExecuteCodeAsync(string text)
{
OnExecute?.Invoke(this, text);
return Task.FromResult(ExecutionResult.Success);
return ExecutionResult.Success;
}

public string FormatClipboard()
Expand Down
10 changes: 5 additions & 5 deletions src/VisualStudio/CodeLens/ReferenceCodeLensProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ public void Dispose()
_cancellationTokenSource.Cancel();
}

public Task<bool> CanCreateDataPointAsync(
public async Task<bool> CanCreateDataPointAsync(
CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
{
if (descriptorContext != null && descriptorContext.ApplicableSpan.HasValue)
{
// we allow all reference points.
// engine will call this for all points our roslyn code lens (reference) tagger tagged.
return SpecializedTasks.True;
return true;
}

return SpecializedTasks.False;
return false;
}

public Task<IAsyncCodeLensDataPoint> CreateDataPointAsync(
public async Task<IAsyncCodeLensDataPoint> CreateDataPointAsync(
CodeLensDescriptor descriptor, CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken)
{
var dataPoint = new DataPoint(
Expand All @@ -84,7 +84,7 @@ public Task<IAsyncCodeLensDataPoint> CreateDataPointAsync(
descriptor);

AddDataPoint(dataPoint);
return Task.FromResult<IAsyncCodeLensDataPoint>(dataPoint);
return dataPoint;
}

// The current CodeLens OOP design does not allow us to register an event handler for WorkspaceChanged events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,23 @@ private async Task<bool> FixHierarchyContentAsync(IVsHierarchyCodeCleanupScope h
return false;
}

private Task<bool> FixTextBufferAsync(TextBufferCodeCleanUpScope textBufferScope, ICodeCleanUpExecutionContext context)
private async Task<bool> FixTextBufferAsync(TextBufferCodeCleanUpScope textBufferScope, ICodeCleanUpExecutionContext context)
{
var buffer = textBufferScope.SubjectBuffer;

// Let LSP handle code cleanup in the cloud scenario
if (buffer.IsInLspEditorContext())
return SpecializedTasks.False;
return false;

var document = buffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
return SpecializedTasks.False;
return false;

var workspace = buffer.GetWorkspace();
if (workspace is not VisualStudioWorkspace visualStudioWorkspace)
return SpecializedTasks.False;
return false;

return FixAsync(visualStudioWorkspace, ApplyFixAsync, context);
return await FixAsync(visualStudioWorkspace, ApplyFixAsync, context).ConfigureAwait(false);

// Local function
async Task<Solution> ApplyFixAsync(IProgress<CodeAnalysisProgress> progress, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,9 @@ private static async Task NotifyCpsProjectSystemAsync(
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
public ValueTask ReportDesignerAttributeDataAsync(ImmutableArray<DesignerAttributeData> data, CancellationToken cancellationToken)
public async ValueTask ReportDesignerAttributeDataAsync(ImmutableArray<DesignerAttributeData> data, CancellationToken cancellationToken)
{
Contract.ThrowIfNull(_projectSystemNotificationQueue);
_projectSystemNotificationQueue.AddWork(data.AsSpan());
return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CommonCodeStyleSettingsProvider(
Update();
}

protected override Task UpdateOptionsAsync(
protected override async Task UpdateOptionsAsync(
TieredAnalyzerConfigOptions options, ImmutableArray<Project> projectsInScope, CancellationToken cancellationToken)
{
var qualifySettings = GetQualifyCodeStyleOptions(options, SettingsUpdater);
Expand Down Expand Up @@ -60,8 +60,6 @@ protected override Task UpdateOptionsAsync(

var experimentalSettings = GetExperimentalCodeStyleOptions(options, SettingsUpdater);
AddRange(experimentalSettings);

return Task.CompletedTask;
}

private static IEnumerable<CodeStyleSetting> GetQualifyCodeStyleOptions(TieredAnalyzerConfigOptions options, OptionUpdater updater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ public CommonWhitespaceSettingsProvider(
Update();
}

protected override Task UpdateOptionsAsync(
protected override async Task UpdateOptionsAsync(
TieredAnalyzerConfigOptions options, ImmutableArray<Project> projectsInScope, CancellationToken cancellationToken)
{
var defaultOptions = GetDefaultOptions(options, SettingsUpdater);
AddRange(defaultOptions);

return Task.CompletedTask;
}

private static IEnumerable<Setting> GetDefaultOptions(TieredAnalyzerConfigOptions options, OptionUpdater updater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ protected AbstractTableDataSourceFindUsagesContext(
// results). To limit the amount of work we do, we'll only update the window every 250ms.
_notifyQueue = new AsyncBatchingWorkQueue(
DelayTimeSpan.Short,
cancellationToken =>
async cancellationToken =>
{
_tableDataSink.FactorySnapshotChanged(this);
return ValueTask.CompletedTask;
},
presenter._asyncListener,
CancellationTokenSource.Token);
Expand Down Expand Up @@ -346,11 +345,10 @@ public IDisposable Subscribe(ITableDataSink sink)

#region FindUsagesContext overrides.

public sealed override ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
public sealed override async ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken)
{
// Note: IFindAllReferenceWindow.Title is safe to set from any thread.
_findReferencesWindow.Title = title;
return default;
}

public sealed override async ValueTask OnCompletedAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -528,28 +526,25 @@ protected RoslynDefinitionBucket GetOrCreateDefinitionBucket(DefinitionItem defi
}
}

public sealed override ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken)
public sealed override async ValueTask ReportNoResultsAsync(string message, CancellationToken cancellationToken)
{
lock (Gate)
{
NoDefinitionsFoundMessage = message;
}

return ValueTask.CompletedTask;
}

public sealed override async ValueTask ReportMessageAsync(string message, NotificationSeverity severity, CancellationToken cancellationToken)
{
await this.Presenter.ReportMessageAsync(message, severity, cancellationToken).ConfigureAwait(false);
}

protected sealed override ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken)
protected sealed override async ValueTask ReportProgressAsync(int current, int maximum, CancellationToken cancellationToken)
{
_progressQueue.AddWork((current, maximum));
return default;
}

private ValueTask UpdateTableProgressAsync(ImmutableSegmentedList<(int current, int maximum)> nextBatch, CancellationToken _)
private async ValueTask UpdateTableProgressAsync(ImmutableSegmentedList<(int current, int maximum)> nextBatch, CancellationToken _)
{
if (!nextBatch.IsEmpty)
{
Expand All @@ -568,8 +563,6 @@ private ValueTask UpdateTableProgressAsync(ImmutableSegmentedList<(int current,
if (current > 0)
_findReferencesWindow.SetProgress(current, maximum);
}

return ValueTask.CompletedTask;
}

protected static DefinitionItem CreateNoResultsDefinitionItem(string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ private SimpleMessageEntry(
_message = message;
}

public static Task<Entry> CreateAsync(
public static async Task<Entry> CreateAsync(
RoslynDefinitionBucket definitionBucket,
RoslynDefinitionBucket? navigationBucket,
string message)
{
var referenceEntry = new SimpleMessageEntry(definitionBucket, navigationBucket, message);
return Task.FromResult<Entry>(referenceEntry);
return referenceEntry;
}

protected override object? GetValueWorker(string keyName)
Expand Down
Loading
Loading