public async static Task Run(MonoDevelop.Ide.Gui.Document doc) { var ad = doc.AnalysisDocument; if (ad == null) { return; } try { var model = await ad.GetSemanticModelAsync(default(CancellationToken)); var root = model.SyntaxTree.GetRoot(default(CancellationToken)); var newDocument = service.RemoveUnnecessaryImports(ad, model, root, default(CancellationToken)); ad.Project.Solution.Workspace.ApplyDocumentChanges(newDocument, CancellationToken.None); } catch (Exception e) { LoggingService.LogError("Error while removing unused usings", e); } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var span = context.Span; var cancellationToken = context.CancellationToken; var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var newDocument = service.RemoveUnnecessaryImports(document, model, root, cancellationToken); if (newDocument == document || newDocument == null) { return; } context.RegisterCodeFix( new DocumentChangeAction(context.Diagnostics[0].Location.SourceSpan, DiagnosticSeverity.Warning, GettextCatalog.GetString("Remove Unnecessary Usings"), (c) => Task.FromResult(newDocument)), context.Diagnostics); }