Skip to content

Commit a688be7

Browse files
committed
Fix completion text for clients which don’t support TextEdit
We could set the `Label` to `CompletionText` as the fallback, but that then makes the list of completions in fancier clients not as accurate (since PowerShell explicitly provides `ListItemText` for this purpose). Instead, we set usually unused field `InsertText` with the same information we provided for more advanced clients in `TextEdit`.
1 parent 78f8fb7 commit a688be7

File tree

6 files changed

+9
-1
lines changed

6 files changed

+9
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ internal static CompletionItem CreateCompletionItem(
185185
// Retain PowerShell's sort order with the given index.
186186
SortText = $"{sortIndex:D4}{result.ListItemText}",
187187
FilterText = result.CompletionText,
188-
TextEdit = textEdit // Used instead of InsertText.
188+
// Used instead of Label when TextEdit is unsupported
189+
InsertText = result.CompletionText,
190+
// Used instead of InsertText when possible
191+
TextEdit = textEdit
189192
};
190193

191194
return result.ResultType switch

test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal static class CompleteCommandFromModule
2626
Kind = CompletionItemKind.Function,
2727
Detail = "", // OS-dependent, checked separately.
2828
FilterText = "Get-Random",
29+
InsertText = "Get-Random",
2930
Label = "Get-Random",
3031
SortText = "0001Get-Random",
3132
TextEdit = new TextEdit

test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandInFile.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal static class CompleteCommandInFile
2323
Kind = CompletionItemKind.Function,
2424
Detail = "",
2525
FilterText = "Get-Something",
26+
InsertText = "Get-Something",
2627
Label = "Get-Something",
2728
SortText = "0001Get-Something",
2829
TextEdit = new TextEdit

test/PowerShellEditorServices.Test.Shared/Completion/CompleteNamespace.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal static class CompleteNamespace
2323
Kind = CompletionItemKind.Module,
2424
Detail = "Namespace System.Collections",
2525
FilterText = "System.Collections",
26+
InsertText = "System.Collections",
2627
Label = "Collections",
2728
SortText = "0001Collections",
2829
TextEdit = new TextEdit

test/PowerShellEditorServices.Test.Shared/Completion/CompleteTypeName.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal static class CompleteTypeName
2323
Kind = CompletionItemKind.TypeParameter,
2424
Detail = "System.Collections.ArrayList",
2525
FilterText = "System.Collections.ArrayList",
26+
InsertText = "System.Collections.ArrayList",
2627
Label = "ArrayList",
2728
SortText = "0001ArrayList",
2829
TextEdit = new TextEdit

test/PowerShellEditorServices.Test.Shared/Completion/CompleteVariableInFile.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal static class CompleteVariableInFile
2323
Kind = CompletionItemKind.Variable,
2424
Detail = "", // Same as label, so not shown.
2525
FilterText = "$testVar1",
26+
InsertText = "$testVar1",
2627
Label = "testVar1",
2728
SortText = "0001testVar1",
2829
TextEdit = new TextEdit

0 commit comments

Comments
 (0)