mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-20 02:34:37 +01:00
Clean up
This commit is contained in:
@@ -210,54 +210,53 @@ function Send-Completions {
|
||||
# Start completions sequence
|
||||
$result = "$([char]0x1b)]633;Completions"
|
||||
|
||||
# Get completions
|
||||
if ($completionPrefix.Length -gt 0) {
|
||||
# If there is a space in the input, defer to TabExpansion2 as it's more complicated to
|
||||
# determine valid completions
|
||||
if ($completionPrefix.Contains(' ')) {
|
||||
$completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
|
||||
if ($null -ne $completions.CompletionMatches) {
|
||||
$result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
|
||||
$result += $completions.CompletionMatches | ConvertTo-Json -Compress
|
||||
}
|
||||
}
|
||||
# If there is no space, get completions using CompletionCompleters as it gives us more
|
||||
# control and works on the empty string
|
||||
else {
|
||||
# $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
|
||||
# if ($null -ne $completions.CompletionMatches) {
|
||||
# $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
|
||||
# $result += $completions.CompletionMatches | ConvertTo-Json -Compress
|
||||
# }
|
||||
# Get and send completions, note that CompleteCommand isn't included here as it's expensive
|
||||
$completions = $(
|
||||
([System.Management.Automation.CompletionCompleters]::CompleteFilename($completionPrefix));
|
||||
([System.Management.Automation.CompletionCompleters]::CompleteVariable($completionPrefix));
|
||||
)
|
||||
if ($null -ne $completions) {
|
||||
$result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
|
||||
$result += $completions | ConvertTo-Json -Compress
|
||||
} else {
|
||||
$result += ";0;$($completionPrefix.Length);$($completionPrefix.Length);[]"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# TODO: Consolidate this case with the above
|
||||
# TODO: Try use this approach after the last whitespace for everything so intellisense is always consistent
|
||||
|
||||
# Special case when the prefix is empty since TabExpansion2 doesn't handle it
|
||||
if ($completionPrefix.Length -eq 0) {
|
||||
# Get and send completions
|
||||
$completions = $(
|
||||
([System.Management.Automation.CompletionCompleters]::CompleteFilename(''));
|
||||
([System.Management.Automation.CompletionCompleters]::CompleteVariable(''));
|
||||
)
|
||||
if ($null -ne $completions) {
|
||||
$result += ";0;0;0;"
|
||||
$result += $completions | ConvertTo-Json -Compress
|
||||
}
|
||||
# If there is a space in the input, defer to TabExpansion2 as it's more complicated to
|
||||
# determine what type of completions to use
|
||||
if ($completionPrefix.Contains(' ')) {
|
||||
$completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
|
||||
if ($null -ne $completions.CompletionMatches) {
|
||||
$result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
|
||||
$result += $completions.CompletionMatches | ConvertTo-Json -Compress
|
||||
}
|
||||
}
|
||||
# If there is no space, get completions using CompletionCompleters as it gives us more
|
||||
# control and works on the empty string
|
||||
else {
|
||||
# $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
|
||||
# if ($null -ne $completions.CompletionMatches) {
|
||||
# $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
|
||||
# $result += $completions.CompletionMatches | ConvertTo-Json -Compress
|
||||
# }
|
||||
# Get and send completions, note that CompleteCommand isn't included here as it's expensive
|
||||
$completions = $(
|
||||
([System.Management.Automation.CompletionCompleters]::CompleteFilename($completionPrefix));
|
||||
([System.Management.Automation.CompletionCompleters]::CompleteVariable($completionPrefix));
|
||||
)
|
||||
this
|
||||
if ($null -ne $completions) {
|
||||
$result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
|
||||
$result += $completions | ConvertTo-Json -Compress
|
||||
} else {
|
||||
$result += ";0;$($completionPrefix.Length);$($completionPrefix.Length);[]"
|
||||
}
|
||||
}
|
||||
# } else {
|
||||
# # TODO: Consolidate this case with the above
|
||||
# # TODO: Try use this approach after the last whitespace for everything so intellisense is always consistent
|
||||
|
||||
# # Special case when the prefix is empty since TabExpansion2 doesn't handle it
|
||||
# if ($completionPrefix.Length -eq 0) {
|
||||
# # Get and send completions
|
||||
# $completions = $(
|
||||
# ([System.Management.Automation.CompletionCompleters]::CompleteFilename(''));
|
||||
# ([System.Management.Automation.CompletionCompleters]::CompleteVariable(''));
|
||||
# )
|
||||
# if ($null -ne $completions) {
|
||||
# $result += ";0;0;0;"
|
||||
# $result += $completions | ConvertTo-Json -Compress
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
# End completions sequence
|
||||
$result += "`a"
|
||||
|
||||
@@ -136,11 +136,11 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
|
||||
}
|
||||
|
||||
private _sync(promptInputState: IPromptInputModelState): void {
|
||||
|
||||
if (
|
||||
(!this._mostRecentPromptInputState || promptInputState.cursorIndex > this._mostRecentPromptInputState.cursorIndex) &&
|
||||
(promptInputState.cursorIndex === 1 || promptInputState.value.substring(0, promptInputState.cursorIndex).match(/\s[^\s]$/))
|
||||
) {
|
||||
// TODO: Allow the user to configure when completions are triggered - this is equivalent to editor.quickSuggestions
|
||||
// TODO: Debounce? Prevent this flooding the channel
|
||||
this._onAcceptedCompletion.fire('\x1b[24~e');
|
||||
}
|
||||
@@ -229,16 +229,6 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
|
||||
let replacementIndex = 0; //args.length === 0 ? 0 : parseInt(args[0]);
|
||||
let replacementLength = this._promptInputModel.cursorIndex; //args.length === 0 ? 0 : parseInt(args[1]);
|
||||
|
||||
console.log({
|
||||
replacementIndex,
|
||||
replacementLength
|
||||
});
|
||||
// TODO: Add bell back?
|
||||
// if (!args[3]) {
|
||||
// this._onBell.fire();
|
||||
// return;
|
||||
// }
|
||||
|
||||
const payload = data.slice(command.length + args[0].length + args[1].length + args[2].length + 4/*semi-colons*/);
|
||||
let completionList: IPwshCompletion[] | IPwshCompletion = args.length === 0 || payload.length === 0 ? [] : JSON.parse(payload);
|
||||
if (!Array.isArray(completionList)) {
|
||||
@@ -263,21 +253,8 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
|
||||
this._leadingLineContent = completions[0]?.completion.label.slice(0, replacementLength) ?? '';
|
||||
}
|
||||
|
||||
console.log({
|
||||
replacementIndex,
|
||||
replacementLength,
|
||||
leadingLineContent: this._leadingLineContent
|
||||
});
|
||||
|
||||
this._cursorIndexDelta = 0;
|
||||
const model = new SimpleCompletionModel(completions, new LineContext(this._leadingLineContent, replacementIndex), replacementIndex, replacementLength);
|
||||
if (completions.length === 1) {
|
||||
const insertText = completions[0].completion.label.substring(replacementLength);
|
||||
if (insertText.length === 0) {
|
||||
this._onBell.fire();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._handleCompletionModel(model);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user