예제 #1
0
 public CodeActionsHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
 }
예제 #2
0
        /// <summary>
        /// Get, order, and filter code actions, and then transform them into VSCodeActions.
        /// </summary>
        /// <remarks>
        /// Used by CodeActionsHandler.
        /// </remarks>
        public static async Task <VSInternalCodeAction[]> GetVSCodeActionsAsync(
            CodeActionParams request,
            CodeActionsCache codeActionsCache,
            Document document,
            CodeActionOptionsProvider fallbackOptions,
            ICodeFixService codeFixService,
            ICodeRefactoringService codeRefactoringService,
            CancellationToken cancellationToken)
        {
            var actionSets = await GetActionSetsAsync(
                document, fallbackOptions, codeFixService, codeRefactoringService, request.Range, cancellationToken).ConfigureAwait(false);

            if (actionSets.IsDefaultOrEmpty)
            {
                return(Array.Empty <VSInternalCodeAction>());
            }

            await codeActionsCache.UpdateActionSetsAsync(document, request.Range, actionSets, cancellationToken).ConfigureAwait(false);

            var documentText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

            // Each suggested action set should have a unique set number, which is used for grouping code actions together.
            var currentHighestSetNumber = 0;

            using var _ = ArrayBuilder <VSInternalCodeAction> .GetInstance(out var codeActions);

            foreach (var set in actionSets)
            {
                var currentSetNumber = ++currentHighestSetNumber;
                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;
                    }

                    // TO-DO: Re-enable code actions involving package manager once supported by LSP.
                    // https://github.com/dotnet/roslyn/issues/48698
                    if (suggestedAction.OriginalCodeAction.Tags.Equals(WellKnownTagArrays.NuGet))
                    {
                        continue;
                    }

                    codeActions.Add(GenerateVSCodeAction(
                                        request, documentText,
                                        suggestedAction: suggestedAction,
                                        codeActionKind: GetCodeActionKindFromSuggestedActionCategoryName(set.CategoryName !),
                                        setPriority: set.Priority,
                                        applicableRange: set.ApplicableToSpan.HasValue ? ProtocolConversions.TextSpanToRange(set.ApplicableToSpan.Value, documentText) : null,
                                        currentSetNumber: currentSetNumber,
                                        currentHighestSetNumber: ref currentHighestSetNumber));
                }
            }

            return(codeActions.ToArray());
        }
예제 #3
0
 public CodeActionsHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IGlobalOptionService globalOptions)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _globalOptions          = globalOptions;
 }
예제 #4
0
 public CodeActionResolveHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     ILspSolutionProvider solutionProvider)
     : base(solutionProvider)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
 }
예제 #5
0
 public CodeActionsHandlerProvider(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IThreadingContext threadingContext
     )
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _threadingContext       = threadingContext;
 }
예제 #6
0
 public RunCodeActionHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IThreadingContext threadingContext)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _threadingContext       = threadingContext;
 }
예제 #7
0
 public CodeActionsHandlerProvider(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IThreadingContext threadingContext,
     IGlobalOptionService globalOptions)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _threadingContext       = threadingContext;
     _globalOptions          = globalOptions;
 }
예제 #8
0
 public CodeActionResolveHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IThreadingContext threadingContext,
     ILspSolutionProvider solutionProvider)
     : base(solutionProvider)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _threadingContext       = threadingContext;
 }
예제 #9
0
 public CodeActionResolveHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IGlobalOptionService globalOptions)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _globalOptions          = globalOptions;
 }
예제 #10
0
 public RunCodeActionHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     ILspSolutionProvider solutionProvider,
     IThreadingContext threadingContext)
 {
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
     _solutionProvider       = solutionProvider;
     _threadingContext       = threadingContext;
 }
예제 #11
0
 public CodeActionsHandler(
     CodeActionsCache codeActionsCache,
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     ILspSolutionProvider solutionProvider)
     : base(solutionProvider)
 {
     _codeActionsCache       = codeActionsCache;
     _codeFixService         = codeFixService;
     _codeRefactoringService = codeRefactoringService;
 }
예제 #12
0
 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);
 }
예제 #15
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);
        }
        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();
        }
예제 #17
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();
        }
예제 #18
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));
        }
예제 #19
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());
        }
        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();
        }
예제 #21
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();
        }
예제 #22
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());
        }
예제 #23
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);
        }
 public XamlCodeActionResolveHandler(
     ICodeFixService codeFixService,
     ICodeRefactoringService codeRefactoringService,
     IGlobalOptionService globalOptions) : base(codeFixService, codeRefactoringService, globalOptions)
 {
 }
 public TypeScriptCodeActionsHandlerShim(ILspSolutionProvider solutionProvider, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
     : base(solutionProvider, codeFixService, codeRefactoringService)
 {
 }
예제 #26
0
 public RoslynRunCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IThreadingContext threadingContext) : base(codeFixService, codeRefactoringService, threadingContext)
 {
 }
예제 #27
0
 public CodeActionsHandlerBase(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
 {
     _codeFixService         = codeFixService ?? throw new ArgumentNullException(nameof(codeFixService));
     _codeRefactoringService = codeRefactoringService ?? throw new ArgumentNullException(nameof(codeRefactoringService));
 }
예제 #28
0
 public static Task <ImmutableArray <CodeRefactoring> > GetRefactoringsAsync(this ICodeRefactoringService service, Document document, TextSpan state, bool isBlocking, CancellationToken cancellationToken)
 => service.GetRefactoringsAsync(document, state, CodeActionRequestPriority.None, isBlocking, addOperationScope: _ => null, cancellationToken);
예제 #29
0
 public static Task <ImmutableArray <CodeRefactoring> > GetRefactoringsAsync(this ICodeRefactoringService service, Document document, TextSpan state, CancellationToken cancellationToken)
 => service.GetRefactoringsAsync(document, state, isBlocking: false, cancellationToken);
예제 #30
0
 public PreviewCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
     : base(codeFixService, codeRefactoringService)
 {
 }
예제 #31
0
 public RunCodeActionsHandler(ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IThreadingContext threadingContext)
     : base(codeFixService, codeRefactoringService)
 {
     _threadingContext = threadingContext;
 }
 public VisualBasicCodeActionsHandlerShim(ILspSolutionProvider solutionProvider, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService)
     : base(solutionProvider, codeFixService, codeRefactoringService)
 {
 }