Skip to content

Preserve PowerShell's CommandCompletion result sort order in VS Code #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,17 +1506,12 @@ private static CompletionItem CreateCompletionItem(
}
}

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

return new CompletionItem
{
Expand Down