8000 Make sure \ appears at end of dir results on Windows · githubnext/vscode@dfeaf15 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfeaf15

Browse files
committed
Make sure \ appears at end of dir results on Windows
Fixes microsoft#222230
1 parent 85e01ef commit dfeaf15

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,10 @@ function Send-Completions {
240240
# Add trailing \ for directories so behavior aligns with TabExpansion2
241241
[System.Management.Automation.CompletionCompleters]::CompleteFilename($completionPrefix) | ForEach-Object {
242242
if ($_.ResultType -eq [System.Management.Automation.CompletionResultType]::ProviderContainer) {
243-
[System.Management.Automation.CompletionResult]::new($_.CompletionText + [System.IO.Path]::DirectorySeparatorChar, $_.ListItemText + [System.IO.Path]::DirectorySeparatorChar, $_.ResultType, $_.ToolTip)
243+
[System.Management.Automation.CompletionResult]::new("$($_.CompletionText)$([System.IO.Path]::DirectorySeparatorChar)", "$($_.CompletionText)$([System.IO.Path]::DirectorySeparatorChar)", $_.ResultType, $_.ToolTip)
244+
} else {
245+
$_
244246
}
245-
$_
246247
}
247248
([System.Management.Automation.CompletionCompleters]::CompleteVariable($completionPrefix));
248249
)

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { getListStyles } from 'vs/platform/theme/browser/defaultStyles';
2727
import type { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
2828
import { terminalSuggestConfigSection, type ITerminalSuggestConfiguration } from 'vs/workbench/contrib/terminalContrib/suggest/common/terminalSuggestConfiguration';
2929
import { commonPrefixLength } from 'vs/base/common/strings';
30+
import { sep } from 'vs/base/common/path';
3031

3132
export const enum VSCodeSuggestOscPt {
3233
Completions = 'Completions',
@@ -611,7 +612,7 @@ export function parseCompletionsFromShell(rawCompletions: PwshCompletion | PwshC
611612
}
612613
if (!Array.isArray(rawCompletions)) {
613614
return [rawCompletions].map(e => (new SimpleCompletionItem({
614-
label: e.CompletionText,
615+
label: parseCompletionText(e.CompletionText, e.ResultType),
615616
icon: pwshTypeToIconMap[e.ResultType],
616617
detail: e.ToolTip,
617618
isFile: e.ResultType === 3,
@@ -622,24 +623,37 @@ export function parseCompletionsFromShell(rawCompletions: PwshCompletion | PwshC
622623
}
623624
if (typeof rawCompletions[0] === 'string') {
624625
return [rawCompletions as CompressedPwshCompletion].map(e => (new SimpleCompletionItem({
625-
label: e[0],
626+
label: parseCompletionText(e[0], e[1]),
626627
icon: pwshTypeToIconMap[e[1]],
627628
detail: e[2],
628629
isFile: e[1] === 3,
629630
})));
630631
}
631632
if (Array.isArray(rawCompletions[0])) {
632633
return (rawCompletions as CompressedPwshCompletion[]).map(e => (new SimpleCompletionItem({
633-
label: e[0],
634+
label: parseCompletionText(e[0], e[1]),
634635
icon: pwshTypeToIconMap[e[1]],
635636
detail: e[2],
636637
isFile: e[1] === 3,
637638
})));
638639
}
639640
return (rawCompletions as PwshCompletion[]).map(e => (new SimpleCompletionItem({
640-
label: e.CompletionText,
641+
label: parseCompletionText(e.CompletionText, e.ResultType),
641642
icon: pwshTypeToIconMap[e.ResultType],
642643
detail: e.ToolTip,
643644
isFile: e.ResultType === 3,
644645
})));
645646
}
647+
648+
function parseCompletionText(completionText: string, resultType: number): string {
649+
// HACK: Somewhere along the way from the powershell script to here, the path separator at the
650+
// end of directories may go missing, likely because `\"` -> `"`. As a result, make sure there
651+
// is a trailing separator at the end of all directory completions. This should not be done for
652+
// `.` and `..` entries because they are optimized not for navigating to different directories
653+
// but for passing as args.
654+
if (resultType === 4 && !completionText.match(/^\.\.?$/) && !completionText.match(/[\\\/]$/)) {
655+
const separator = completionText.match(/(?<sep>[\\\/])/)?.groups?.sep ?? sep;
656+
return completionText + separator;
657+
}
658+
return completionText;
659+
}

0 commit comments

Comments
 (0)
0