Skip to content

Commit 0d45376

Browse files
committed
Preserve PowerShell's CommandCompletion result sort order in VS Code
This change causes VS Code to preserve PowerShell's original CommandCompletion result sort order by creating SortText entries for every completion result, not just parameters. Resolves PowerShell/vscode-powershell#579.
1 parent dc9223e commit 0d45376

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1506,17 +1506,12 @@ private static CompletionItem CreateCompletionItem(
15061506
}
15071507
}
15081508

1509-
// We want a special "sort order" for parameters that is not lexicographical.
1510-
// Fortunately, PowerShell returns parameters in the preferred sort order by
1511-
// default (with common params at the end). We just need to make sure the default
1512-
// order also be the lexicographical order which we do by prefixig the ListItemText
1513-
// with a leading 0's four digit index. This would not sort correctly for a list
1514-
// > 999 parameters but surely we won't have so many items in the "parameter name"
1515-
// completion list. Technically we don't need the ListItemText at all but it may come
1516-
// in handy during debug.
1517-
var sortText = (completionDetails.CompletionType == CompletionType.ParameterName)
1518-
? $"{sortIndex:D3}{completionDetails.ListItemText}"
1519-
: null;
1509+
// Force the client to maintain the sort order in which the
1510+
// original completion results were returned. We just need to
1511+
// make sure the default order also be the lexicographical order
1512+
// which we do by prefixing the ListItemText with a leading 0's
1513+
// four digit index.
1514+
var sortText = $"{sortIndex:D4}{completionDetails.ListItemText}";
15201515

15211516
return new CompletionItem
15221517
{

0 commit comments

Comments
 (0)