Skip to content

Commit cc626a1

Browse files
authored
Merge pull request microsoft#224697 from microsoft/tyriar/223414
Request path completions from nearest / or \
2 parents 220cb47 + c68db99 commit cc626a1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ function Send-Completions {
245245
$cursorIndex = $newCursorIndex
246246
}
247247
}
248+
# If it contains `/` or `\`, get completions from the nearest `/` or `\` such that file
249+
# completions are consistent regardless of where it was requested
250+
elseif ($lastWord -match '[/\\]') {
251+
$lastSlashIndex = $completionPrefix.LastIndexOfAny(@('/', '\'))
252+
if ($lastSlashIndex -ne -1 && $lastSlashIndex -lt $cursorIndex) {
253+
$newCursorIndex = $lastSlashIndex + 1
254+
$completionPrefix = $completionPrefix.Substring(0, $newCursorIndex)
255+
$prefixCursorDelta = $cursorIndex - $newCursorIndex
256+
$cursorIndex = $newCursorIndex
257+
}
258+
}
248259

249260
# Get completions using TabExpansion2
250261
$completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
@@ -293,6 +304,17 @@ function Send-Completions {
293304
# If there is no space, get completions using CompletionCompleters as it gives us more
294305
# control and works on the empty string
295306
else {
307+
# If it contains `/` or `\`, get completions from the nearest `/` or `\` such that file
308+
# completions are consistent regardless of where it was requested
309+
if ($completionPrefix -match '[/\\]') {
310+
$lastSlashIndex = $completionPrefix.LastIndexOfAny(@('/', '\'))
311+
if ($lastSlashIndex -ne -1 && $lastSlashIndex -lt $cursorIndex) {
312+
$newCursorIndex = $lastSlashIndex + 1
313+
$completionPrefix = $completionPrefix.Substring(0, $newCursorIndex)
314+
$prefixCursorDelta = $cursorIndex - $newCursorIndex
315+
$cursorIndex = $newCursorIndex
316+
}
317+
}
296318
# Note that CompleteCommand isn't included here as it's expensive
297319
$completions = $(
298320
# Add trailing \ for directories so behavior aligns with TabExpansion2

0 commit comments

Comments
 (0)