本文整理汇总了C#中Microsoft.CodeAnalysis.CodeActions.CodeAction类的典型用法代码示例。如果您正苦于以下问题:C# CodeAction类的具体用法?C# CodeAction怎么用?C# CodeAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeAction类属于Microsoft.CodeAnalysis.CodeActions命名空间,在下文中一共展示了CodeAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeFix
internal CodeFix(Project project, CodeAction action, ImmutableArray<Diagnostic> diagnostics)
{
Debug.Assert(!diagnostics.IsDefault);
this.Project = project;
this.Action = action;
this.Diagnostics = diagnostics;
}
示例2: SuggestedActionWithFlavors
protected SuggestedActionWithFlavors(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
CodeAction codeAction,
object provider) : base(workspace, subjectBuffer, editHandler, codeAction, provider)
{
}
示例3: SuggestedActionWithPreview
public SuggestedActionWithPreview(
Workspace workspace, ITextBuffer subjectBuffer, ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator, CodeAction codeAction, object provider,
IAsynchronousOperationListener operationListener)
: base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction,
provider, operationListener, actionSets: null)
{
}
示例4: SuggestedActionWithNestedActions
public SuggestedActionWithNestedActions(
SuggestedActionsSourceProvider sourceProvider, Workspace workspace,
ITextBuffer subjectBuffer, object provider,
CodeAction codeAction, SuggestedActionSet nestedActionSet)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
NestedActionSet = nestedActionSet;
}
示例5: ExecuteCodeAction
private async Task ExecuteCodeAction(CodeAction codeAction)
{
var operations = await codeAction.GetOperationsAsync(CancellationToken.None).ConfigureAwait(true);
foreach (var operation in operations)
{
operation.Apply(_roslynHost.GetDocument(_documentId).Project.Solution.Workspace, CancellationToken.None);
}
}
示例6: CodeRefactoringSuggestedAction
public CodeRefactoringSuggestedAction(
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
CodeRefactoringProvider provider,
CodeAction codeAction)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
}
示例7: RegisterRefactoring
/// <summary>
/// Add supplied <paramref name="action"/> to the list of refactorings that will be offered to the user.
/// </summary>
/// <param name="action">The <see cref="CodeAction"/> that will be invoked to apply the refactoring.</param>
public void RegisterRefactoring(CodeAction action)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
_registerRefactoring(action);
}
示例8: CodeRefactoringSuggestedAction
public CodeRefactoringSuggestedAction(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
CodeAction codeAction,
CodeRefactoringProvider provider)
: base(workspace, subjectBuffer, editHandler, codeAction, provider)
{
}
示例9: SuggestedActionWithNestedFlavors
public SuggestedActionWithNestedFlavors(
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace, ITextBuffer subjectBuffer,
object provider, CodeAction codeAction,
SuggestedActionSet additionalFlavors = null)
: base(sourceProvider, workspace, subjectBuffer,
provider, codeAction)
{
_additionalFlavors = additionalFlavors;
}
示例10: SuggestedActionWithFlavors
protected SuggestedActionWithFlavors(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator,
CodeAction codeAction,
object provider,
IAsynchronousOperationListener operationListener) : base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction, provider, operationListener)
{
}
示例11: CodeRefactoringSuggestedAction
public CodeRefactoringSuggestedAction(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator,
CodeAction codeAction,
CodeRefactoringProvider provider,
IAsynchronousOperationListener operationListener)
: base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction, provider, operationListener)
{
}
示例12: GetFixAllOperationsAsync
private async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext, string fixAllPreviewChangesTitle, bool showPreviewChangesDialog)
{
// We have computed the fix all occurrences code fix.
// Now fetch the new solution with applied fix and bring up the Preview changes dialog.
var cancellationToken = fixAllContext.CancellationToken;
var workspace = fixAllContext.Project.Solution.Workspace;
cancellationToken.ThrowIfCancellationRequested();
var operations = await codeAction.GetOperationsAsync(cancellationToken).ConfigureAwait(false);
if (operations == null)
{
return null;
}
cancellationToken.ThrowIfCancellationRequested();
var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken).ConfigureAwait(false);
if (showPreviewChangesDialog)
{
cancellationToken.ThrowIfCancellationRequested();
using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken))
{
var previewService = workspace.Services.GetService<IPreviewDialogService>();
var glyph = fixAllContext.Project.Language == LanguageNames.CSharp ?
Glyph.CSharpProject :
Glyph.BasicProject;
var changedSolution = previewService.PreviewChanges(
string.Format(EditorFeaturesResources.PreviewChangesOf, fixAllPreviewChangesTitle),
"vs.codefix.fixall",
codeAction.Title,
fixAllPreviewChangesTitle,
glyph,
newSolution,
fixAllContext.Project.Solution);
if (changedSolution == null)
{
// User clicked cancel.
FixAllLogger.LogPreviewChangesResult(applied: false);
return null;
}
FixAllLogger.LogPreviewChangesResult(applied: true, allChangesApplied: changedSolution == newSolution);
newSolution = changedSolution;
}
}
// Get a code action, with apply changes operation replaced with the newSolution.
return GetNewFixAllOperations(operations, newSolution, cancellationToken);
}
示例13: RefactoringPreviewTooltipWindow
public RefactoringPreviewTooltipWindow (TextEditor editor, DocumentContext documentContext, CodeAction codeAction)
{
this.editor = editor;
this.documentContext = documentContext;
this.codeAction = codeAction;
TransientFor = IdeApp.Workbench.RootWindow;
fontDescription = Pango.FontDescription.FromString (DefaultSourceEditorOptions.Instance.FontName);
fontDescription.Size = (int)(fontDescription.Size * 0.8f);
using (var metrics = PangoContext.GetMetrics (fontDescription, PangoContext.Language)) {
lineHeight = (int)Math.Ceiling (0.5 + (metrics.Ascent + metrics.Descent) / Pango.Scale.PangoScale);
}
}
示例14: CodeAction
public static void CodeAction(CodeAction codeAction, Document document, string expectedCode)
{
var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
Assert.That(operations.Count(), Is.EqualTo(1));
var operation = operations.Single();
var workspace = document.Project.Solution.Workspace;
operation.Apply(workspace, CancellationToken.None);
var newDocument = workspace.CurrentSolution.GetDocument(document.Id);
var sourceText = newDocument.GetTextAsync(CancellationToken.None).Result;
var text = sourceText.ToString();
Assert.That(text, Is.EqualTo(expectedCode));
}
示例15: TryGetRedundantLambdaParameterAction
private static bool TryGetRedundantLambdaParameterAction(SyntaxNode syntaxNode, SyntaxNode root,
Document document, out CodeAction action)
{
var parameterList = syntaxNode.Parent?.Parent as ParameterListSyntax;
if (parameterList == null)
{
action = null;
return false;
}
action = CodeAction.Create(TitleRedundantLambdaParameterType, c =>
{
var newParameterList = parameterList.WithParameters(
SyntaxFactory.SeparatedList(parameterList.Parameters.Select(p =>
SyntaxFactory.Parameter(p.Identifier).WithTriviaFrom(p))));
var newRoot = root.ReplaceNode(parameterList, newParameterList);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}, TitleRedundantLambdaParameterType);
return true;
}