public RunCodeActionHandler( ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, ILspSolutionProvider solutionProvider, IThreadingContext threadingContext) { _codeFixService = codeFixService; _codeRefactoringService = codeRefactoringService; _solutionProvider = solutionProvider; _threadingContext = threadingContext; }
public CodeActionResolveHandler( CodeActionsCache codeActionsCache, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, ILspSolutionProvider solutionProvider) : base(solutionProvider) { _codeActionsCache = codeActionsCache; _codeFixService = codeFixService; _codeRefactoringService = codeRefactoringService; }
public RunCodeActionHandler( CodeActionsCache codeActionsCache, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IThreadingContext threadingContext) { _codeActionsCache = codeActionsCache; _codeFixService = codeFixService; _codeRefactoringService = codeRefactoringService; _threadingContext = threadingContext; }
public CodeActionsHandlerProvider( ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IThreadingContext threadingContext, IGlobalOptionService globalOptions) { _codeFixService = codeFixService; _codeRefactoringService = codeRefactoringService; _threadingContext = threadingContext; _globalOptions = globalOptions; }
public CodeActionResolveHandler( CodeActionsCache codeActionsCache, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IGlobalOptionService globalOptions) { _codeActionsCache = codeActionsCache; _codeFixService = codeFixService; _codeRefactoringService = codeRefactoringService; _globalOptions = globalOptions; }
public RunCodeActionHandler( ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IGlobalOptionService globalOptions, IThreadingContext threadingContext) { _codeFixService = codeFixService; _codeRefactoringService = codeRefactoringService; _globalOptions = globalOptions; _threadingContext = threadingContext; }
public SuggestedActionsSourceProvider( ICodeRefactoringService codeRefactoringService, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandler, [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners) { _codeRefactoringService = codeRefactoringService; _diagnosticService = diagnosticService; _codeFixService = codeFixService; _editHandler = editHandler; _listener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.LightBulb); }
public SuggestedActionsSourceProvider( ICodeRefactoringService codeRefactoringService, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandler, [ImportMany] IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners) { _codeRefactoringService = codeRefactoringService; _diagnosticService = diagnosticService; _codeFixService = codeFixService; _editHandler = editHandler; _listener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.LightBulb); }
public static async Task <IEnumerable <CodeAction> > GetCodeActionsAsync( Document document, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, LSP.Range selection, CancellationToken cancellationToken) { var(codeFixCollections, codeRefactorings) = await GetCodeFixesAndRefactoringsAsync( document, codeFixService, codeRefactoringService, selection, cancellationToken).ConfigureAwait(false); var codeActions = codeFixCollections.SelectMany(c => c.Fixes.Select(f => f.Action)).Concat( codeRefactorings.SelectMany(r => r.CodeActions.Select(ca => ca.action))); return(codeActions); }
public VisualStudioSuppressionFixService( SVsServiceProvider serviceProvider, VisualStudioWorkspaceImpl workspace, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, IVisualStudioDiagnosticListSuppressionStateService suppressionStateService, IWaitIndicator waitIndicator) { _workspace = workspace; _diagnosticService = diagnosticService; _codeFixService = codeFixService; _suppressionStateService = (VisualStudioDiagnosticListSuppressionStateService)suppressionStateService; _waitIndicator = waitIndicator; _fixMultipleOccurencesService = workspace.Services.GetService<IFixMultipleOccurrencesService>(); var errorList = serviceProvider.GetService(typeof(SVsErrorList)) as IErrorList; _tableControl = errorList?.TableControl; }
public SuggestedActionsSourceProvider( ICodeRefactoringService codeRefactoringService, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandler, IWaitIndicator waitIndicator, [ImportMany] IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners, [ImportMany] IEnumerable <Lazy <IImageMonikerService, OrderableMetadata> > imageMonikerServices) { _codeRefactoringService = codeRefactoringService; _diagnosticService = diagnosticService; _codeFixService = codeFixService; EditHandler = editHandler; WaitIndicator = waitIndicator; OperationListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.LightBulb); ImageMonikerServices = ExtensionOrderer.Order(imageMonikerServices).ToImmutableArray(); }
public static async Task <(ImmutableArray <CodeFixCollection>, ImmutableArray <CodeRefactoring>)> GetCodeFixesAndRefactoringsAsync( Document document, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, LSP.Range selection, CancellationToken cancellationToken) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var textSpan = ProtocolConversions.RangeToTextSpan(selection, text); var codeFixCollectionsTask = codeFixService.GetFixesAsync(document, textSpan, includeSuppressionFixes: true, cancellationToken); var codeRefactoringsTask = codeRefactoringService.GetRefactoringsAsync(document, textSpan, cancellationToken); await Task.WhenAll(codeFixCollectionsTask, codeRefactoringsTask).ConfigureAwait(false); return(await codeFixCollectionsTask.ConfigureAwait(false), await codeRefactoringsTask.ConfigureAwait(false)); }
public SuggestedActionsSourceProvider( ICodeRefactoringService codeRefactoringService, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandler, IWaitIndicator waitIndicator, [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners, [ImportMany] IEnumerable<Lazy<IImageMonikerService, OrderableMetadata>> imageMonikerServices) { _codeRefactoringService = codeRefactoringService; _diagnosticService = diagnosticService; _codeFixService = codeFixService; EditHandler = editHandler; WaitIndicator = waitIndicator; OperationListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.LightBulb); ImageMonikerServices = ExtensionOrderer.Order(imageMonikerServices).ToImmutableArray(); }
/// <summary> /// Gets, filters, and orders code fixes. /// </summary> public static async ValueTask <ImmutableArray <UnifiedSuggestedActionSet> > GetFilterAndOrderCodeFixesAsync( Workspace workspace, ICodeFixService codeFixService, Document document, TextSpan selection, bool isBlocking, Func <string, IDisposable?> addOperationScope, CancellationToken cancellationToken) { // Intentionally switch to a threadpool thread to compute fixes. We do not want to accidentally // run any of this on the UI thread and potentially allow any code to take a dependency on that. var fixes = await Task.Run(() => codeFixService.GetFixesAsync( document, selection, includeSuppressionFixes: true, isBlocking, addOperationScope, cancellationToken), cancellationToken).ConfigureAwait(false); var filteredFixes = fixes.WhereAsArray(c => c.Fixes.Length > 0); var organizedFixes = OrganizeFixes(workspace, filteredFixes); return(organizedFixes); }
/// <summary> /// Get, order, and filter code actions. /// </summary> /// <remarks> /// Used by CodeActionResolveHandler and RunCodeActionHandler. /// </remarks> public static async Task <ImmutableArray <CodeAction> > GetCodeActionsAsync( CodeActionsCache codeActionsCache, Document document, LSP.Range selection, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, CancellationToken cancellationToken) { var actionSets = await GetActionSetsAsync( document, codeFixService, codeRefactoringService, selection, cancellationToken).ConfigureAwait(false); if (!actionSets.HasValue) { actionSets = await GetActionSetsAsync( document, codeFixService, codeRefactoringService, selection, cancellationToken).ConfigureAwait(false); if (!actionSets.HasValue) { return(ImmutableArray <CodeAction> .Empty); } await codeActionsCache.UpdateActionSetsAsync(document, selection, actionSets.Value, cancellationToken).ConfigureAwait(false); } var _ = ArrayBuilder <CodeAction> .GetInstance(out var codeActions); foreach (var set in actionSets) { foreach (var suggestedAction in set.Actions) { // Filter out code actions with options since they'll show dialogs and we can't remote the UI and the options. if (suggestedAction.OriginalCodeAction is CodeActionWithOptions) { continue; } codeActions.Add(GetNestedActionsFromActionSet(suggestedAction)); } } return(codeActions.ToImmutable()); }
public VisualStudioSuppressionFixService( SVsServiceProvider serviceProvider, VisualStudioWorkspaceImpl workspace, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandlerService, IVisualStudioDiagnosticListSuppressionStateService suppressionStateService, IWaitIndicator waitIndicator) { _workspace = workspace; _diagnosticService = diagnosticService; _codeFixService = codeFixService; _suppressionStateService = (VisualStudioDiagnosticListSuppressionStateService)suppressionStateService; _editHandlerService = editHandlerService; _waitIndicator = waitIndicator; _fixMultipleOccurencesService = workspace.Services.GetService <IFixMultipleOccurrencesService>(); var errorList = serviceProvider.GetService(typeof(SVsErrorList)) as IErrorList; _tableControl = errorList?.TableControl; }
public SuggestedActionsSourceProvider( ICodeRefactoringService codeRefactoringService, IDiagnosticAnalyzerService diagnosticService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandler, IWaitIndicator waitIndicator, ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry, IAsynchronousOperationListenerProvider listenerProvider, [ImportMany] IEnumerable <Lazy <IImageMonikerService, OrderableMetadata> > imageMonikerServices, [ImportMany] IEnumerable <Lazy <ISuggestedActionCallback> > actionCallbacks) { _codeRefactoringService = codeRefactoringService; _diagnosticService = diagnosticService; _codeFixService = codeFixService; _suggestedActionCategoryRegistry = suggestedActionCategoryRegistry; ActionCallbacks = actionCallbacks.ToImmutableArray(); EditHandler = editHandler; WaitIndicator = waitIndicator; OperationListener = listenerProvider.GetListener(FeatureAttribute.LightBulb); ImageMonikerServices = ExtensionOrderer.Order(imageMonikerServices).ToImmutableArray(); }
public SuggestedActionsSourceProvider( IThreadingContext threadingContext, ICodeRefactoringService codeRefactoringService, ICodeFixService codeFixService, ICodeActionEditHandlerService editHandler, IUIThreadOperationExecutor uiThreadOperationExecutor, ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry, IAsynchronousOperationListenerProvider listenerProvider, IGlobalOptionService globalOptions, [ImportMany] IEnumerable <Lazy <IImageIdService, OrderableMetadata> > imageIdServices) { _threadingContext = threadingContext; _codeRefactoringService = codeRefactoringService; _codeFixService = codeFixService; _suggestedActionCategoryRegistry = suggestedActionCategoryRegistry; _globalOptions = globalOptions; EditHandler = editHandler; UIThreadOperationExecutor = uiThreadOperationExecutor; OperationListener = listenerProvider.GetListener(FeatureAttribute.LightBulb); ImageIdServices = ExtensionOrderer.Order(imageIdServices).ToImmutableArray(); }
private static async Task <FirstDiagnosticResult?> HasSuggesetedActionCoreAsync( ITextView view, ITextBuffer buffer, ICodeFixService service, SnapshotSpan range, CancellationToken cancellationToken) { var documentAndSnapshot = await GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).ConfigureAwait(false); if (!documentAndSnapshot.HasValue) { return(null); } var document = documentAndSnapshot.Value.Item1; // make sure current document support codefix var supportCodeFix = document.Project.Solution.Workspace.Services.GetService <IDocumentSupportsSuggestionService>(); if (!supportCodeFix.SupportsCodeFixes(document)) { return(null); } return(await service.GetFirstDiagnosticWithFixAsync(document, range.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Get, order, and filter code actions, and then transform them into VSCodeActions. /// </summary> /// <remarks> /// Used by CodeActionsHandler. /// </remarks> public static async Task <VSCodeAction[]> GetVSCodeActionsAsync( CodeActionParams request, CodeActionsCache codeActionsCache, Document document, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, CancellationToken cancellationToken) { var actionSets = await GetActionSetsAsync( document, codeFixService, codeRefactoringService, request.Range, cancellationToken).ConfigureAwait(false); if (!actionSets.HasValue) { return(Array.Empty <VSCodeAction>()); } await codeActionsCache.UpdateActionSetsAsync(document, request.Range, actionSets.Value, cancellationToken).ConfigureAwait(false); var _ = ArrayBuilder <VSCodeAction> .GetInstance(out var codeActions); foreach (var set in actionSets) { foreach (var suggestedAction in set.Actions) { // Filter out code actions with options since they'll show dialogs and we can't remote the UI and the options. if (suggestedAction.OriginalCodeAction is CodeActionWithOptions) { continue; } codeActions.Add(GenerateVSCodeAction( request, GetNestedActionsFromActionSet(suggestedAction), GetCodeActionKindFromSuggestedActionCategoryName(set.CategoryName !))); } } return(codeActions.ToArray()); }
private static async Task <ImmutableArray <UnifiedSuggestedActionSet>?> GetActionSetsAsync( Document document, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, LSP.Range selection, CancellationToken cancellationToken) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var textSpan = ProtocolConversions.RangeToTextSpan(selection, text); var codeFixes = await UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync( document.Project.Solution.Workspace, codeFixService, document, textSpan, includeSuppressionFixes : true, isBlocking : false, addOperationScope : _ => null, cancellationToken).ConfigureAwait(false); var codeRefactorings = await UnifiedSuggestedActionsSource.GetFilterAndOrderCodeRefactoringsAsync( document.Project.Solution.Workspace, codeRefactoringService, document, textSpan, isBlocking : false, addOperationScope : _ => null, filterOutsideSelection : false, cancellationToken).ConfigureAwait(false); var actionSets = UnifiedSuggestedActionsSource.FilterAndOrderActionSets(codeFixes, codeRefactorings, textSpan); return(actionSets); }
/// <summary> /// Gets, filters, and orders code fixes. /// </summary> public static async Task <ImmutableArray <UnifiedSuggestedActionSet> > GetFilterAndOrderCodeFixesAsync( Workspace workspace, ICodeFixService codeFixService, Document document, TextSpan selection, bool includeSuppressionFixes, bool isBlocking, Func <string, IDisposable?> addOperationScope, CancellationToken cancellationToken) { // It may seem strange that we kick off a task, but then immediately 'Wait' on // it. However, it's deliberate. We want to make sure that the code runs on // the background so that no one takes an accidentally dependency on running on // the UI thread. var fixes = await Task.Run( () => codeFixService.GetFixesAsync( document, selection, includeSuppressionFixes, isBlocking, addOperationScope, cancellationToken), cancellationToken).ConfigureAwait(false); var filteredFixes = fixes.WhereAsArray(c => c.Fixes.Length > 0); var organizedFixes = OrganizeFixes(workspace, filteredFixes, includeSuppressionFixes); return(organizedFixes); }
public static Task <ImmutableArray <CodeFixCollection> > GetFixesAsync(this ICodeFixService service, Document document, TextSpan range, CodeActionOptionsProvider options, bool isBlocking, CancellationToken cancellationToken) => service.StreamFixesAsync(document, range, options, isBlocking, cancellationToken).ToImmutableArrayAsync(cancellationToken);
public RoslynContextActionProvider(DocumentId documentId, IRoslynHost roslynHost) { _documentId = documentId; _roslynHost = roslynHost; _codeFixService = _roslynHost.GetService <ICodeFixService>(); }
protected AbstractCodeCleanupService(ICodeFixService codeFixService, IDiagnosticAnalyzerService diagnosticAnalyzerService) { _codeFixService = codeFixService; _diagnosticService = diagnosticAnalyzerService; }
private static CodeFixProvider?GetSuppressionFixer(IEnumerable <Diagnostic> diagnostics, string language, ICodeFixService codeFixService) { // Fetch the suppression fixer to apply the fix. return(codeFixService.GetSuppressionFixer(language, diagnostics.Select(d => d.Id))); }
private static CodeFixProvider GetSuppressionFixer(IEnumerable<Diagnostic> diagnostics, string language, ICodeFixService codeFixService) { var allDiagnosticsBuilder = ImmutableArray.CreateBuilder<Diagnostic>(); foreach (var documentDiagnostics in diagnostics) { allDiagnosticsBuilder.AddRange(diagnostics); } // Fetch the suppression fixer to apply the fix. return codeFixService.GetSuppressionFixer(language, allDiagnosticsBuilder.ToImmutable()); }
public CodeActionsHandlerBase(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService) { _codeFixService = codeFixService ?? throw new ArgumentNullException(nameof(codeFixService)); _codeRefactoringService = codeRefactoringService ?? throw new ArgumentNullException(nameof(codeRefactoringService)); }
protected AbstractCodeCleanupService(ICodeFixService codeFixService) { _codeFixService = codeFixService; }
public PreviewCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService) : base(codeFixService, codeRefactoringService) { }
private static async Task<FirstDiagnosticResult?> HasSuggesetedActionCoreAsync( ITextView view, ITextBuffer buffer, ICodeFixService service, SnapshotSpan range, CancellationToken cancellationToken) { var documentAndSnapshot = await GetMatchingDocumentAndSnapshotAsync(range.Snapshot, cancellationToken).ConfigureAwait(false); if (!documentAndSnapshot.HasValue) { return null; } var document = documentAndSnapshot.Value.Item1; // make sure current document support codefix var supportCodeFix = document.Project.Solution.Workspace.Services.GetService<IDocumentSupportsSuggestionService>(); if (!supportCodeFix.SupportsCodeFixes(document)) { return null; } return await service.GetFirstDiagnosticWithFixAsync(document, range.Span.ToTextSpan(), cancellationToken).ConfigureAwait(false); }
public RoslynContextActionProvider(DocumentId documentId, RoslynHost roslynHost) { _documentId = documentId; _roslynHost = roslynHost; _codeFixService = _roslynHost.GetService<ICodeFixService>(); }
public static Task <ImmutableArray <CodeFixCollection> > GetFixesAsync(this ICodeFixService service, Document document, TextSpan range, CancellationToken cancellationToken) => service.GetFixesAsync(document, range, isBlocking: false, cancellationToken);
public static IAsyncEnumerable <CodeFixCollection> StreamFixesAsync(this ICodeFixService service, Document document, TextSpan range, CodeActionOptionsProvider options, bool isBlocking, CancellationToken cancellationToken) => service.StreamFixesAsync(document, range, CodeActionRequestPriority.None, options, isBlocking, addOperationScope: _ => null, cancellationToken);
private static CodeFixProvider GetSuppressionFixer(IEnumerable<Diagnostic> diagnostics, string language, ICodeFixService codeFixService) { // Fetch the suppression fixer to apply the fix. return codeFixService.GetSuppressionFixer(language, diagnostics.Select(d => d.Id)); }
public static Task <ImmutableArray <CodeFixCollection> > GetFixesAsync(this ICodeFixService service, Document document, TextSpan range, bool isBlocking, CancellationToken cancellationToken) => service.GetFixesAsync(document, range, CodeActionRequestPriority.None, isBlocking, addOperationScope: _ => null, cancellationToken);
public static Task <ImmutableArray <CodeFixCollection> > GetFixesAsync(this ICodeFixService service, Document document, TextSpan textSpan, CodeActionRequestPriority priority, CodeActionOptionsProvider options, bool isBlocking, Func <string, IDisposable?> addOperationScope, CancellationToken cancellationToken) => service.StreamFixesAsync(document, textSpan, priority, options, isBlocking, addOperationScope, cancellationToken).ToImmutableArrayAsync(cancellationToken);