Esempio n. 1
0
        public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            CurrentCompilationOptions.Nullability = context.Document.Project.CompilationOptions?.NullableContextOptions.Equals(NullableContextOptions.Enable) ?? true;

            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var node = root.FindToken(context.Span.Start);

            context.Register("Expand enum to union type", UnionTypeCodeProvider.TryGetEnumDeclaration,
                             async(enumDeclaration, c) =>
            {
                var updatedDoc = await UnionTypeCodeProvider.EnumToClass(context.Document, enumDeclaration, c);
                return(updatedDoc.Project.Solution);
            }, node);

            context.Register("Generate 'With' extension", ImmutableHelpersCodeProvider.TryGetClassDeclaration,
                             async(classDeclaration, c) =>
            {
                var updatedDoc = await ImmutableHelpersCodeProvider.GenerateWithExtension(context.Document, classDeclaration, c);
                return(updatedDoc.Project.Solution);
            }, node);

            context.Register(dotFilePath => $"Generate state machine from {Path.GetFileName(dotFilePath)}",
                             _ => StateMachineCodeProvider.TryGetDotFilename(context.Document),
                             async(dotFilePath, c) =>
            {
                var updatedDoc = await StateMachineCodeProvider.GenerateStateMachine(context.Document, dotFilePath, c);
                return(updatedDoc.Project.Solution);
            }, node);
        }
Esempio n. 2
0
        protected override async Task Refactor(AdhocWorkspace workspace, Document document, SyntaxNode root)
        {
            var updatedDoc = await UnionTypeCodeProvider.EnumToClass(
                document,
                root.DescendantNodes().OfType <EnumDeclarationSyntax>().Last(), CancellationToken.None)
                             .ConfigureAwait(false);

            workspace.TryApplyChanges(updatedDoc.Project.Solution);
        }