Innovenergy_trunk/csharp/Lib/SrcGen/ConfigConnectionStringCodeF...

34 lines
1.1 KiB
C#
Raw Normal View History

2023-06-13 11:03:09 +00:00
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);
}
}