Skip to content

Commit febf5d8

Browse files
committed
feat(vscode): add shell integration to run RobotCode in a VSCode terminal without requiring Python package installation
1 parent 7f3010a commit febf5d8

File tree

6 files changed

+59
-33
lines changed

6 files changed

+59
-33
lines changed

bundled/scripts/robotcode

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /bin/bash
2+
python3 $ROBOTCODE_BUNDLED_ROBOTCODE_MAIN $@

bundled/scripts/robotcode.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
:: Bat script to run the robot code
3+
python %ROBOTCODE_BUNDLED_ROBOTCODE_MAIN% %*

bundled/scripts/robotcode.fish

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# fish script to run the bundled robotcode
2+
python3 $ROBOTCODE_BUNDLED_ROBOTCODE_MAIN $argv

bundled/scripts/robotcode.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# PowerShell script to run the bundled RobotCode
2+
if ($PSVersionTable.OS -match "Windows") {
3+
python $env:ROBOTCODE_BUNDLED_ROBOTCODE_MAIN $args
4+
} else {
5+
python3 $env:ROBOTCODE_BUNDLED_ROBOTCODE_MAIN $args
6+
}

src/robotcode/cli/commands/profiles.py

+32-28
Original file line numberDiff line numberDiff line change
@@ -128,35 +128,39 @@ def list(app: Application, paths: List[Path], show_hidden: bool = False, sort_by
128128
lines = v[k].splitlines()
129129
v[k] = " ".join(lines[:1]) + (" ..." if len(lines) > 1 else "")
130130

131-
header = ""
132-
max_name = max(
133-
0,
134-
len("Name"),
135-
*(len(profile["name"]) for profile in result["profiles"]),
136-
)
137-
max_description = max(
138-
0,
139-
len("Description"),
140-
*(len(profile["description"]) for profile in result["profiles"]),
141-
)
142-
header += (
143-
f'| Active | Selected | Enabled | Precedence | Name{(max_name - len("Name")) * " "} '
144-
f'| Description{(max_description - len("Description")) * " "} |\n'
145-
)
146-
header += f"|:------:|:------:|:--------:|:-------:|:{max_name * '-'}-|:{max_description * '-'}-|\n"
147-
for selected_profiles, enabled, name, description, precedence in (
148-
(v["selected"], v["enabled"], v["name"], v["description"], v["precedence"]) for v in result["profiles"]
149-
):
150-
header += (
151-
f'| {"*" if selected_profiles and enabled else " "} '
152-
f'| {"*" if selected_profiles else " "} '
153-
f'| {"*" if enabled else " "} '
154-
f'| {precedence if precedence else " "} '
155-
f'| {name}{(max_name - len(name)) * " "} '
156-
f'| {description if description else ""}{(max_description - len(description)) * " "} |\n'
131+
output = ""
132+
if result["profiles"]:
133+
max_name = max(
134+
0,
135+
len("Name"),
136+
*(len(profile["name"]) for profile in result["profiles"]),
157137
)
158-
159-
app.echo_as_markdown(header)
138+
max_description = max(
139+
0,
140+
len("Description"),
141+
*(len(profile["description"]) for profile in result["profiles"]),
142+
)
143+
output += (
144+
f'| Active | Selected | Enabled | Precedence | Name{(max_name - len("Name")) * " "} '
145+
f'| Description{(max_description - len("Description")) * " "} |\n'
146+
)
147+
output += f"|:------:|:------:|:--------:|:-------:|:{max_name * '-'}-|:{max_description * '-'}-|\n"
148+
for selected_profiles, enabled, name, description, precedence in (
149+
(v["selected"], v["enabled"], v["name"], v["description"], v["precedence"])
150+
for v in result["profiles"]
151+
):
152+
output += (
153+
f'| {"*" if selected_profiles and enabled else " "} '
154+
f'| {"*" if selected_profiles else " "} '
155+
f'| {"*" if enabled else " "} '
156+
f'| {precedence if precedence else " "} '
157+
f'| {name}{(max_name - len(name)) * " "} '
158+
f'| {description if description else ""}{(max_description - len(description)) * " "} |\n'
159+
)
160+
else:
161+
output += "No profiles defined.\n"
162+
163+
app.echo_as_markdown(output)
160164
else:
161165
app.print_data(result)
162166

vscode-client/extension/index.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TestControllerManager } from "./testcontrollermanager";
66
import { KeywordsTreeViewProvider } from "./keywordsTreeViewProvider";
77
import { LanguageToolsManager } from "./languageToolsManager";
88
import { NotebookManager } from "./notebook";
9+
import path from "path";
910

1011
class TerminalLink extends vscode.TerminalLink {
1112
constructor(
@@ -154,12 +155,20 @@ export async function activateAsync(context: vscode.ExtensionContext): Promise<v
154155
}),
155156
);
156157

157-
context.environmentVariableCollection.clear();
158-
context.environmentVariableCollection.description = new vscode.MarkdownString(
159-
"Disable ANSI links in `robot`'s terminal output.",
160-
);
158+
const collection = context.environmentVariableCollection;
159+
collection.description = new vscode.MarkdownString("RobotCode specific variables.");
160+
161+
collection.clear();
162+
163+
const pathSeparator = process.platform === "win32" ? ";" : ":";
164+
const scriptsDir = context.asAbsolutePath(path.join("bundled", "scripts"));
165+
166+
collection.append("PATH", `${pathSeparator}${scriptsDir}`, {
167+
applyAtShellIntegration: true,
168+
});
161169

162-
context.environmentVariableCollection.replace("ROBOTCODE_DISABLE_ANSI_LINKS", "1");
170+
collection.replace("ROBOTCODE_DISABLE_ANSI_LINKS", "1");
171+
collection.replace("ROBOTCODE_BUNDLED_ROBOTCODE_MAIN", pythonManager.robotCodeMain);
163172

164173
languageClientManger.refresh();
165174
}

0 commit comments

Comments
 (0)