Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc921b55

Browse files
committed
Score .exe command completions from pwsh as files
Fixesmicrosoft#222554
1 parente13f0b7 commitc921b55

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

‎src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -616,54 +616,62 @@ class PersistedWidgetSize {
616616
}
617617
}
618618

619-
exportfunctionparseCompletionsFromShell(rawCompletions:PwshCompletion|PwshCompletion[]|CompressedPwshCompletion[]|CompressedPwshCompletion){
619+
exportfunctionparseCompletionsFromShell(rawCompletions:PwshCompletion|PwshCompletion[]|CompressedPwshCompletion[]|CompressedPwshCompletion):SimpleCompletionItem[]{
620620
if(!rawCompletions){
621621
return[];
622622
}
623+
lettypedRawCompletions:PwshCompletion[];
623624
if(!Array.isArray(rawCompletions)){
624-
return[rawCompletions].map(e=>(newSimpleCompletionItem({
625-
label:parseCompletionText(e.CompletionText,e.ResultType),
626-
icon:pwshTypeToIconMap[e.ResultType],
627-
detail:e.ToolTip,
628-
isFile:e.ResultType===3,
629-
})));
630-
}
631-
if(rawCompletions.length===0){
632-
return[];
633-
}
634-
if(typeofrawCompletions[0]==='string'){
635-
return[rawCompletionsasCompressedPwshCompletion].map(e=>(newSimpleCompletionItem({
636-
label:parseCompletionText(e[0],e[1]),
637-
icon:pwshTypeToIconMap[e[1]],
638-
detail:e[2],
639-
isFile:e[1]===3,
640-
})));
641-
}
642-
if(Array.isArray(rawCompletions[0])){
643-
return(rawCompletionsasCompressedPwshCompletion[]).map(e=>(newSimpleCompletionItem({
644-
label:parseCompletionText(e[0],e[1]),
645-
icon:pwshTypeToIconMap[e[1]],
646-
detail:e[2],
647-
isFile:e[1]===3,
648-
})));
625+
typedRawCompletions=[rawCompletions];
626+
}else{
627+
if(rawCompletions.length===0){
628+
return[];
629+
}
630+
if(typeofrawCompletions[0]==='string'){
631+
typedRawCompletions=[rawCompletionsasCompressedPwshCompletion].map(e=>({
632+
CompletionText:e[0],
633+
ResultType:e[1],
634+
ToolTip:e[2],
635+
}));
636+
}elseif(Array.isArray(rawCompletions[0])){
637+
typedRawCompletions=(rawCompletionsasCompressedPwshCompletion[]).map(e=>({
638+
CompletionText:e[0],
639+
ResultType:e[1],
640+
ToolTip:e[2],
641+
}));
642+
}else{
643+
typedRawCompletions=rawCompletionsasPwshCompletion[];
644+
}
649645
}
650-
return(rawCompletionsasPwshCompletion[]).map(e=>(newSimpleCompletionItem({
651-
label:parseCompletionText(e.CompletionText,e.ResultType),
652-
icon:pwshTypeToIconMap[e.ResultType],
653-
detail:e.ToolTip,
654-
isFile:e.ResultType===3,
655-
})));
646+
returntypedRawCompletions.map(e=>rawCompletionToSimpleCompletionItem(e));
656647
}
657648

658-
functionparseCompletionText(completionText:string,resultType:number):string{
649+
functionrawCompletionToSimpleCompletionItem(rawCompletion:PwshCompletion):SimpleCompletionItem{
659650
// HACK: Somewhere along the way from the powershell script to here, the path separator at the
660651
// end of directories may go missing, likely because `\"` -> `"`. As a result, make sure there
661652
// is a trailing separator at the end of all directory completions. This should not be done for
662653
// `.` and `..` entries because they are optimized not for navigating to different directories
663654
// but for passing as args.
664-
if(resultType===4&&!completionText.match(/^\.\.?$/)&&!completionText.match(/[\\\/]$/)){
665-
constseparator=completionText.match(/(?<sep>[\\\/])/)?.groups?.sep??sep;
666-
returncompletionText+separator;
655+
letlabel=rawCompletion.CompletionText;
656+
if(rawCompletion.ResultType===4&&!label.match(/^\.\.?$/)&&!label.match(/[\\\/]$/)){
657+
constseparator=label.match(/(?<sep>[\\\/])/)?.groups?.sep??sep;
658+
label=label+separator;
667659
}
668-
returncompletionText;
660+
661+
// Pwsh gives executables a result type of 2, but we want to treat them as files wrt the sorting
662+
// and file extension score boost. An example of where this improves the experience is typing
663+
// `git`, `git.exe` should appear at the top and beat `git-lfs.exe`. Keep the same icon though.
664+
consticon=pwshTypeToIconMap[rawCompletion.ResultType];
665+
constisExecutable=rawCompletion.ResultType===2&&rawCompletion.CompletionText.endsWith('.exe');
666+
if(isExecutable){
667+
// icon = Codicon.play;
668+
rawCompletion.ResultType=3;
669+
}
670+
671+
returnnewSimpleCompletionItem({
672+
label,
673+
icon,
674+
detail:rawCompletion.ToolTip,
675+
isFile:rawCompletion.ResultType===3,
676+
});
669677
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp