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
8 changes: 3 additions & 5 deletions src/LanguageServer/Protocol/Handler/AbstractRefreshQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public AbstractRefreshQueue(
_notificationManager = notificationManager;
}

public Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken)
public async Task OnInitializedAsync(ClientCapabilities clientCapabilities, RequestContext context, CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to know some details about these efforts. Is that somehow related to the new runtime async stuff? IIRC, this used to produce warning along the lines of "this async method is lacking awaits and will run synchronously".

{
Initialize(clientCapabilities);
return Task.CompletedTask;
}

public void Initialize(ClientCapabilities clientCapabilities)
Expand Down Expand Up @@ -104,7 +103,7 @@ protected void EnqueueRefreshNotification(DocumentUri? documentUri)
}
}

private ValueTask FilterLspTrackedDocumentsAsync(
private async ValueTask FilterLspTrackedDocumentsAsync(
LspWorkspaceManager lspWorkspaceManager,
IClientLanguageServerManager notificationManager,
ImmutableSegmentedList<DocumentUri?> documentUris,
Expand All @@ -117,7 +116,7 @@ private ValueTask FilterLspTrackedDocumentsAsync(
{
try
{
return notificationManager.SendRequestAsync(GetWorkspaceRefreshName(), cancellationToken);
await notificationManager.SendRequestAsync(GetWorkspaceRefreshName(), cancellationToken).ConfigureAwait(false);
}
catch (Exception ex) when (ex is ObjectDisposedException or ConnectionLostException)
{
Expand All @@ -128,7 +127,6 @@ private ValueTask FilterLspTrackedDocumentsAsync(
}

// LSP is already tracking all changed documents so we don't need to send a refresh request.
return ValueTask.CompletedTask;
}

public virtual void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ await AddTextDocumentEditsAsync(

return new LSP.WorkspaceEdit { DocumentChanges = textDocumentEdits.ToArray() };

Task AddTextDocumentDeletionsAsync<TTextDocument>(
async Task AddTextDocumentDeletionsAsync<TTextDocument>(
IEnumerable<DocumentId> removedDocuments,
Func<DocumentId, TTextDocument?> getOldDocument)
where TTextDocument : TextDocument
Expand All @@ -223,8 +223,6 @@ Task AddTextDocumentDeletionsAsync<TTextDocument>(

textDocumentEdits.Add(new DeleteFile { DocumentUri = oldTextDoc.GetURI() });
}

return Task.CompletedTask;
}

async Task AddTextDocumentAdditionsAsync<TTextDocument>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ public CompletionResolveHandler(IGlobalOptionService globalOptions)
public LSP.TextDocumentIdentifier? GetTextDocumentIdentifier(LSP.CompletionItem request)
=> GetTextDocumentCacheEntry(request);

public Task<LSP.CompletionItem> HandleRequestAsync(LSP.CompletionItem completionItem, RequestContext context, CancellationToken cancellationToken)
public async Task<LSP.CompletionItem> HandleRequestAsync(LSP.CompletionItem completionItem, RequestContext context, CancellationToken cancellationToken)
{
var completionListCache = context.GetRequiredLspService<CompletionListCache>();

if (!completionListCache.TryGetCompletionListCacheEntry(completionItem, out var cacheEntry))
{
// Don't have a cache associated with this completion item, cannot resolve.
context.TraceWarning("No cache entry found for the provided completion item at resolve time.");
return Task.FromResult(completionItem);
return completionItem;
}

var document = context.GetRequiredDocument();
var capabilityHelper = new CompletionCapabilityHelper(context.GetRequiredClientCapabilities());

return ResolveCompletionItemAsync(
completionItem, cacheEntry.CompletionList, document, _globalOptions, capabilityHelper, cancellationToken);
return await ResolveCompletionItemAsync(
completionItem, cacheEntry.CompletionList, document, _globalOptions, capabilityHelper, cancellationToken).ConfigureAwait(false);
}

public static Task<LSP.CompletionItem> ResolveCompletionItemAsync(
public static async Task<LSP.CompletionItem> ResolveCompletionItemAsync(
LSP.CompletionItem completionItem,
Document document,
IGlobalOptionService globalOptions,
Expand All @@ -73,11 +73,11 @@ public CompletionResolveHandler(IGlobalOptionService globalOptions)
if (!completionListCache.TryGetCompletionListCacheEntry(completionItem, out var cacheEntry))
{
// Don't have a cache associated with this completion item, cannot resolve.
return Task.FromResult(completionItem);
return completionItem;
}

return ResolveCompletionItemAsync(
completionItem, cacheEntry.CompletionList, document, globalOptions, capabilityHelper, cancellationToken);
return await ResolveCompletionItemAsync(
completionItem, cacheEntry.CompletionList, document, globalOptions, capabilityHelper, cancellationToken).ConfigureAwait(false);
}

private static async Task<LSP.CompletionItem> ResolveCompletionItemAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public AbstractGoToDefinitionHandler(IMetadataAsSourceFileService metadataAsSour

public abstract Task<LSP.Location[]?> HandleRequestAsync(TextDocumentPositionParams request, RequestContext context, CancellationToken cancellationToken);

protected Task<LSP.Location[]?> GetDefinitionAsync(LSP.TextDocumentPositionParams request, bool forSymbolType, RequestContext context, CancellationToken cancellationToken)
protected async Task<LSP.Location[]?> GetDefinitionAsync(LSP.TextDocumentPositionParams request, bool forSymbolType, RequestContext context, CancellationToken cancellationToken)
{
var workspace = context.Workspace;
var document = context.Document;
if (workspace is null || document is null)
return SpecializedTasks.Null<LSP.Location[]>();
return null;

var linePosition = ProtocolConversions.PositionToLinePosition(request.Position);

return GetDefinitionsAsync(_globalOptions, _metadataAsSourceFileService, workspace, document, forSymbolType, linePosition, cancellationToken);
return await GetDefinitionsAsync(_globalOptions, _metadataAsSourceFileService, workspace, document, forSymbolType, linePosition, cancellationToken).ConfigureAwait(false);
}

internal static async Task<LSP.Location[]?> GetDefinitionsAsync(IGlobalOptionService globalOptions, IMetadataAsSourceFileService? metadataAsSourceFileService, Workspace workspace, Document document, bool forSymbolType, LinePosition linePosition, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal abstract class AbstractDocumentPullDiagnosticHandler<TDiagnosticsParams

public abstract TextDocumentIdentifier? GetTextDocumentIdentifier(TDiagnosticsParams diagnosticsParams);

protected override ValueTask<ImmutableArray<IDiagnosticSource>> GetOrderedDiagnosticSourcesAsync(TDiagnosticsParams diagnosticsParams, string? requestDiagnosticCategory, RequestContext context, CancellationToken cancellationToken)
protected override async ValueTask<ImmutableArray<IDiagnosticSource>> GetOrderedDiagnosticSourcesAsync(TDiagnosticsParams diagnosticsParams, string? requestDiagnosticCategory, RequestContext context, CancellationToken cancellationToken)
{
// Note: context.Document may be null in the case where the client is asking about a document that we have
// since removed from the workspace. In this case, we don't really have anything to process.
Expand All @@ -38,15 +38,15 @@ protected override ValueTask<ImmutableArray<IDiagnosticSource>> GetOrderedDiagno
if (identifier is null || context.TextDocument is null)
{
context.TraceDebug("Ignoring diagnostics request because no text document was provided");
return new([]);
return [];
}

if (!context.IsTracking(identifier.DocumentUri))
{
context.TraceWarning($"Ignoring diagnostics request for untracked document: {identifier.DocumentUri}");
return new([]);
return [];
}

return DiagnosticSourceManager.CreateDocumentDiagnosticSourcesAsync(context, requestDiagnosticCategory, cancellationToken);
return await DiagnosticSourceManager.CreateDocumentDiagnosticSourcesAsync(context, requestDiagnosticCategory, cancellationToken).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ protected abstract ValueTask<ImmutableArray<IDiagnosticSource>> GetOrderedDiagno
/// Used by public workspace pull diagnostics to allow it to keep the connection open until
/// changes occur to avoid the client spamming the server with requests.
/// </summary>
protected virtual Task WaitForChangesAsync(string? category, RequestContext context, CancellationToken cancellationToken)
protected virtual async Task WaitForChangesAsync(string? category, RequestContext context, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public async Task<TReturn?> HandleRequestAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ public void Dispose()
_workspaceRegistrationService.LspSolutionChanged -= OnLspSolutionChanged;
}

protected override ValueTask<ImmutableArray<IDiagnosticSource>> GetOrderedDiagnosticSourcesAsync(TDiagnosticsParams diagnosticsParams, string? requestDiagnosticCategory, RequestContext context, CancellationToken cancellationToken)
protected override async ValueTask<ImmutableArray<IDiagnosticSource>> GetOrderedDiagnosticSourcesAsync(TDiagnosticsParams diagnosticsParams, string? requestDiagnosticCategory, RequestContext context, CancellationToken cancellationToken)
{
if (context.ServerKind == WellKnownLspServerKinds.RazorLspServer)
{
// If we're being called from razor, we do not support WorkspaceDiagnostics at all. For razor, workspace
// diagnostics will be handled by razor itself, which will operate by calling into Roslyn and asking for
// document-diagnostics instead.
return new([]);
return [];
}

return DiagnosticSourceManager.CreateWorkspaceDiagnosticSourcesAsync(context, requestDiagnosticCategory, cancellationToken);
return await DiagnosticSourceManager.CreateWorkspaceDiagnosticSourcesAsync(context, requestDiagnosticCategory, cancellationToken).ConfigureAwait(false);
}

private void OnLspSolutionChanged(object? sender, WorkspaceChangeEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ internal abstract class AbstractDocumentSyntaxAndSemanticDiagnosticSourceProvide

public bool IsEnabled(ClientCapabilities clientCapabilities) => true;

public ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken)
public async ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken)
{
return new([new DocumentDiagnosticSource(kind, context.GetRequiredDocument())]);
return [new DocumentDiagnosticSource(kind, context.GetRequiredDocument())];
}

[Export(typeof(IDiagnosticSourceProvider)), Shared]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
private sealed class CodeAnalysisDiagnosticSource(Project project, ICodeAnalysisDiagnosticAnalyzerService codeAnalysisService)
: AbstractProjectDiagnosticSource(project)
{
public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
RequestContext context,
CancellationToken cancellationToken)
{
Expand All @@ -69,7 +69,7 @@ public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
// user. As such, it is definitely not "live" data, and it should be overridden by any subsequent fresh data
// that has been produced.
diagnostics = ProtocolConversions.AddBuildTagIfNotPresent(diagnostics);
return Task.FromResult(diagnostics);
return diagnostics;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ AsyncLazy<ILookup<DocumentId, DiagnosticData>> GetLazyDiagnostics()
private sealed class CodeAnalysisDiagnosticSource(TextDocument document, ICodeAnalysisDiagnosticAnalyzerService codeAnalysisService)
: AbstractWorkspaceDocumentDiagnosticSource(document)
{
public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
RequestContext context,
CancellationToken cancellationToken)
{
Expand All @@ -104,7 +104,7 @@ public override Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
// user. As such, it is definitely not "live" data, and it should be overridden by any subsequent fresh data
// that has been produced.
diagnostics = ProtocolConversions.AddBuildTagIfNotPresent(diagnostics);
return Task.FromResult(diagnostics);
return diagnostics;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ internal sealed class PublicDocumentNonLocalDiagnosticSourceProvider(

public bool IsEnabled(ClientCapabilities clientCapabilities) => true;

public ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken)
public async ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken)
{
// Non-local document diagnostics are reported only when full solution analysis is enabled for analyzer execution.
if (globalOptions.GetBackgroundAnalysisScope(context.GetRequiredDocument().Project.Language) == BackgroundAnalysisScope.FullSolution)
{
// NOTE: Compiler does not report any non-local diagnostics, so we only ask to run non-compiler-analyzers.
return new([new NonLocalDocumentDiagnosticSource(context.GetRequiredDocument(), AnalyzerFilter.NonCompilerAnalyzer)]);
return [new NonLocalDocumentDiagnosticSource(context.GetRequiredDocument(), AnalyzerFilter.NonCompilerAnalyzer)];
}

return new([]);
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ internal class DidChangeHandler() : ILspServiceDocumentRequestHandler<DidChangeT
public TextDocumentIdentifier GetTextDocumentIdentifier(DidChangeTextDocumentParams request)
=> request.TextDocument;

public Task<object?> HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken)
public async Task<object?> HandleRequestAsync(DidChangeTextDocumentParams request, RequestContext context, CancellationToken cancellationToken)
{
var text = context.GetTrackedDocumentInfo(request.TextDocument.DocumentUri).SourceText;

text = GetUpdatedSourceText(request.ContentChanges, text);

context.UpdateTrackedDocument(request.TextDocument.DocumentUri, text, request.TextDocument.Version);

return SpecializedTasks.Default<object>();
return null;
}

internal static bool AreChangesInReverseOrder(TextDocumentContentChangeEvent[] contentChanges)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ internal sealed class DocumentEditAndContinueDiagnosticSourceProvider() : IDiagn

public bool IsEnabled(ClientCapabilities capabilities) => true;

public ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken)
public async ValueTask<ImmutableArray<IDiagnosticSource>> CreateDiagnosticSourcesAsync(RequestContext context, CancellationToken cancellationToken)
{
return new([EditAndContinueDiagnosticSource.CreateOpenDocumentSource(context.GetRequiredDocument())]);
return [EditAndContinueDiagnosticSource.CreateOpenDocumentSource(context.GetRequiredDocument())];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public RegisterSolutionSnapshotHandler(ISolutionSnapshotRegistry registry)
public bool MutatesSolutionState => false;
public bool RequiresLSPSolution => true;

public Task<LspSolutionSnapshotId> HandleRequestAsync(RequestContext context, CancellationToken cancellationToken)
public async Task<LspSolutionSnapshotId> HandleRequestAsync(RequestContext context, CancellationToken cancellationToken)
{
Contract.ThrowIfNull(context.Solution);
var id = _registry.RegisterSolutionSnapshot(context.Solution);
return Task.FromResult(new LspSolutionSnapshotId(id.Id));
return new LspSolutionSnapshotId(id.Id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public FoldingRangesHandler(IGlobalOptionService globalOptions)

public TextDocumentIdentifier GetTextDocumentIdentifier(FoldingRangeParams request) => request.TextDocument;

public Task<FoldingRange[]?> HandleRequestAsync(FoldingRangeParams request, RequestContext context, CancellationToken cancellationToken)
public async Task<FoldingRange[]?> HandleRequestAsync(FoldingRangeParams request, RequestContext context, CancellationToken cancellationToken)
{
var document = context.Document;
if (document is null)
return SpecializedTasks.Null<FoldingRange[]>();
return null;

var lineFoldingOnly = context.GetRequiredClientCapabilities().TextDocument?.FoldingRange?.LineFoldingOnly == true;
return SpecializedTasks.AsNullable(GetFoldingRangesAsync(_globalOptions, document, lineFoldingOnly, cancellationToken));
return await SpecializedTasks.AsNullable(GetFoldingRangesAsync(_globalOptions, document, lineFoldingOnly, cancellationToken)).ConfigureAwait(false);
}

internal static Task<FoldingRange[]> GetFoldingRangesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public DocumentHighlightsHandler(IHighlightingService highlightingService, IGlob

public TextDocumentIdentifier GetTextDocumentIdentifier(TextDocumentPositionParams request) => request.TextDocument;

public Task<DocumentHighlight[]?> HandleRequestAsync(TextDocumentPositionParams request, RequestContext context, CancellationToken cancellationToken)
public async Task<DocumentHighlight[]?> HandleRequestAsync(TextDocumentPositionParams request, RequestContext context, CancellationToken cancellationToken)
{
var document = context.Document;
if (document == null)
return SpecializedTasks.Null<DocumentHighlight[]>();
return null;

var position = ProtocolConversions.PositionToLinePosition(request.Position);
return GetHighlightsAsync(_globalOptions, _highlightingService, document, position, cancellationToken);
return await GetHighlightsAsync(_globalOptions, _highlightingService, document, position, cancellationToken).ConfigureAwait(false);
}

internal static async Task<DocumentHighlight[]?> GetHighlightsAsync(IGlobalOptionService globalOptions, IHighlightingService highlightingService, Document document, LinePosition linePosition, CancellationToken cancellationToken)
Expand Down
Loading
Loading