using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeRefactorings; namespace InnovEnergy.Lib.SrcGen; [ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = nameof(IeCodeRefactoringProvider))] public sealed class IeCodeRefactoringProvider : CodeRefactoringProvider { // NOT WORKING public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context) { // var root = await context // .Document // .GetSyntaxRootAsync(context.CancellationToken) // .ConfigureAwait(false); await File.WriteAllTextAsync("/home/eef/sync/work/Code/innovenergy/git/csharp/Lib/SrcGen/test.txt", context.Span.ToString()); var action = CodeAction.Create("IeAction", async token => { var text = await context.Document.GetTextAsync(token); var modified = text.Replace(0, 0, "// " + context.Span + "\n"); return context.Document.WithText(modified); }); context.RegisterRefactoring(action); } }