Merge pull request #215581 from microsoft/tyriar/211996

Add . and .. to suggestions, do nothing is completing same
This commit is contained in:
Daniel Imms 2024-06-17 07:30:36 -07:00 committed by GitHub
commit ed0a90c0b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View file

@ -212,7 +212,19 @@ function Send-Completions {
$completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
if ($null -ne $completions.CompletionMatches) {
$result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
$result += $completions.CompletionMatches | ConvertTo-Json -Compress
if ($completions.CompletionMatches.Count -gt 0 -and $completions.CompletionMatches.Where({ $_.ResultType -eq 3 -or $_.ResultType -eq 4 })) {
$json = [System.Collections.ArrayList]@($completions.CompletionMatches)
# Add . and .. to the completions list
$json.Add([System.Management.Automation.CompletionResult]::new(
'.', '.', [System.Management.Automation.CompletionResultType]::ProviderContainer, (Get-Location).Path)
)
$json.Add([System.Management.Automation.CompletionResult]::new(
'..', '..', [System.Management.Automation.CompletionResultType]::ProviderContainer, (Split-Path (Get-Location) -Parent))
)
$result += $json | ConvertTo-Json -Compress
} else {
$result += $completions.CompletionMatches | ConvertTo-Json -Compress
}
}
}
# If there is no space, get completions using CompletionCompleters as it gives us more

View file

@ -267,6 +267,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
if (!Array.isArray(completionList)) {
completionList = [completionList];
}
const completions = completionList.map((e: any) => {
return new SimpleCompletionItem({
label: e.ListItemText,
@ -278,6 +279,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
this._leadingLineContent = this._promptInputModel.value.substring(0, this._promptInputModel.cursorIndex);
// If there's no space it means this is a command, add cached commands list to completions
const firstChar = this._leadingLineContent.length === 0 ? '' : this._leadingLineContent[0];
if (this._leadingLineContent.trim().includes(' ') || firstChar === '[') {
@ -503,6 +505,12 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
const completionText = completion.completionText ?? completion.label;
const finalCompletionRightSide = completionText.substring((this._leadingLineContent?.length ?? 0) - (lastSpaceIndex === -1 ? 0 : lastSpaceIndex + 1));
// Hide the widget if there is no change
if (finalCompletionRightSide === additionalInput) {
this.hideSuggestWidget();
return;
}
// Get the final completion on the right side of the cursor if it differs from the initial
// propmt input state
let finalCompletionLeftSide = completionText.substring(0, (this._leadingLineContent?.length ?? 0) - (lastSpaceIndex === -1 ? 0 : lastSpaceIndex + 1));

View file

@ -81,10 +81,6 @@ export const events = [
"type": "command",
"id": "workbench.action.terminal.acceptSelectedSuggestion"
},
{
"type": "sendText",
"data": "s"
},
{
"type": "output",
"data": "\u001b[?25l\u001b[93m\u001b[3;3Hls\u001b[97m\u001b[2m\u001b[3ms\b\u001b[?25h"