Skip to content

Commit 5aa5337

Browse files
committed
Only disable for arm, clean up
1 parent f26d82c commit 5aa5337

File tree

5 files changed

+53
-39
lines changed

5 files changed

+53
-39
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,21 @@ export class CommandSimplifier {
8484
private async _rewriteUnsupportedPwshChainOperators(commandLine: string, os: OperatingSystem, shell: string) {
8585
// TODO: This should just be Windows PowerShell in the future when the powershell grammar
8686
// supports chain operators https://github.com/airbus-cert/tree-sitter-powershell/issues/27
87-
const disablePowerShellRewrites = true; // see https://github.com/microsoft/vscode/issues/273177
88-
if (!disablePowerShellRewrites && isPowerShell(shell, os)) {
89-
const doubleAmpersandCaptures = await this._treeSitterCommandParser.queryTree(TreeSitterCommandParserLanguage.PowerShell, commandLine, [
90-
'(',
91-
' (command',
92-
' (command_elements',
93-
' (generic_token) @double.ampersand',
94-
' (#eq? @double.ampersand "&&")))',
95-
')',
96-
].join('\n'));
97-
for (const capture of doubleAmpersandCaptures.reverse()) {
98-
commandLine = `${commandLine.substring(0, capture.node.startIndex)};${commandLine.substring(capture.node.endIndex)}`;
87+
if (isPowerShell(shell, os)) {
88+
try {
89+
const doubleAmpersandCaptures = await this._treeSitterCommandParser.queryTree(TreeSitterCommandParserLanguage.PowerShell, commandLine, [
90+
'(',
91+
' (command',
92+
' (command_elements',
93+
' (generic_token) @double.ampersand',
94+
' (#eq? @double.ampersand "&&")))',
95+
')',
96+
].join('\n'));
97+
for (const capture of doubleAmpersandCaptures.reverse()) {
98+
commandLine = `${commandLine.substring(0, capture.node.startIndex)};${commandLine.substring(capture.node.endIndex)}`;
99+
}
100+
} catch {
101+
// Swallow tree sitter failures
99102
}
100103
}
101104
return commandLine;

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

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,33 @@ export class TreeSitterCommandParser {
2424
}
2525

2626
async extractSubCommands(languageId: TreeSitterCommandParserLanguage, commandLine: string): Promise<string[]> {
27-
const disableSubCommandExtraction = true; // see https://github.com/microsoft/vscode/issues/273177
27+
this._throwIfCanCrash(languageId);
2828

29-
if (disableSubCommandExtraction) {
30-
throw new Error('not supported');
31-
} else {
32-
const parser = await this._parser;
33-
const language = await waitForState(derived(reader => {
34-
return this._treeSitterLibraryService.getLanguage(languageId, true, reader);
35-
}));
36-
parser.setLanguage(language);
37-
38-
const tree = parser.parse(commandLine);
39-
if (!tree) {
40-
throw new BugIndicatingError('Failed to parse tree');
41-
}
42-
43-
const query = await this._getQuery(language);
44-
if (!query) {
45-
throw new BugIndicatingError('Failed to create tree sitter query');
46-
}
47-
48-
const captures = query.captures(tree.rootNode);
49-
const subCommands = captures.map(e => e.node.text);
50-
51-
return subCommands;
29+
const parser = await this._parser;
30+
const language = await waitForState(derived(reader => {
31+
return this._treeSitterLibraryService.getLanguage(languageId, true, reader);
32+
}));
33+
parser.setLanguage(language);
34+
35+
const tree = parser.parse(commandLine);
36+
if (!tree) {
37+
throw new BugIndicatingError('Failed to parse tree');
38+
}
39+
40+
const query = await this._getQuery(language);
41+
if (!query) {
42+
throw new BugIndicatingError('Failed to create tree sitter query');
5243
}
44+
45+
const captures = query.captures(tree.rootNode);
46+
const subCommands = captures.map(e => e.node.text);
47+
48+
return subCommands;
5349
}
5450

5551
async queryTree(languageId: TreeSitterCommandParserLanguage, commandLine: string, querySource: string): Promise<QueryCapture[]> {
52+
this._throwIfCanCrash(languageId);
53+
5654
const parser = await this._parser;
5755
const language = await waitForState(derived(reader => {
5856
return this._treeSitterLibraryService.getLanguage(languageId, true, reader);
@@ -82,4 +80,14 @@ export class TreeSitterCommandParser {
8280
}
8381
return query;
8482
}
83+
84+
private _throwIfCanCrash(languageId: TreeSitterCommandParserLanguage) {
85+
// TODO: The powershell grammar can cause an OOM crash on arm https://github.com/microsoft/vscode/issues/273177
86+
if (
87+
(process.arch === 'arm' || process.arch === 'arm64') &&
88+
languageId === TreeSitterCommandParserLanguage.PowerShell
89+
) {
90+
throw new Error('not supported');
91+
}
92+
}
8593
}

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/commandSimplifier.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import { FileService } from '../../../../../../platform/files/common/fileService
2323
import { Schemas } from '../../../../../../base/common/network.js';
2424
import { TreeSitterLibraryService } from '../../../../../services/treeSitter/browser/treeSitterLibraryService.js';
2525

26-
suite.skip('command re-writing', () => {
26+
// TODO: The powershell grammar can cause an OOM crash on arm https://github.com/microsoft/vscode/issues/273177
27+
(process.arch === 'arm' || process.arch === 'arm64' ? suite.skip : suite)('command re-writing', () => {
2728
const store = ensureNoDisposablesAreLeakedInTestSuite();
2829

2930
let instantiationService: TestInstantiationService;

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/runInTerminalTool.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class TestRunInTerminalTool extends RunInTerminalTool {
4444
}
4545
}
4646

47-
suite('RunInTerminalTool', () => {
47+
// TODO: The powershell grammar can cause an OOM crash on arm https://github.com/microsoft/vscode/issues/273177
48+
(process.arch === 'arm' || process.arch === 'arm64' ? suite.skip : suite)('RunInTerminalTool', () => {
4849
const store = ensureNoDisposablesAreLeakedInTestSuite();
4950

5051
let instantiationService: TestInstantiationService;

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/treeSitterCommandParser.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { Schemas } from '../../../../../../base/common/network.js';
1515
import { TestIPCFileSystemProvider } from '../../../../../test/electron-browser/workbenchTestServices.js';
1616
import { TreeSitterCommandParser, TreeSitterCommandParserLanguage } from '../../browser/treeSitterCommandParser.js';
1717

18-
suite('TreeSitterCommandParser', () => {
18+
// TODO: The powershell grammar can cause an OOM crash on arm https://github.com/microsoft/vscode/issues/273177
19+
(process.arch === 'arm' || process.arch === 'arm64' ? suite.skip : suite)('TreeSitterCommandParser', () => {
1920
const store = ensureNoDisposablesAreLeakedInTestSuite();
2021

2122
let instantiationService: TestInstantiationService;

0 commit comments

Comments
 (0)