VSCODE Exstention fix

This commit is contained in:
allexanderbergmns
2026-08-25 16:25:31 +02:00
parent 7ed774089e
commit b125721977
218 changed files with 5034 additions and 2 deletions
@@ -0,0 +1 @@
.vscode/settings.json
+9
View File
@@ -0,0 +1,9 @@
fn helper(x) {
return x * 2
}
fn main() {
let y = helper(21)
println(y)
println(unknown_var)
}
+6
View File
@@ -0,0 +1,6 @@
import os
fn main() {
let a = os.exists("x")
println(a)
}
+41
View File
@@ -0,0 +1,41 @@
// runTest.js — launches a real VS Code instance with this extension loaded
// and runs the suite in test/suite. The workspace fixture's settings point
// the language client at the vr toolchain (VR_TOOLCHAIN env or `vr` on PATH).
//
// npm test
// VR_TOOLCHAIN=/path/to/vr npm test
const path = require('path');
const fs = require('fs');
const { runTests } = require('@vscode/test-electron');
async function main() {
const workspace = path.join(__dirname, 'fixtures', 'workspace');
const settingsDir = path.join(workspace, '.vscode');
fs.mkdirSync(settingsDir, { recursive: true });
const vr = process.env.VR_TOOLCHAIN || 'vr';
fs.writeFileSync(
path.join(settingsDir, 'settings.json'),
JSON.stringify({ 'vuurraaf.toolchainPath': vr }, null, 2)
);
// default to the locally installed stable VS Code; override with
// VSCODE_EXECUTABLE for CI runners that pre-install it
const executable =
process.env.VSCODE_EXECUTABLE ||
'/Applications/Visual Studio Code.app/Contents/MacOS/Code';
try {
await runTests({
vscodeExecutablePath: executable,
extensionDevelopmentPath: path.resolve(__dirname, '..'),
extensionTestsPath: path.join(__dirname, 'suite', 'index.js'),
launchArgs: [workspace],
});
console.log('VuurRaaf extension tests passed.');
} catch (err) {
console.error('VuurRaaf extension tests failed:', err);
process.exit(1);
}
}
main();
+101
View File
@@ -0,0 +1,101 @@
// extension.test.js — end-to-end tests for the VuurRaaf VS Code extension.
//
// These launch a real VS Code instance with the extension loaded, open a
// demo .vr file, and verify the full editing experience against the live
// `vr lsp` server: language registration, diagnostics, go-to-definition,
// and hover.
const assert = require('assert');
const path = require('path');
const vscode = require('vscode');
const DEMO_URI = vscode.Uri.file(
path.join(__dirname, '..', 'fixtures', 'workspace', 'demo.vr')
);
async function openDemo() {
const doc = await vscode.workspace.openTextDocument(DEMO_URI);
await vscode.window.showTextDocument(doc);
return doc;
}
async function waitForDiagnostics(timeoutMs) {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const diags = vscode.languages.getDiagnostics(DEMO_URI);
if (diags.length > 0) {
return diags;
}
await new Promise((r) => setTimeout(r, 500));
}
return vscode.languages.getDiagnostics(DEMO_URI);
}
suite('VuurRaaf extension', function () {
this.timeout(90000);
test('vuurraaf language (grammar) is registered', async function () {
const langs = await vscode.languages.getLanguages();
assert.ok(langs.includes('vuurraaf'), 'vuurraaf language id not registered');
});
test('language server publishes compiler diagnostics', async function () {
await openDemo();
const diags = await waitForDiagnostics(30000);
assert.ok(diags.length > 0, 'no diagnostics were published');
const joined = diags.map((d) => d.message).join('; ');
assert.ok(joined.includes('unknown_var'), 'expected unknown_var error, got: ' + joined);
assert.strictEqual(diags[0].severity, vscode.DiagnosticSeverity.Error);
});
test('go-to-definition jumps to the function declaration', async function () {
await openDemo();
// "helper" in `let y = helper(21)` — line 6, char 12 (0-based)
const pos = new vscode.Position(5, 12);
const locs = await vscode.commands.executeCommand(
'vscode.executeDefinitionProvider',
DEMO_URI,
pos
);
assert.ok(locs && locs.length > 0, 'no definition returned for helper');
assert.strictEqual(locs[0].range.start.line, 0, 'helper should resolve to line 1');
});
test('hover reports the symbol kind', async function () {
await openDemo();
// on the local `y` — line 6, char 5
const pos = new vscode.Position(5, 5);
const hovers = await vscode.commands.executeCommand('vscode.executeHoverProvider', DEMO_URI, pos);
assert.ok(hovers && hovers.length > 0, 'no hover returned for y');
const text = hovers
.map((h) => h.contents.map((c) => (typeof c === 'string' ? c : c.value)).join(' '))
.join(' ');
assert.ok(text.includes('variable'), 'expected a variable hover, got: ' + text);
});
test('go-to-definition resolves stdlib module functions', async function () {
await openDemo();
// switch to a file that calls os.exists so the import resolves
const modUri = vscode.Uri.file(
path.join(__dirname, '..', 'fixtures', 'workspace', 'module.vr')
);
const doc = await vscode.workspace.openTextDocument(modUri);
await vscode.window.showTextDocument(doc);
// "exists" in `let a = os.exists("x")` — line 4, char 12 (0-based)
const pos = new vscode.Position(3, 12);
// the definition request may race the didOpen notification, so retry
let locs = [];
for (let i = 0; i < 20 && locs.length === 0; i++) {
locs = await vscode.commands.executeCommand(
'vscode.executeDefinitionProvider',
modUri,
pos
);
if (locs.length === 0) {
await new Promise((r) => setTimeout(r, 500));
}
}
assert.ok(locs && locs.length > 0, 'no definition returned for os.exists');
assert.ok(locs[0].uri.fsPath.endsWith('os.vr'), 'expected lib/os.vr, got ' + locs[0].uri.fsPath);
});
});
+23
View File
@@ -0,0 +1,23 @@
// index.js — mocha bootstrap, executed inside the VS Code extension host.
const path = require('path');
const Mocha = require('mocha');
async function run() {
const mocha = new Mocha({
ui: 'tdd',
timeout: 90000,
reporter: 'spec',
});
mocha.addFile(path.join(__dirname, 'extension.test.js'));
return new Promise((resolve, reject) => {
mocha.run((failures) => {
if (failures > 0) {
reject(new Error(`${failures} test(s) failed`));
} else {
resolve();
}
});
});
}
module.exports = { run };