Skip to content

Commit e66304e

Browse files
Merge pull request #111 from Chia-Network/20250207-debug-refresh
20250207 debug refresh
2 parents b36f657 + d71080e commit e66304e

File tree

7 files changed

+410
-182
lines changed

7 files changed

+410
-182
lines changed

package.json

+34-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"icon": "images/chialisp.png",
55
"description": "A Rust LSP client for Chialisp",
66
"publisher": "ChiaNetwork",
7-
"version": "1.2.2",
7+
"version": "1.2.3",
88
"engines": {
99
"vscode": "^1.85.0"
1010
},
@@ -15,7 +15,10 @@
1515
"activationEvents": [
1616
"onLanguage:chialisp",
1717
"onCommand:chialisp.startDebug",
18-
"onDebug"
18+
"onDebug",
19+
"onDebugResolve:chialisp",
20+
"workspaceContains:chialisp.json",
21+
"onFileSystem:cpptools-schema"
1922
],
2023
"contributes": {
2124
"languages": [
@@ -87,11 +90,38 @@
8790
"Chialisp",
8891
"chialisp"
8992
],
93+
"jsonValidation": [
94+
{
95+
"fileMatch": "schema/chialisp_properties.json",
96+
"url": "chialisp-schema:///schema/chialisp_properties.json"
97+
}
98+
],
9099
"configurationAttributes": {
91100
"launch": {
92101
"required": [
93-
"program"
94-
]
102+
"program",
103+
"args",
104+
"type"
105+
],
106+
"properties": {
107+
"program": {
108+
"type": "string",
109+
"description": "The chialisp program to run."
110+
},
111+
"args": {
112+
"type": "array",
113+
"description": "Environment for program. Specified as an array of strings for compatibility with other debug style tools.",
114+
"items": {
115+
"type": "string"
116+
},
117+
"default": ["()"]
118+
},
119+
"symbols": {
120+
"type": "string",
121+
"description": "Symbol file to use. Can specify additional information for classic chialisp and inputs files.",
122+
"default": ""
123+
}
124+
}
95125
}
96126
}
97127
}

schema/chialisp_properties.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"definitions": {
5+
"configurations": {
6+
"type": "array",
7+
"items": {
8+
"type": "object",
9+
"required": ["name", "program"],
10+
"properties": {
11+
"name": {
12+
"description": "Name of the configuration",
13+
"type": "string"
14+
},
15+
"args": {
16+
"description": "Arguments to specify the environment for running the program",
17+
"type": "array",
18+
"items": {
19+
"type": "string"
20+
},
21+
"default": ["()"]
22+
},
23+
"symbols": {
24+
"description": "Symbol file to use for launching pre-compiled clvm or classic chialisp",
25+
"type": "string",
26+
"default": ""
27+
},
28+
"program": {
29+
"description": "Program to run (hex, clvm or clsp)",
30+
"type": "string"
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}

src/extension.ts

+23
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
// Import the module and reference it with the alias vscode in your code below
44
import * as vscode from 'vscode';
55
import * as path from 'path';
6+
import * as fsBase from 'fs';
67
import * as os from 'os';
78

9+
const fs = fsBase.promises;
10+
811
import {
912
ExecutableOptions,
1013
LanguageClient,
@@ -22,6 +25,26 @@ import { debuggerActivate, debuggerDeactivate } from './dbg';
2225
// this method is called when your extension is activated
2326
// your extension is activated the very first time the c`ommand is executed
2427
export async function activate(context: vscode.ExtensionContext) {
28+
// Taken from vscode-cpptools...
29+
// Register a protocol handler to serve localized versions of the schema for c_cpp_properties.json
30+
class SchemaProvider implements vscode.TextDocumentContentProvider {
31+
public async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
32+
console.assert(uri.path[0] === '/', "A preceding slash is expected on schema uri path");
33+
const fileName: string = uri.path.substring(1);
34+
let extension = vscode.extensions.getExtension('ChiaNetwork.chialisp');
35+
if (extension) {
36+
let targetPath = path.join(extension.extensionUri.fsPath, fileName);
37+
let fileBuffer = await fs.readFile(targetPath);
38+
return fileBuffer.toString('utf8');
39+
}
40+
41+
return new Promise((resolve, reject) => {
42+
reject(new Error("requested file doesn't seem to exist"));
43+
});
44+
}
45+
}
46+
47+
vscode.workspace.registerTextDocumentContentProvider('chialisp-schema', new SchemaProvider());
2548
languageActivate(context);
2649
debuggerActivate(context);
2750
}

test/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM codercom/code-server:4.21.0-focal
1+
FROM codercom/code-server:4.96.4-focal
22
RUN sudo ln -s /usr/lib/code-server/lib/node /bin/node
33
COPY launch.json /home/coder/.vscode/launch.json

test/test/test.js

+63-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// Require modules used in the logic below
22
const jasmine = require('jasmine');
33
const os = require('os');
4-
const {Builder, By, Key, until} = require('selenium-webdriver');
4+
const {Builder, Options, By, Key, until} = require('selenium-webdriver');
55

66
// You can use a remote Selenium Hub, but we are not doing that here
77
require('chromedriver');
8+
9+
const chrome = require('selenium-webdriver/chrome');
10+
const options = new chrome.Options();
11+
options.addArguments('--remote-debugging-pipe');
12+
813
const driver = new Builder()
9-
.forBrowser('chrome')
10-
.build();
14+
.forBrowser('chrome')
15+
.setChromeOptions(options)
16+
.build();
1117

1218
const baseUrl = "http://localhost:8080";
1319
const password = "739f75e86e8d7843df146bac";
@@ -39,6 +45,10 @@ let login = async function() {
3945
// once the Log in button has gone "stale."
4046
await enterCredentialsAndLogin();
4147
console.log('Logged in.');
48+
49+
console.log('grant clipboard permissions if needed');
50+
await driver.setPermission('clipboard-read', 'granted');
51+
await driver.setPermission('clipboard-write', 'granted');
4252
};
4353

4454
// Configure Jasmine's timeout value to account for longer tests.
@@ -264,6 +274,16 @@ async function findFileInput(driver) {
264274
return await ibwrapper.findElement(By.css(".input"));
265275
}
266276

277+
async function dismissTrustDialogue() {
278+
// Dismiss trust dialog if it comes up.
279+
console.log('check for the trust dialog');
280+
let trustDialog = await driver.findElements(By.css('.dialog-shadow'));
281+
if (trustDialog.length !== 0) {
282+
let trustButton = await driver.wait(until.elementLocated(byVisibleText("Yes, I trust the authors")));
283+
trustButton.click();
284+
}
285+
}
286+
267287
// Define a category of tests using test framework, in this case Jasmine
268288
describe("Basic element tests", function() {
269289
// After each test, close the browser.
@@ -280,17 +300,11 @@ describe("Basic element tests", function() {
280300
console.log('wait for an element indicating that the workspace is up');
281301
await driver.wait(until.elementLocated(By.css('.monaco-workbench')), 10 * 1000);
282302

283-
// Things load more progressively in the current vs code.
303+
// Things load more progressively in the current vs code.
284304
const actions = driver.actions({async: true});
285305
await actions.pause(3000).perform();
286306

287-
// Dismiss trust dialog if it comes up.
288-
console.log('check for the trust dialog');
289-
let trustDialog = await driver.findElements(By.css('.dialog-shadow'));
290-
if (trustDialog.length !== 0) {
291-
let trustButton = await driver.wait(until.elementLocated(byVisibleText("Yes, I trust the authors")));
292-
trustButton.click();
293-
}
307+
await dismissTrustDialogue();
294308
}
295309

296310
async function installVsix() {
@@ -313,11 +327,26 @@ describe("Basic element tests", function() {
313327
console.log('install done');
314328
}
315329

330+
// The launch json we have should have squiggles until the extension is installed.
331+
async function checkSquiggleInLaunchJson() {
332+
await openFileTheLongWay(driver, ".vscode/launch.json");
333+
334+
await dismissTrustDialogue();
335+
336+
// Will abort if not found.
337+
// There should be a squiggly here before the driver is installed.
338+
let squiggly = await driver.wait(until.elementLocated(By.css(".squiggly-warning")));
339+
340+
await dismissTrustDialogue();
341+
}
342+
316343
it("starts", async function() {
317344
await login();
318345

319346
await enterTheEditor();
320347

348+
await checkSquiggleInLaunchJson();
349+
321350
await installVsix();
322351
});
323352

@@ -327,7 +356,7 @@ describe("Basic element tests", function() {
327356
// This test should pass.
328357
console.log('Running test...');
329358

330-
await openFile(driver, 'collatz.cl');
359+
await openFile(driver, 'collatz.cl');
331360

332361
// If these elements can be found, we're highlighting.
333362
console.log('finding highlighting');
@@ -357,23 +386,23 @@ describe("Basic element tests", function() {
357386
await sendReturn();
358387

359388
console.log('find the input box');
360-
let inputBox = await findFileInput(driver);
361-
await inputBox.click();
389+
let inputBox = await findFileInput(driver);
390+
await inputBox.click();
362391
await inputBox.sendKeys("include/test-inc.clsp");
363392

364393
console.log('accept input');
365394
let okBox = await driver.wait(until.elementLocated(byVisibleText("OK")));
366395
okBox.click();
367396

368-
await wait(3.0);
397+
await wait(3.0);
369398

370399
console.log('Check the content of chialisp.json');
371-
await openFile(driver, "chialisp.json");
400+
await openFile(driver, "chialisp.json");
372401

373402
console.log('Check content');
374403
let chialispText = await driver.wait(until.elementLocated(byVisibleText('"./project/include"')));
375404

376-
await openFile(driver, "collatz.cl");
405+
await openFile(driver, "collatz.cl");
377406

378407
console.log('comments should move');
379408
let otherComment = await driver.wait(until.elementLocated(byVisibleText("defun-inline")));
@@ -437,6 +466,20 @@ describe("Basic element tests", function() {
437466
await closeBox.click();
438467

439468
console.log("completion test done, should have no search box");
469+
470+
// Wait for the ui to settle.
471+
await wait(2.0);
472+
473+
// Check that we apply our schema to the launch json
474+
console.log('Check launch json highlighting');
475+
// This version of vs code opens from the most recent folder.
476+
await openFileTheLongWay(driver, "../.vscode/launch.json");
477+
478+
// Verify that installing the debugger made the lint warnings disappear in
479+
// launch.json.
480+
squigglies = await driver.findElements(By.css('.squiggly-warning'));
481+
expect(squigglies.length).toBe(0);
482+
440483
await wait(25.0);
441484

442485
//
@@ -447,7 +490,8 @@ describe("Basic element tests", function() {
447490
// This test should pass.
448491
console.log('Running debug test 1...');
449492

450-
await openFileTheLongWay(driver, 'include/fact.clinc');
493+
// Change folder.
494+
await openFileTheLongWay(driver, '../project/include/fact.clinc');
451495

452496
let debugButton = await driver.wait(until.elementLocated(By.css(".codicon-run-view-icon")));
453497
await debugButton.click();
@@ -477,7 +521,7 @@ describe("Basic element tests", function() {
477521

478522
let expression = await driver.wait(until.elementLocated(By.css(".expression")));
479523
let text = await expression.getText();
480-
while (simplifyText(text) != "X:4") {
524+
while (simplifyText(text) != "X=4") {
481525
await clickStepInto();
482526
console.log(simplifyText(text));
483527
expression = await driver.wait(until.elementLocated(By.css(".expression")));

0 commit comments

Comments
 (0)