private static async Task AddParameterCodeActionsAsync( ArrayBuilder <CodeAction> result, Document document, State state, CodeGenerationOptionsProvider fallbackOptions, CancellationToken cancellationToken) { if (state.CanGenerateParameter()) { // Don't generate parameters with a `_` prefix unless that's what the user really wants as their naming style. if (await NameIsHighlyUnlikelyToWarrantSymbolAsync( document, state, SymbolKind.Parameter, Accessibility.NotApplicable, fallbackOptions, cancellationToken).ConfigureAwait(false)) { return; } var containingMethod = state.ContainingMethod; var parameterIndex = containingMethod.Parameters.Length; if (containingMethod.Parameters.Length > 0) { var compilation = await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var cancellationTokenType = compilation.CancellationTokenType(); for (var i = containingMethod.Parameters.Length - 1; i >= 0; i--) { var parameter = containingMethod.Parameters[i]; // Keep moving the insertion position for the generated parameter backwards // until we get to a parameter that does not need to be at the end of the // parameter list. if (parameter.HasExplicitDefaultValue || parameter.IsParams || parameter.RefKind is RefKind.Out || Equals(parameter.Type, cancellationTokenType)) { parameterIndex = i; continue; } break; } // If we are in an extension method, then we want to make sure to insert after // the first parameter. if (containingMethod.IsExtensionMethod && parameterIndex == 0) { parameterIndex = 1; } } result.Add(new GenerateParameterCodeAction(document, state, includeOverridesAndImplementations: false, parameterIndex)); if (AddParameterService.HasCascadingDeclarations(state.ContainingMethod)) { result.Add(new GenerateParameterCodeAction(document, state, includeOverridesAndImplementations: true, parameterIndex)); } } }
protected override Task <Solution?> GetChangedSolutionAsync(CancellationToken cancellationToken) { return(AddParameterService.AddParameterAsync( _document, _state.ContainingMethod, _state.LocalType, RefKind.None, _state.IdentifierToken.ValueText, newParameterIndex: null, _includeOverridesAndImplementations, cancellationToken).AsNullable()); }
private static void AddParameterCodeActions(ArrayBuilder <CodeAction> result, Document document, State state) { if (state.CanGenerateParameter()) { result.Add(new GenerateParameterCodeAction(document, state, includeOverridesAndImplementations: false)); if (AddParameterService.HasCascadingDeclarations(state.ContainingMethod)) { result.Add(new GenerateParameterCodeAction(document, state, includeOverridesAndImplementations: true)); } } }
private static async Task AddParameterCodeActionsAsync( ArrayBuilder <CodeAction> result, Document document, State state, CancellationToken cancellationToken) { if (state.CanGenerateParameter()) { // Don't generate parameters with a `_` prefix unless that's what the user really wants as their naming style. if (await NameIsHighlyUnlikelyToWarrantSymbolAsync( document, state, SymbolKind.Parameter, Accessibility.NotApplicable, cancellationToken).ConfigureAwait(false)) { return; } result.Add(new GenerateParameterCodeAction(document, state, includeOverridesAndImplementations: false)); if (AddParameterService.HasCascadingDeclarations(state.ContainingMethod)) { result.Add(new GenerateParameterCodeAction(document, state, includeOverridesAndImplementations: true)); } } }