Skip to content

Commit 6cb1132

Browse files
use edit
1 parent 8f21759 commit 6cb1132

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ public async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request,
9191
{
9292
Title = correction.Name,
9393
Kind = CodeActionKind.QuickFix,
94-
Diagnostics = new Container<Diagnostic>(diagnostic),
95-
Command = new Command
94+
Edit = new WorkspaceEdit
9695
{
97-
Title = correction.Name,
98-
Name = "PowerShell.ApplyCodeActionEdits",
99-
Arguments = JArray.FromObject(correction.Edits)
96+
DocumentChanges = new Container<WorkspaceEditDocumentChange>(
97+
new WorkspaceEditDocumentChange(
98+
new TextDocumentEdit()
99+
{
100+
TextDocument = new VersionedTextDocumentIdentifier()
101+
{
102+
Uri = request.TextDocument.Uri
103+
},
104+
Edits = new Container<TextEdit>(correction.Edits.Select(ScriptRegion.ToTextEdit))
105+
}))
100106
}
101107
});
102108
}

src/PowerShellEditorServices/Services/TextDocument/ScriptRegion.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System;
77
using System.Management.Automation.Language;
8+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
89

910
namespace Microsoft.PowerShell.EditorServices.Services.TextDocument
1011
{
@@ -49,6 +50,27 @@ public static ScriptRegion Create(IScriptExtent scriptExtent)
4950
scriptExtent.EndOffset);
5051
}
5152

53+
internal static TextEdit ToTextEdit(ScriptRegion scriptRegion)
54+
{
55+
return new TextEdit
56+
{
57+
NewText = scriptRegion.Text,
58+
Range = new Range
59+
{
60+
Start = new Position
61+
{
62+
Line = scriptRegion.StartLineNumber - 1,
63+
Character = scriptRegion.StartColumnNumber - 1,
64+
},
65+
End = new Position
66+
{
67+
Line = scriptRegion.EndLineNumber - 1,
68+
Character = scriptRegion.EndColumnNumber - 1,
69+
}
70+
}
71+
};
72+
}
73+
5274
#endregion
5375

5476
#region Constructors

0 commit comments

Comments
 (0)