コード例 #1
0
 public RunCodeActionHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     ILspSolutionProvider solutionProvider,
     IThreadingContext threadingContext)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _solutionProvider       = solutionProvider;
     _threadingContext       = threadingContext;
 }
コード例 #2
0
 public CodeActionResolveHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     ILspSolutionProvider solutionProvider)
     : base(solutionProvider)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
 }
コード例 #3
0
 public RunCodeActionHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IThreadingContext threadingContext)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _threadingContext       = threadingContext;
 }
コード例 #4
0
 public CodeActionsHandlerProvider(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IThreadingContext threadingContext,
     IGlobalOptionService globalOptions)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _threadingContext       = threadingContext;
     _globalOptions          = globalOptions;
 }
コード例 #5
0
 public CodeActionResolveHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IGlobalOptionService globalOptions)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _globalOptions          = globalOptions;
 }
コード例 #6
0
 public RunCodeActionHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IGlobalOptionService globalOptions,
     IThreadingContext threadingContext)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _globalOptions          = globalOptions;
     _threadingContext       = threadingContext;
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 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);
 }
コード例 #9
0
        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);
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        /// <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());
        }
コード例 #16
0
        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;
        }
コード例 #17
0
        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();
        }
コード例 #18
0
        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();
        }
コード例 #19
0
            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));
            }
コード例 #20
0
        /// <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());
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        /// <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);
        }
コード例 #23
0
 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);
コード例 #24
0
 public RoslynContextActionProvider(DocumentId documentId, IRoslynHost roslynHost)
 {
     _documentId     = documentId;
     _roslynHost     = roslynHost;
     _codeFixService = _roslynHost.GetService <ICodeFixService>();
 }
コード例 #25
0
 protected AbstractCodeCleanupService(ICodeFixService codeFixService, IDiagnosticAnalyzerService diagnosticAnalyzerService)
 {
     _codeFixService    = codeFixService;
     _diagnosticService = diagnosticAnalyzerService;
 }
コード例 #26
0
 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)));
 }
コード例 #27
0
        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());
        }
コード例 #28
0
 public CodeActionsHandlerBase(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
 {
     _codeFixService         = codeFixService ?? throw new ArgumentNullException(nameof(codeFixService));
     _codeRefactoringService = codeRefactoringService ?? throw new ArgumentNullException(nameof(codeRefactoringService));
 }
コード例 #29
0
 protected AbstractCodeCleanupService(ICodeFixService codeFixService)
 {
     _codeFixService = codeFixService;
 }
コード例 #30
0
 public PreviewCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
     : base(codeFixService, codeRefactoringService)
 {
 }
コード例 #31
0
            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);
            }
コード例 #32
0
 public RoslynContextActionProvider(DocumentId documentId, RoslynHost roslynHost)
 {
     _documentId = documentId;
     _roslynHost = roslynHost;
     _codeFixService = _roslynHost.GetService<ICodeFixService>();
 }
コード例 #33
0
 public static Task <ImmutableArray <CodeFixCollection> > GetFixesAsync(this ICodeFixService service, Document document, TextSpan range, CancellationToken cancellationToken)
 => service.GetFixesAsync(document, range, isBlocking: false, cancellationToken);
コード例 #34
0
 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);
コード例 #35
0
 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));
 }
コード例 #36
0
 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);
コード例 #37
0
 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);