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 @@ -30,10 +30,10 @@ private RefactorAllProvider()
public override IEnumerable<RefactorAllScope> GetSupportedRefactorAllScopes()
=> [RefactorAllScope.Solution];

public override Task<CodeAction?> GetRefactoringAsync(RefactorAllContext fixAllContext)
public override async Task<CodeAction?> GetRefactoringAsync(RefactorAllContext fixAllContext)
{
Debug.Assert(fixAllContext.Scope == RefactorAllScope.Solution);
return Task.FromResult<CodeAction?>(new FixAllCodeAction(EnableNullableReferenceTypesInSolutionAsync));
return new FixAllCodeAction(EnableNullableReferenceTypesInSolutionAsync);

async Task<Solution> EnableNullableReferenceTypesInSolutionAsync(
CodeActionPurpose purpose, IProgress<CodeAnalysisProgress> progress, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ protected override TypeSyntax FindAnalyzableType(SyntaxNode node, SemanticModel
protected override TypeStyleResult AnalyzeTypeName(TypeSyntax typeName, SemanticModel semanticModel, CSharpSimplifierOptions options, CancellationToken cancellationToken)
=> CSharpUseImplicitTypeHelper.Instance.AnalyzeTypeName(typeName, semanticModel, options, cancellationToken);

protected override Task HandleDeclarationAsync(Document document, SyntaxEditor editor, TypeSyntax type, CancellationToken cancellationToken)
protected override async Task HandleDeclarationAsync(Document document, SyntaxEditor editor, TypeSyntax type, CancellationToken cancellationToken)
{
UseImplicitTypeCodeFixProvider.ReplaceTypeWithVar(editor, type);
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
context.RegisterRefactoring(
CodeAction.Create(
CSharpFeaturesResources.Use_recursive_patterns,
_ => Task.FromResult(document.WithSyntaxRoot(replacementFunc(root))),
async _ => document.WithSyntaxRoot(replacementFunc(root)),
nameof(CSharpFeaturesResources.Use_recursive_patterns)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal override CompletionRules GetRules(CompletionOptions options)
return newRules;
}

internal override async Task<bool> IsSpeculativeTypeParameterContextAsync(Document document, int position, CancellationToken cancellationToken)
internal override async ValueTask<bool> IsSpeculativeTypeParameterContextAsync(Document document, int position, CancellationToken cancellationToken)
{
var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ private static IEnumerable<ISymbol> GetAttributeNamedParameters(
return attributeType.GetAttributeNamedParameters(semanticModel.Compilation, within);
}

protected override Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
=> Task.FromResult(GetTextChange(selectedItem, ch));
protected override async Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
=> GetTextChange(selectedItem, ch);

private static TextChange? GetTextChange(CompletionItem selectedItem, char? ch)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ private static CompletionItemRules GetRules(string displayText)
}
}

protected override Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
protected override async Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
{
if (!SymbolCompletionItem.TryGetInsertionText(selectedItem, out var insertionText))
{
insertionText = selectedItem.DisplayText;
}

return Task.FromResult<TextChange?>(new TextChange(selectedItem.Span, insertionText));
return new TextChange(selectedItem.Span, insertionText);
}

internal TestAccessor GetTestAccessor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public override async Task ProvideCompletionsAsync(CompletionContext context)
}
}

protected override Task<ImmutableArray<SymbolAndSelectionInfo>> GetSymbolsAsync(
protected override async Task<ImmutableArray<SymbolAndSelectionInfo>> GetSymbolsAsync(
CompletionContext? completionContext, CSharpSyntaxContext context, int position, CompletionOptions options, CancellationToken cancellationToken)
{
var targetToken = context.TargetToken;

// Don't want to offer this after "async" (even though the compiler may parse that as a type).
if (SyntaxFacts.GetContextualKeywordKind(targetToken.ValueText) == SyntaxKind.AsyncKeyword)
return SpecializedTasks.EmptyImmutableArray<SymbolAndSelectionInfo>();
return [];

var potentialTypeNode = targetToken.Parent;
if (targetToken.IsKind(SyntaxKind.GreaterThanToken) && potentialTypeNode is TypeArgumentListSyntax typeArgumentList)
Expand All @@ -89,17 +89,17 @@ protected override Task<ImmutableArray<SymbolAndSelectionInfo>> GetSymbolsAsync(
}

if (typeNode == null)
return SpecializedTasks.EmptyImmutableArray<SymbolAndSelectionInfo>();
return [];

// We weren't after something that looked like a type.
var tokenBeforeType = typeNode.GetFirstToken().GetPreviousToken();

if (!IsPreviousTokenValid(tokenBeforeType))
return SpecializedTasks.EmptyImmutableArray<SymbolAndSelectionInfo>();
return [];

var typeDeclaration = typeNode.GetAncestor<TypeDeclarationSyntax>();
if (typeDeclaration == null)
return SpecializedTasks.EmptyImmutableArray<SymbolAndSelectionInfo>();
return [];

// Looks syntactically good. See what interfaces our containing class/struct/interface has
Debug.Assert(IsClassOrStructOrInterfaceOrRecord(typeDeclaration));
Expand All @@ -115,7 +115,7 @@ protected override Task<ImmutableArray<SymbolAndSelectionInfo>> GetSymbolsAsync(
interfaceSet.AddRange(directInterface.AllInterfaces);
}

return Task.FromResult(interfaceSet.SelectAsArray(t => new SymbolAndSelectionInfo(Symbol: t, Preselect: false)));
return interfaceSet.SelectAsArray(t => new SymbolAndSelectionInfo(Symbol: t, Preselect: false));
}

private static bool IsPreviousTokenValid(SyntaxToken tokenBeforeType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override bool IsFinalSemicolonOfUsingOrExtern(SyntaxNode directive, Sy
};
}

protected override Task<bool> ShouldProvideParenthesisCompletionAsync(
protected override async Task<bool> ShouldProvideParenthesisCompletionAsync(
Document document,
CompletionItem item,
char? commitKey,
Expand All @@ -57,7 +57,7 @@ protected override Task<bool> ShouldProvideParenthesisCompletionAsync(
// it can only be used as like: bar.ToInt();
// Func<int> x = bar.ToInt or Func<Bar, int> x = bar.ToInt is illegal. It can't be assign to delegate.
// Therefore at here we always assume the user always wants to add parenthesis.
=> Task.FromResult(commitKey is ';' or '.');
=> commitKey is ';' or '.';

protected override (ITypeSymbol? receiverTypeSymbol, bool isStatic) TryGetReceiverTypeSymbol(
SemanticModel semanticModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ bool IEqualityComparer<IParameterSymbol>.Equals(IParameterSymbol? x, IParameterS
int IEqualityComparer<IParameterSymbol>.GetHashCode(IParameterSymbol obj)
=> obj.Name.GetHashCode();

protected override Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
protected override async Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
{
return Task.FromResult<TextChange?>(new TextChange(
return new TextChange(
selectedItem.Span,
// Insert extra colon if committing with '(' only: "method(parameter:(" is preferred to "method(parameter(".
// In all other cases, do not add extra colon. Note that colon is already added if committing with ':'.
ch == '(' ? selectedItem.GetEntireDisplayText() : selectedItem.DisplayText));
ch == '(' ? selectedItem.GetEntireDisplayText() : selectedItem.DisplayText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ private static void AddItems(ImmutableArray<INamedTypeSymbol> inferredTypes, int
}
}

protected override Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
protected override async Task<TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char? ch, CancellationToken cancellationToken)
{
return Task.FromResult<TextChange?>(new TextChange(
return new TextChange(
selectedItem.Span,
selectedItem.DisplayText));
selectedItem.DisplayText);
}

public override ImmutableHashSet<char> TriggerCharacters => [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public DefaultArgumentProvider()
{
}

public override Task ProvideArgumentAsync(ArgumentContext context)
public override async Task ProvideArgumentAsync(ArgumentContext context)
{
if (context.PreviousValue is { })
{
Expand Down Expand Up @@ -52,7 +52,5 @@ public override Task ProvideArgumentAsync(ArgumentContext context)
_ => "default",
};
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public OutVariableArgumentProvider()
{
}

public override Task ProvideArgumentAsync(ArgumentContext context)
public override async Task ProvideArgumentAsync(ArgumentContext context)
{
if (context.PreviousValue is not null)
{
// This argument provider does not attempt to replace arguments already in code.
return Task.CompletedTask;
return;
}

if (context.Parameter.RefKind != RefKind.Out)
{
// This argument provider only considers 'out' parameters.
return Task.CompletedTask;
return;
}

// Since tihs provider runs after ContextVariableArgumentProvider, we know there is no suitable target in
Expand All @@ -60,6 +60,5 @@ public override Task ProvideArgumentAsync(ArgumentContext context)
[]))));

context.DefaultValue = syntax.NormalizeWhitespace().ToFullString();
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ private sealed class CopilotDismissChangesCodeAction(SyntaxNode originalMethodNo
{
public override string Title => FeaturesResources.Dismiss;

protected override Task<IEnumerable<CodeActionOperation>> ComputePreviewOperationsAsync(CancellationToken cancellationToken)
=> Task.FromResult<IEnumerable<CodeActionOperation>>(null!);
protected override async Task<IEnumerable<CodeActionOperation>> ComputePreviewOperationsAsync(CancellationToken cancellationToken)
=> null!;

protected override Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken)
=> Task.FromResult<IEnumerable<CodeActionOperation>>(
[new TriggerDismissalCodeActionOperation(originalMethodNode, diagnostic)]);
protected override async Task<IEnumerable<CodeActionOperation>> ComputeOperationsAsync(CancellationToken cancellationToken)
=> [new TriggerDismissalCodeActionOperation(originalMethodNode, diagnostic)];

private sealed class TriggerDismissalCodeActionOperation(SyntaxNode originalMethodNode, Diagnostic diagnostic) : CodeActionOperation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal sealed class CSharpDocumentHighlightsService(
CSharpSyntaxKinds.Instance,
services)
{
protected override async Task<ImmutableArray<Location>> GetAdditionalReferencesAsync(
protected override async ValueTask<ImmutableArray<Location>> GetAdditionalReferencesAsync(
Document document, ISymbol symbol, CancellationToken cancellationToken)
{
// The FindRefs engine won't find references through 'var' for performance reasons.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal override bool ShouldIncludeAccessibilityModifier(SyntaxNode typeNode)
return typeDeclaration.Modifiers.Any(m => SyntaxFacts.IsAccessibilityModifier(m.Kind()));
}

protected override Task<Solution> UpdateMembersWithExplicitImplementationsAsync(
protected override async Task<Solution> UpdateMembersWithExplicitImplementationsAsync(
Solution unformattedSolution, IReadOnlyList<DocumentId> documentIds,
INamedTypeSymbol extractedInterface, INamedTypeSymbol typeToExtractFrom,
IEnumerable<ISymbol> includedMembers, ImmutableDictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationMap,
Expand All @@ -72,6 +72,6 @@ protected override Task<Solution> UpdateMembersWithExplicitImplementationsAsync(
// In C#, member implementations do not always need
// to be explicitly added. It's safe enough to return
// the passed in solution
return Task.FromResult(unformattedSolution);
return unformattedSolution;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ protected override SyntaxNode GetFirstStatementOrInitializerSelectedAtCallSite()
protected override SyntaxNode GetLastStatementOrInitializerSelectedAtCallSite()
=> this.SelectionResult.GetLastStatementUnderContainer();

protected override Task<SyntaxNode> GetStatementOrInitializerContainingInvocationToExtractedMethodAsync(CancellationToken cancellationToken)
protected override async Task<SyntaxNode> GetStatementOrInitializerContainingInvocationToExtractedMethodAsync(CancellationToken cancellationToken)
{
var statement = GetStatementContainingInvocationToExtractedMethodWorker();
return Task.FromResult<SyntaxNode>(statement.WithAdditionalAnnotations(CallSiteAnnotation));
return statement.WithAdditionalAnnotations(CallSiteAnnotation);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ protected override SyntaxNode GetLastStatementOrInitializerSelectedAtCallSite()
return this.SelectionResult.GetFirstStatement();
}

protected override Task<SyntaxNode> GetStatementOrInitializerContainingInvocationToExtractedMethodAsync(CancellationToken cancellationToken)
protected override async Task<SyntaxNode> GetStatementOrInitializerContainingInvocationToExtractedMethodAsync(CancellationToken cancellationToken)
{
var statement = GetStatementContainingInvocationToExtractedMethodWorker();
return Task.FromResult<SyntaxNode>(statement.WithAdditionalAnnotations(CallSiteAnnotation));
return statement.WithAdditionalAnnotations(CallSiteAnnotation);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace Microsoft.CodeAnalysis.CSharp.GoToDefinition;
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal sealed class CSharpGoToDefinitionSymbolService() : AbstractGoToDefinitionSymbolService
{
protected override Task<ISymbol> FindRelatedExplicitlyDeclaredSymbolAsync(Project project, ISymbol symbol, CancellationToken cancellationToken)
=> Task.FromResult(symbol);
protected override async Task<ISymbol> FindRelatedExplicitlyDeclaredSymbolAsync(Project project, ISymbol symbol, CancellationToken cancellationToken)
=> symbol;

protected override int? GetTargetPositionIfControlFlow(SemanticModel semanticModel, SyntaxToken token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.CodeAnalysis.CSharp.IntroduceVariable;

internal sealed partial class CSharpIntroduceVariableService
{
protected override Task<Document> IntroduceFieldAsync(
protected override async Task<Document> IntroduceFieldAsync(
SemanticDocument document,
ExpressionSyntax expression,
bool allOccurrences,
Expand Down Expand Up @@ -68,7 +68,7 @@ protected override Task<Document> IntroduceFieldAsync(
var finalTypeDeclaration = InsertMember(newTypeDeclaration, newFieldDeclaration, insertionIndex);

var newRoot = document.Root.ReplaceNode(oldTypeDeclaration, finalTypeDeclaration);
return Task.FromResult(document.Document.WithSyntaxRoot(newRoot));
return document.Document.WithSyntaxRoot(newRoot);
}
else
{
Expand All @@ -81,7 +81,7 @@ protected override Task<Document> IntroduceFieldAsync(
: DetermineFieldInsertPosition(oldCompilationUnit.Members, newCompilationUnit.Members);

var newRoot = newCompilationUnit.WithMembers(newCompilationUnit.Members.Insert(insertionIndex, newFieldDeclaration));
return Task.FromResult(document.Document.WithSyntaxRoot(newRoot));
return document.Document.WithSyntaxRoot(newRoot);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ protected override void AddEnumUnderlyingTypeSeparator()
Space());
}

protected override Task<ImmutableArray<SymbolDisplayPart>> GetInitializerSourcePartsAsync(
protected override async Task<ImmutableArray<SymbolDisplayPart>> GetInitializerSourcePartsAsync(
ISymbol symbol)
{
// Actually check for C# symbol types here.
if (symbol is IParameterSymbol parameter)
{
return GetInitializerSourcePartsAsync(parameter);
return await GetInitializerSourcePartsAsync(parameter).ConfigureAwait(false);
}
else if (symbol is ILocalSymbol local)
{
return GetInitializerSourcePartsAsync(local);
return await GetInitializerSourcePartsAsync(local).ConfigureAwait(false);
}
else if (symbol is IFieldSymbol field)
{
return GetInitializerSourcePartsAsync(field);
return await GetInitializerSourcePartsAsync(field).ConfigureAwait(false);
}

return SpecializedTasks.EmptyImmutableArray<SymbolDisplayPart>();
return [];
}

protected override ImmutableArray<SymbolDisplayPart> ToMinimalDisplayParts(ISymbol symbol, SemanticModel semanticModel, int position, SymbolDisplayFormat format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ await GetQuickinfoForPragmaWarningAsync(document, token, cancellationToken).Conf
await GetQuickInfoForSuppressMessageAttributeAsync(document, token, cancellationToken).ConfigureAwait(false);
}

protected override Task<QuickInfoItem?> BuildQuickInfoAsync(
protected override async Task<QuickInfoItem?> BuildQuickInfoAsync(
CommonQuickInfoContext context,
SyntaxToken token)
{
// TODO: This provider currently needs access to Document/Project to compute applicable analyzers
// and provide quick info, which is not available in CommonQuickInfoContext.
return Task.FromResult<QuickInfoItem?>(null);
return null;
}

private static async Task<QuickInfoItem?> GetQuickinfoForPragmaWarningAsync(
Expand Down
Loading
Loading