@@ -431,13 +431,15 @@ await editorSession.LanguageService.GetCompletionsInFile(
431
431
432
432
if ( completionResults != null )
433
433
{
434
+ int sortIndex = 1 ;
434
435
completionItems =
435
436
completionResults
436
437
. Completions
437
438
. Select (
438
439
c => CreateCompletionItem (
439
440
c ,
440
- completionResults . ReplacedRange ) )
441
+ completionResults . ReplacedRange ,
442
+ sortIndex ++ ) )
441
443
. ToArray ( ) ;
442
444
}
443
445
else
@@ -982,7 +984,8 @@ private static CompletionItemKind MapCompletionKind(CompletionType completionTyp
982
984
983
985
private static CompletionItem CreateCompletionItem (
984
986
CompletionDetails completionDetails ,
985
- BufferRange completionRange )
987
+ BufferRange completionRange ,
988
+ int sortIndex )
986
989
{
987
990
string detailString = null ;
988
991
string documentationString = null ;
@@ -1031,13 +1034,26 @@ private static CompletionItem CreateCompletionItem(
1031
1034
}
1032
1035
}
1033
1036
1037
+ // We want a special "sort order" for parameters that is not lexicographical.
1038
+ // Fortunately, PowerShell returns parameters in the preferred sort order by
1039
+ // default (with common params at the end). We just need to make sure the default
1040
+ // order also be the lexicographical order which we do by prefixig the ListItemText
1041
+ // with a leading 0's four digit index. This would not sort correctly for a list
1042
+ // > 999 parameters but surely we won't have so many items in the "parameter name"
1043
+ // completion list. Technically we don't need the ListItemText at all but it may come
1044
+ // in handy during debug.
1045
+ var sortText = ( completionDetails . CompletionType == CompletionType . ParameterName )
1046
+ ? string . Format ( "{0:D3}{1}" , sortIndex , completionDetails . ListItemText )
1047
+ : null ;
1048
+
1034
1049
return new CompletionItem
1035
1050
{
1036
1051
InsertText = completionDetails . CompletionText ,
1037
1052
Label = labelString ,
1038
1053
Kind = MapCompletionKind ( completionDetails . CompletionType ) ,
1039
1054
Detail = detailString ,
1040
1055
Documentation = documentationString ,
1056
+ SortText = sortText ,
1041
1057
TextEdit = new TextEdit
1042
1058
{
1043
1059
NewText = completionDetails . CompletionText ,
0 commit comments