Skip to content

Commit 0b413e0

Browse files
committed
Merge remote-tracking branch 'origin/main' into tyriar/257468
2 parents ba2ec76 + dafc6c5 commit 0b413e0

File tree

7 files changed

+146
-120
lines changed

7 files changed

+146
-120
lines changed

extensions/terminal-suggest/src/completions/upstream/git.ts renamed to extensions/terminal-suggest/src/completions/git.ts

Lines changed: 113 additions & 96 deletions
Large diffs are not rendered by default.

extensions/terminal-suggest/src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const upstreamSpecs = [
3838
'grep',
3939
'find',
4040

41-
'git',
4241
'npm',
4342
'yarn',
4443
'python',

extensions/terminal-suggest/src/fig/figInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function getFigSuggestions(
110110
result.foldersRequested ||= completionItemResult.foldersRequested;
111111
result.fileExtensions ||= completionItemResult.fileExtensions;
112112
if (completionItemResult.items) {
113-
result.items.push(...completionItemResult.items);
113+
result.items = result.items.concat(completionItemResult.items);
114114
}
115115
}
116116
}

extensions/terminal-suggest/src/terminalSuggestMain.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@ import * as vscode from 'vscode';
88
import cdSpec from './completions/cd';
99
import codeCompletionSpec from './completions/code';
1010
import codeInsidersCompletionSpec from './completions/code-insiders';
11+
import codeTunnelCompletionSpec from './completions/code-tunnel';
12+
import codeTunnelInsidersCompletionSpec from './completions/code-tunnel-insiders';
13+
import gitCompletionSpec from './completions/git';
1114
import npxCompletionSpec from './completions/npx';
1215
import setLocationSpec from './completions/set-location';
1316
import { upstreamSpecs } from './constants';
1417
import { ITerminalEnvironment, PathExecutableCache, watchPathDirectories } from './env/pathExecutableCache';
18+
import { executeCommand, executeCommandTimeout, IFigExecuteExternals } from './fig/execute';
19+
import { getFigSuggestions } from './fig/figInterface';
20+
import { createCompletionItem } from './helpers/completionItem';
1521
import { osIsWindows } from './helpers/os';
22+
import { createTimeoutPromise } from './helpers/promise';
1623
import { getFriendlyResourcePath } from './helpers/uri';
1724
import { getBashGlobals } from './shell/bash';
1825
import { getFishGlobals } from './shell/fish';
1926
import { getPwshGlobals } from './shell/pwsh';
2027
import { getZshGlobals } from './shell/zsh';
21-
import { getTokenType, TokenType, shellTypeResetChars, defaultShellTypeResetChars } from './tokens';
28+
import { defaultShellTypeResetChars, getTokenType, shellTypeResetChars, TokenType } from './tokens';
2229
import type { ICompletionResource } from './types';
23-
import { createCompletionItem } from './helpers/completionItem';
24-
import { getFigSuggestions } from './fig/figInterface';
25-
import { executeCommand, executeCommandTimeout, IFigExecuteExternals } from './fig/execute';
26-
import { createTimeoutPromise } from './helpers/promise';
27-
import codeTunnelCompletionSpec from './completions/code-tunnel';
28-
import codeTunnelInsidersCompletionSpec from './completions/code-tunnel-insiders';
2930

3031
export const enum TerminalShellType {
3132
Bash = 'bash',
@@ -59,6 +60,7 @@ export const availableSpecs: Fig.Spec[] = [
5960
codeCompletionSpec,
6061
codeTunnelCompletionSpec,
6162
codeTunnelInsidersCompletionSpec,
63+
gitCompletionSpec,
6264
npxCompletionSpec,
6365
setLocationSpec,
6466
];
@@ -277,9 +279,10 @@ export async function activate(context: vscode.ExtensionContext) {
277279
terminal.name,
278280
token
279281
),
280-
createTimeoutPromise(300, undefined)
282+
createTimeoutPromise(5000, undefined)
281283
]);
282284
if (!result) {
285+
console.debug('#terminalCompletions Timed out fetching completions from specs');
283286
return;
284287
}
285288

@@ -407,7 +410,7 @@ export async function getCompletionItemsFromSpecs(
407410
token?: vscode.CancellationToken,
408411
executeExternals?: IFigExecuteExternals,
409412
): Promise<{ items: vscode.TerminalCompletionItem[]; filesRequested: boolean; foldersRequested: boolean; fileExtensions?: string[]; cwd?: vscode.Uri }> {
410-
const items: vscode.TerminalCompletionItem[] = [];
413+
let items: vscode.TerminalCompletionItem[] = [];
411414
let filesRequested = false;
412415
let foldersRequested = false;
413416
let hasCurrentArg = false;
@@ -429,7 +432,7 @@ export async function getCompletionItemsFromSpecs(
429432
foldersRequested ||= result.foldersRequested;
430433
fileExtensions = result.fileExtensions;
431434
if (result.items) {
432-
items.push(...result.items);
435+
items = items.concat(result.items);
433436
}
434437
}
435438

extensions/terminal-suggest/src/test/completions/upstream/git.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import 'mocha';
77
import { testPaths, type ISuiteSpec } from '../../helpers';
8-
import gitSpec from '../../../completions/upstream/git';
8+
import gitSpec from '../../../completions/git';
99

1010
// const gitSubcommandAndArgs = ['--bare', '--exec-path', '--git-dir', '--help', '--html-path', '--info-path', '--man-path', '--namespace', '--no-optional-locks', '--no-pager', '--no-replace-objects', '--paginate', '--version', '--work-tree', '-C', '-c', '-p', 'add', 'apply', 'archive', 'bisect', 'blame', 'branch', 'checkout', 'cherry-pick', 'clean', 'clone', 'commit', 'config', 'daemon', 'diff', 'fetch', 'grep', 'init', 'log', 'ls-remote', 'merge', 'mergetool', 'mv', 'pull', 'push', 'rebase', 'reflog', 'remote', 'reset', 'restore', 'revert', 'rm', 'show', 'stage', 'stash', 'status', 'submodule', 'switch', 'tag', 'worktree'];
1111
// const gitCommitArgs = ['--', '--all', '--allow-empty', '--allow-empty-message', '--amend', '--author', '--branch', '--cleanup', '--date', '--dry-run', '--edit', '--file', '--fixup', '--gpg-sign', '--include', '--long', '--message', '--no-edit', '--no-gpg-sign', '--no-post-rewrite', '--no-signoff', '--no-status', '--no-verify', '--null', '--only', '--patch', '--pathspec-file-nul', '--pathspec-from-file', '--porcelain', '--quiet', '--reedit-message', '--reset-author', '--reuse-message', '--short', '--signoff', '--squash', '--status', '--template', '--untracked-files', '--verbose', '-C', '-F', '-S', '-a', '-am', '-c', '-e', '-i', '-m', '-n', '-o', '-p', '-q', '-s', '-t', '-u', '-v', '-z'];

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/commandLineAutoApprover.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ConfigurationTarget, IConfigurationService, type IConfigurationValue }
1212
import { TerminalChatAgentToolsSettingId } from '../common/terminalChatAgentToolsConfiguration.js';
1313
import { isPowerShell } from './runInTerminalHelpers.js';
1414

15-
interface IAutoApproveRule {
15+
export interface IAutoApproveRule {
1616
regex: RegExp;
1717
regexCaseInsensitive: RegExp;
1818
sourceText: string;

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { XtermTerminal } from '../../../../terminal/browser/xterm/xtermTerm
2828
import { ITerminalProfileResolverService } from '../../../../terminal/common/terminal.js';
2929
import { getRecommendedToolsOverRunInTerminal } from '../alternativeRecommendation.js';
3030
import { getOutput } from '../bufferOutputPolling.js';
31-
import { CommandLineAutoApprover, type ICommandApprovalResultWithReason } from '../commandLineAutoApprover.js';
31+
import { CommandLineAutoApprover, type IAutoApproveRule, type ICommandApprovalResult, type ICommandApprovalResultWithReason } from '../commandLineAutoApprover.js';
3232
import { BasicExecuteStrategy } from '../executeStrategy/basicExecuteStrategy.js';
3333
import type { ITerminalExecuteStrategy } from '../executeStrategy/executeStrategy.js';
3434
import { NoneExecuteStrategy } from '../executeStrategy/noneExecuteStrategy.js';
@@ -40,6 +40,8 @@ import { Codicon } from '../../../../../../base/common/codicons.js';
4040
import { OutputMonitor } from '../outputMonitor.js';
4141
import type { TerminalNewAutoApproveButtonData } from '../../../../chat/browser/chatContentParts/toolInvocationParts/chatTerminalToolConfirmationSubPart.js';
4242
import { basename } from '../../../../../../base/common/path.js';
43+
import type { SingleOrMany } from '../../../../../../base/common/types.js';
44+
import { asArray } from '../../../../../../base/common/arrays.js';
4345

4446
const TERMINAL_SESSION_STORAGE_KEY = 'chat.terminalSessions';
4547

@@ -255,20 +257,25 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
255257
}
256258
}
257259

260+
function formatRuleLinks(result: SingleOrMany<{ result: ICommandApprovalResult; rule?: IAutoApproveRule; reason: string }>): string {
261+
return asArray(result).map(e => {
262+
return `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget} "${localize('ruleTooltip', 'View rule in settings')}")`;
263+
}).join(', ');
264+
}
258265
if (isAutoApproved) {
259266
switch (autoApproveReason) {
260267
case 'commandLine': {
261268
if (commandLineResult.rule) {
262-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', `[\`${commandLineResult.rule.sourceText}\`](settings_${commandLineResult.rule.sourceTarget})`)}_`);
269+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', formatRuleLinks(commandLineResult))}_`);
263270
}
264271
break;
265272
}
266273
case 'subCommand': {
267-
const uniqueRules = Array.from(new Set(subCommandResults.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`)));
274+
const uniqueRules = Array.from(new Set(subCommandResults));
268275
if (uniqueRules.length === 1) {
269-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', uniqueRules[0])}_`);
276+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rule', 'Auto approved by rule {0}', formatRuleLinks(uniqueRules))}_`);
270277
} else if (uniqueRules.length > 1) {
271-
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rules', 'Auto approved by rules {0}', uniqueRules.join(', '))}_`);
278+
autoApproveInfo = new MarkdownString(`_${localize('autoApprove.rules', 'Auto approved by rules {0}', formatRuleLinks(uniqueRules))}_`);
272279
}
273280
break;
274281
}
@@ -277,24 +284,24 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
277284
switch (autoApproveReason) {
278285
case 'commandLine': {
279286
if (commandLineResult.rule) {
280-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', `[\`${commandLineResult.rule.sourceText}\`](settings_${commandLineResult.rule.sourceTarget})`)}_`);
287+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', formatRuleLinks(commandLineResult))}_`);
281288
}
282289
break;
283290
}
284291
case 'subCommand': {
285292
const deniedRules = subCommandResults.filter(e => e.result === 'denied');
286-
const uniqueRules = Array.from(new Set(deniedRules.map(e => `[\`${e.rule!.sourceText}\`](settings_${e.rule!.sourceTarget})`)));
293+
const uniqueRules = Array.from(new Set(deniedRules));
287294
if (uniqueRules.length === 1) {
288-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', uniqueRules[0])}_`);
295+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rule', 'Auto approval denied by rule {0}', formatRuleLinks(uniqueRules))}_`);
289296
} else if (uniqueRules.length > 1) {
290-
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rules', 'Auto approval denied by rules {0}', uniqueRules.join(', '))}_`);
297+
autoApproveInfo = new MarkdownString(`_${localize('autoApproveDenied.rules', 'Auto approval denied by rules {0}', formatRuleLinks(uniqueRules))}_`);
291298
}
292299
break;
293300
}
294301
}
295302
}
296303

297-
// TODO: Surface reason on tool part https://github.com/microsoft/vscode/issues/256780
304+
// Log detailed auto approval reasoning
298305
for (const reason of autoApproveReasons) {
299306
this._logService.info(`- ${reason}`);
300307
}

0 commit comments

Comments
 (0)