Skip to content

Commit 50426a2

Browse files
committed
feat(vscode): use shell integration instead of full python command line to start repl if shell integration is enabled
1 parent febf5d8 commit 50426a2

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

vscode-client/extension/languageToolsManager.ts

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ type QuickPickActionItem = {
3939
action?(folder?: vscode.WorkspaceFolder): Promise<void>;
4040
};
4141

42+
async function waitForShellIntegration(
43+
folder: vscode.WorkspaceFolder,
44+
terminal: vscode.Terminal,
45+
timeout: number = 3000,
46+
): Promise<boolean> {
47+
const config = vscode.workspace.getConfiguration("terminal.integrated.shellIntegration", folder);
48+
const enabled = config.get("enabled", false);
49+
if (!enabled) {
50+
return false;
51+
}
52+
53+
return new Promise<boolean>((resolve) => {
54+
if (terminal.shellIntegration) {
55+
resolve(true);
56+
return;
57+
}
58+
59+
const listener = vscode.window.onDidChangeTerminalShellIntegration((event) => {
60+
if (event.terminal === terminal) {
61+
listener.dispose();
62+
resolve(true);
63+
}
64+
});
65+
66+
setTimeout(() => {
67+
listener.dispose();
68+
resolve(false);
69+
}, timeout);
70+
});
71+
}
72+
4273
export class LanguageToolsManager {
4374
private _workspaceFolderLanguageStatuses = new WeakMap<vscode.WorkspaceFolder, ProjectInfo>();
4475
private _disposables: vscode.Disposable;
@@ -237,20 +268,27 @@ export class LanguageToolsManager {
237268
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
238269
const profiles = config.get<string[]>("profiles", []);
239270

240-
const { pythonCommand, final_args } = await this.pythonManager.buildRobotCodeCommand(
241-
folder,
242-
["repl"],
243-
profiles,
244-
);
245-
vscode.window
246-
.createTerminal({
247-
name: `Robot REPL${vscode.workspace.workspaceFolders?.length === 1 ? "" : ` (${folder.name})`}`,
248-
shellPath: pythonCommand,
249-
shellArgs: final_args,
250-
cwd: folder.uri,
251-
iconPath: new vscode.ThemeIcon("robotcode-robot"),
252-
})
253-
.show();
271+
const terminal = vscode.window.createTerminal({
272+
name: `Robot REPL${vscode.workspace.workspaceFolders?.length === 1 ? "" : ` (${folder.name})`}`,
273+
cwd: folder.uri,
274+
iconPath: new vscode.ThemeIcon("robotcode-robot"),
275+
isTransient: false,
276+
});
277+
terminal.show();
278+
const shellIntegrationActive = await waitForShellIntegration(folder, terminal);
279+
if (shellIntegrationActive) {
280+
terminal.shellIntegration?.executeCommand("robotcode", [
281+
...(profiles !== undefined ? profiles.flatMap((v) => ["-p", v]) : []),
282+
"repl",
283+
]);
284+
} else {
285+
const { pythonCommand, final_args } = await this.pythonManager.buildRobotCodeCommand(
286+
folder,
287+
["repl"],
288+
profiles,
289+
);
290+
terminal.sendText(`${pythonCommand} ${final_args.join(" ")}`, true);
291+
}
254292
},
255293
),
256294
vscode.commands.registerCommand("robotcode.disableRoboCop", async () => {

vscode-client/extension/pythonmanger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class PythonManager {
265265
...(format ? ["--format", format] : []),
266266
...(noColor ? ["--no-color"] : []),
267267
...(noPager ? ["--no-pager"] : []),
268-
...(profiles !== undefined ? profiles.flatMap((v) => ["--profile", v]) : []),
268+
...(profiles !== undefined ? profiles.flatMap((v) => ["--p", v]) : []),
269269
...args,
270270
];
271271
return { pythonCommand, final_args };

0 commit comments

Comments
 (0)