Skip to content

Commit 0d29150

Browse files
committed
some refactorings
1 parent c8ff191 commit 0d29150

File tree

3 files changed

+58
-104
lines changed

3 files changed

+58
-104
lines changed

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,11 @@
216216
"type": "string",
217217
"enum": [
218218
"disabled",
219-
"external",
220-
"internal"
219+
"external"
221220
],
222221
"enumDescriptions": [
223222
"Do not open the result report",
224-
"Opens the report in an external browser.",
225-
"Opens the report in an internal view (experimental)."
223+
"Opens the report in an external browser."
226224
],
227225
"default": "none",
228226
"description": "Defines if the test report should be opened a run session automatically.",
@@ -503,10 +501,10 @@
503501
"devDependencies": {
504502
"@types/glob": "^7.1.3",
505503
"@types/mocha": "^8.2.2",
506-
"@types/node": "^15.0.2",
504+
"@types/node": "^15.3.0",
507505
"@types/vscode": "^1.56.0",
508-
"@typescript-eslint/eslint-plugin": "^4.22.1",
509-
"@typescript-eslint/parser": "^4.22.1",
506+
"@typescript-eslint/eslint-plugin": "^4.23.0",
507+
"@typescript-eslint/parser": "^4.23.0",
510508
"eslint": "^7.26.0",
511509
"glob": "^7.1.7",
512510
"mocha": "^8.4.0",
@@ -515,7 +513,7 @@
515513
"vsce": "^1.88.0",
516514
"vscode-debugadapter-testsupport": "^1.47.0",
517515
"vscode-test": "^1.5.2",
518-
"webpack": "^5.36.2",
516+
"webpack": "^5.37.0",
519517
"webpack-cli": "^4.7.0"
520518
}
521519
}

robotcode/debug_adapter/launcher/__main__.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def start_debugpy_async() -> None:
150150

151151
loop = asyncio.new_event_loop()
152152

153-
thread = threading.Thread(name="RobotCode Debug Launcher", target=run_server, args=(port, loop))
153+
thread = threading.Thread(name="RobotCode Debugger", target=run_server, args=(port, loop))
154154
thread.setDaemon(True)
155155
thread.start()
156156

@@ -159,32 +159,28 @@ async def start_debugpy_async() -> None:
159159
try:
160160
if wait_for_client:
161161
try:
162-
163-
await asyncio.gather(
164-
# start_debugpy_async(),
165-
asyncio.wrap_future(
166-
asyncio.run_coroutine_threadsafe(
167-
server.protocol.wait_for_client(wait_for_client_timeout), loop=loop
168-
)
169-
),
162+
await asyncio.wrap_future(
163+
asyncio.run_coroutine_threadsafe(
164+
server.protocol.wait_for_client(wait_for_client_timeout), loop=loop
165+
)
170166
)
171167
except (asyncio.CancelledError, SystemExit, KeyboardInterrupt):
172168
pass
173169
except asyncio.TimeoutError:
174170
raise ConnectionError("No incomming connection from a debugger client.")
175171

176-
await asyncio.wrap_future(asyncio.run_coroutine_threadsafe(server.protocol.initialized(), loop=loop))
172+
await asyncio.wrap_future(asyncio.run_coroutine_threadsafe(server.protocol.initialized(), loop=loop))
177173

178-
try:
179-
await asyncio.wrap_future(
180-
asyncio.run_coroutine_threadsafe(
181-
server.protocol.wait_for_configuration_done(configuration_done_timeout), loop=loop
182-
)
174+
try:
175+
await asyncio.wrap_future(
176+
asyncio.run_coroutine_threadsafe(
177+
server.protocol.wait_for_configuration_done(configuration_done_timeout), loop=loop
183178
)
184-
except (asyncio.CancelledError, SystemExit, KeyboardInterrupt):
185-
pass
186-
except asyncio.TimeoutError:
187-
raise ConnectionError("Timeout to get configuration from client.")
179+
)
180+
except (asyncio.CancelledError, SystemExit, KeyboardInterrupt):
181+
pass
182+
except asyncio.TimeoutError:
183+
raise ConnectionError("Timeout to get configuration from client.")
188184

189185
await start_debugpy_async()
190186

vscode-client/extension.ts

Lines changed: 37 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as net from "net";
22
import * as path from "path";
3+
import * as fs from "fs";
34
import * as vscode from "vscode";
45
import { LanguageClient, LanguageClientOptions, ServerOptions } from "vscode-languageclient/node";
56
import { sleep } from "./utils";
@@ -27,8 +28,8 @@ function getPythonCommand(folder: vscode.WorkspaceFolder | undefined): string |
2728
if (configPython !== undefined && configPython != "") {
2829
result = configPython;
2930
} else {
30-
const extension = vscode.extensions.getExtension("ms-python.python")!;
31-
let pythonExtensionPythonPath: string[] | undefined = extension.exports.settings.getExecutionDetails(
31+
const pythonExtension = vscode.extensions.getExtension("ms-python.python")!;
32+
let pythonExtensionPythonPath: string[] | undefined = pythonExtension.exports.settings.getExecutionDetails(
3233
folder?.uri
3334
)?.execCommand;
3435

@@ -439,62 +440,6 @@ async function attachPython(session: vscode.DebugSession, event: string, options
439440
}
440441
}
441442

442-
async function openReportInternal(reportFile: string) {
443-
let panel = vscode.window.createWebviewPanel("robotcode.report", "Robot Report", vscode.ViewColumn.Active, {
444-
enableScripts: true,
445-
enableFindWidget: true,
446-
enableCommandUris: true,
447-
retainContextWhenHidden: true,
448-
localResourceRoots: [vscode.Uri.file(path.dirname(reportFile))],
449-
});
450-
451-
let uri = vscode.Uri.file(reportFile);
452-
453-
panel.webview.html = `<!DOCTYPE html>
454-
<html>
455-
456-
<head>
457-
<meta http-equiv="Content-Security-Policy" content="
458-
default-src none 'unsafe-inline';
459-
frame-src ${panel.webview.cspSource} 'unsafe-inline';
460-
style-src ${panel.webview.cspSource} 'unsafe-inline';
461-
img-src ${panel.webview.cspSource};
462-
script-src ${panel.webview.cspSource} 'unsafe-inline';">
463-
464-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
465-
<title>Robot Report</title>
466-
</head>
467-
468-
<body>
469-
<script>
470-
function frame_loaded() {
471-
function WhichLinkWasClicked(evt) {
472-
alert(evt.target);
473-
//evt.preventDefault();
474-
}
475-
476-
var links = myFrame.document.querySelectorAll('a');
477-
for (var link of links) {
478-
console.log("blah link");
479-
link.addEventListener('click', WhichLinkWasClicked);
480-
}
481-
}
482-
</script>
483-
484-
<iframe style="position: absolute; height: 100%; width: 100%; border: none" src="${panel.webview
485-
.asWebviewUri(uri)
486-
.toString()}" name="myFrame"
487-
onload="frame_loaded()" sandbox="allow-scripts allow-same-origin" referrerpolicy="origin" >
488-
</iframe>
489-
</body>
490-
491-
</html>`;
492-
//panel.webview.html = fs.readFileSync(event.body?.reportFile).toString();
493-
// panel.webview.onDidReceiveMessage(async (event) => {
494-
// console.log(`hello ${JSON.stringify(event)}`);
495-
// });
496-
}
497-
498443
async function onRobotExited(session: vscode.DebugSession, outputFile?: string, logFile?: string, reportFile?: string) {
499444
if (reportFile) {
500445
let config = vscode.workspace.getConfiguration(CONFIG_SECTION, session.workspaceFolder);
@@ -503,12 +448,7 @@ async function onRobotExited(session: vscode.DebugSession, outputFile?: string,
503448
case "disabled":
504449
return;
505450
case "external":
506-
vscode.env.openExternal(vscode.Uri.file(reportFile));
507-
break;
508-
509-
case "internal":
510-
openReportInternal(reportFile);
511-
break;
451+
vscode.env.openExternal(vscode.Uri.file(reportFile));
512452
}
513453
}
514454
}
@@ -533,17 +473,13 @@ export async function activateAsync(context: vscode.ExtensionContext) {
533473
pythonDebugAdapterMain = context.asAbsolutePath(path.join("robotcode", "debug_adapter", "__main__.py"));
534474

535475
OUTPUT_CHANNEL.appendLine("Try to activate Python extension.");
536-
const extension = vscode.extensions.getExtension("ms-python.python")!;
476+
const pythonExtension = vscode.extensions.getExtension("ms-python.python")!;
537477

538-
await extension.activate().then(function () {
539-
OUTPUT_CHANNEL.appendLine("Python Extension is active");
540-
});
478+
await pythonExtension.activate();
541479

542-
context.subscriptions.push(
543-
extension.exports.settings.onDidChangeExecutionDetails((uri: vscode.Uri) => {
544-
OUTPUT_CHANNEL.appendLine(uri.toString());
545-
}),
480+
OUTPUT_CHANNEL.appendLine("Python Extension is active");
546481

482+
context.subscriptions.push(
547483
vscode.commands.registerCommand("robotcode.runSuite", async (resource) => {
548484
return await debugSuiteOrTestcase(resource ?? vscode.window.activeTextEditor?.document.uri, undefined, {
549485
noDebug: true,
@@ -630,7 +566,6 @@ export async function activateAsync(context: vscode.ExtensionContext) {
630566
}),
631567
vscode.window.registerTerminalLinkProvider({
632568
provideTerminalLinks(context: vscode.TerminalLinkContext, token: vscode.CancellationToken) {
633-
console.log("ho");
634569
if (
635570
(context.line.startsWith("Log:") || context.line.startsWith("Report:")) &&
636571
context.line.endsWith("html")
@@ -658,9 +593,6 @@ export async function activateAsync(context: vscode.ExtensionContext) {
658593
);
659594

660595
switch (config.get<string>("run.openReportAfterRun")) {
661-
case "internal":
662-
openReportInternal(link.path);
663-
break;
664596
default:
665597
vscode.env.openExternal(vscode.Uri.file(link.path));
666598
break;
@@ -706,7 +638,35 @@ export async function activateAsync(context: vscode.ExtensionContext) {
706638
vscode.window.onDidChangeTextEditorSelection(async (event) => {
707639
await updateEditorContext(event.textEditor);
708640
}),
709-
vscode.workspace.onDidOpenTextDocument(getLanguageClientForDocument)
641+
vscode.workspace.onDidOpenTextDocument(getLanguageClientForDocument),
642+
643+
vscode.languages.registerInlineValuesProvider("robotframework", {
644+
provideInlineValues(
645+
document: vscode.TextDocument,
646+
viewPort: vscode.Range,
647+
context: vscode.InlineValueContext,
648+
token: vscode.CancellationToken
649+
): vscode.ProviderResult<vscode.InlineValue[]> {
650+
const allValues: vscode.InlineValue[] = [];
651+
652+
for (let l = 0; l <= context.stoppedLocation.end.line; l++) {
653+
const line = document.lineAt(l);
654+
let text = line.text.split("#")[0];
655+
656+
const variableMatches =
657+
/([$@&%]\{)(?:((?:\d+\.?\d*)|(?:0x[\/da-f]+)|(?:0o[0-7]+)|(?:0b[01]+))|(true|false|none|null|empty|space|\/|:|\\n)|((.+?}*)))(\})(?:(\[)(?:(\d+)|(.*?))?(\]))?/gi;
658+
659+
let match;
660+
while ((match = variableMatches.exec(text))) {
661+
let varName = match[0];
662+
663+
const rng = new vscode.Range(l, match.index, l, match.index + varName.length);
664+
allValues.push(new vscode.InlineValueVariableLookup(rng, varName, false));
665+
}
666+
}
667+
return allValues;
668+
},
669+
})
710670
);
711671

712672
for (let document of vscode.workspace.textDocuments) {

0 commit comments

Comments
 (0)