Skip to content

Commit 7e91dcd

Browse files
authored
Merge pull request #57 from SSlinky/dev
Bug fixes and enhancements
2 parents dedb041 + 38903a7 commit 7e91dcd

File tree

20 files changed

+184
-53
lines changed

20 files changed

+184
-53
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
npm run antlr4ngPre
3737
npm run antlr4ngFmt
3838
mv ./server/src/antlr/out/server/src/antlr/* ./server/src/antlr/out
39-
- run: npm run compile
39+
- run: npm run build
4040
- run: xvfb-run -a npm test
4141
if: runner.os == 'Linux'
4242
- run: npm test

.vscode/launch.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"--extensionDevelopmentPath=${workspaceRoot}",
1212
"${workspaceFolder}/sample"
1313
],
14-
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
1514
"preLaunchTask": {
1615
"type": "npm",
1716
"script": "compile"
@@ -23,7 +22,6 @@
2322
"name": "Attach to Server",
2423
"port": 6009,
2524
"restart": true,
26-
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
2725
},
2826
{
2927
"name": "Language Server E2E Test",
@@ -32,10 +30,10 @@
3230
"runtimeExecutable": "${execPath}",
3331
"args": [
3432
"--extensionDevelopmentPath=${workspaceRoot}",
35-
"--extensionTestsPath=${workspaceRoot}/client/out/test/index",
36-
"${workspaceRoot}/client/testFixture"
33+
"--extensionTestsPath=${workspaceRoot}/dist/client/out/test/index",
34+
"${workspaceRoot}/test/fixtures"
3735
],
38-
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
36+
"outFiles": ["${workspaceRoot}/dist/client/out/test/**/*.js"]
3937
},
4038
{
4139
"name": "Debug ANTLR4 grammar",

client/src/test/diagnostics.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode';
77
import * as assert from 'assert';
8-
import { getDocUri, activate } from './helper';
8+
import { getDocUri, activate, runOnActivate } from './helper';
99
import { toRange } from './util';
1010

1111
suite('Should get diagnostics', () => {
@@ -147,8 +147,11 @@ suite('Should get diagnostics', () => {
147147
async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
148148
await activate(docUri);
149149

150-
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
151-
150+
// Use this method first to ensure the extension is activated.
151+
const actualDiagnostics = await runOnActivate(
152+
() => vscode.languages.getDiagnostics(docUri),
153+
(result) => result.length > 0
154+
);
152155
assert.equal(actualDiagnostics.length, expectedDiagnostics.length, "Count");
153156

154157
expectedDiagnostics.forEach((expectedDiagnostic, i) => {

client/src/test/foldingRanges.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as assert from 'assert';
3-
import { getDocUri, activate } from './helper';
3+
import { getDocUri, activate, runOnActivate } from './helper';
44

55
suite('Should get folding ranges', () => {
66
test('formatting.class.template', async () => {
@@ -24,10 +24,16 @@ suite('Should get folding ranges', () => {
2424

2525
async function testFoldingRanges(docUri: vscode.Uri, expectedFoldingRanges: vscode.FoldingRange[]) {
2626
await activate(docUri);
27-
const actualFoldingRanges = await vscode.commands.executeCommand<vscode.FoldingRange[]>(
27+
const action = () => vscode.commands.executeCommand<vscode.FoldingRange[]>(
2828
'vscode.executeFoldingRangeProvider',
2929
docUri
3030
)
31+
32+
// Use this method first to ensure the extension is activated.
33+
const actualFoldingRanges = await runOnActivate(
34+
action,
35+
(result) => Array.isArray(result) && result.length > 0
36+
);
3137

3238
assert.equal(actualFoldingRanges.length ?? 0, expectedFoldingRanges.length, "Count");
3339

client/src/test/formatting.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as assert from 'assert';
3-
import { getDocUri, activate } from './helper';
3+
import { getDocUri, activate, runOnActivate } from './helper';
44
import { toRange } from './util';
55

66
suite('Should get text edits', () => {
@@ -42,11 +42,18 @@ suite('Should get text edits', () => {
4242

4343
async function testTextEdits(docUri: vscode.Uri, expectedTextEdits: vscode.TextEdit[]) {
4444
await activate(docUri);
45-
const actualEdits = await vscode.commands.executeCommand<vscode.TextEdit[]>(
45+
await vscode.window.showTextDocument(docUri);
46+
const action = () => vscode.commands.executeCommand<vscode.TextEdit[]>(
4647
'vscode.executeFormatDocumentProvider',
4748
docUri,
4849
{ tabSize: 4, insertSpaces: true }
49-
)
50+
);
51+
52+
// Use this method first to ensure the extension is activated.
53+
const actualEdits = await runOnActivate(
54+
action,
55+
(result) => Array.isArray(result) && result.length > 0
56+
);
5057

5158
assert.equal(actualEdits.length ?? 0, expectedTextEdits.length, "Count");
5259

client/src/test/helper.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export let doc: vscode.TextDocument;
1010
export let editor: vscode.TextEditor;
1111
export let documentEol: string;
1212
export let platformEol: string;
13+
const TIMEOUTMS = 5000;
1314

1415
/**
1516
* Activates the vscode.lsp-sample extension
@@ -21,16 +22,31 @@ export async function activate(docUri: vscode.Uri) {
2122
try {
2223
doc = await vscode.workspace.openTextDocument(docUri);
2324
editor = await vscode.window.showTextDocument(doc);
24-
await sleep(500); // Wait for server activation
2525
} catch (e) {
2626
console.error(e);
2727
}
2828
}
2929

30+
export function getTimeout() {
31+
return Date.now() + TIMEOUTMS;
32+
}
33+
3034
async function sleep(ms: number) {
3135
return new Promise(resolve => setTimeout(resolve, ms));
3236
}
3337

38+
export async function runOnActivate<T>(action: () => T|Thenable<T>, test: (result: T) => boolean): Promise<T> {
39+
const timeout = getTimeout();
40+
while (Date.now() < timeout) {
41+
const result = await action();
42+
if (test(result)) {
43+
return result;
44+
}
45+
await sleep(100);
46+
}
47+
throw new Error(`Timed out after ${TIMEOUTMS}`);
48+
}
49+
3450
export const getDocPath = (p: string) => {
3551
return path.resolve(__dirname, '../../../../test/fixtures', p);
3652
};

esbuild.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const esbuild = require('esbuild');
33

44
const production = process.argv.includes('--production');
55
const watch = process.argv.includes('--watch');
6+
const test = process.argv.includes('--test');
67

78
/**
89
* @type {import('esbuild').Plugin}
@@ -77,11 +78,11 @@ async function buildTests() {
7778
}
7879

7980
async function main() {
80-
const buildTasks = [
81-
buildClient(),
82-
buildServer(),
83-
buildTests()
84-
]
81+
const buildTasks = test ? [] : [
82+
buildClient(),
83+
buildServer(),
84+
];
85+
buildTasks.push(buildTests());
8586
const buildContexts = await Promise.all(buildTasks);
8687

8788
if (watch) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"icon": "images/vba-lsp-icon.png",
77
"author": "SSlinky",
88
"license": "MIT",
9-
"version": "1.5.6",
9+
"version": "1.5.7",
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/SSlinky/VBA-LanguageServer"
@@ -179,7 +179,8 @@
179179
},
180180
"scripts": {
181181
"vscode:prepublish": "npm run package",
182-
"compile": "npm run check-types && node esbuild.js",
182+
"build": "npm run check-types && node esbuild.js",
183+
"build-test": "node esbuild.js --test",
183184
"check-types": "tsc --noEmit",
184185
"watch": "npm-run-all -p watch:*",
185186
"watch:esbuild": "node esbuild.js --watch",
@@ -188,7 +189,7 @@
188189
"lint": "eslint ./client/src ./server/src --ext .ts,.tsx",
189190
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
190191
"textMate": "npx js-yaml client/syntaxes/vba.tmLanguage.yaml > client/syntaxes/vba.tmLanguage.json && npm run tmSnapTest",
191-
"antlr": "npm run antlr4ngPre && npm run antlr4ng && npm run antlr4ngFmt && npm run compile",
192+
"antlr": "npm run antlr4ngPre && npm run antlr4ng && npm run antlr4ngFmt && npm run build",
192193
"antlr4ng": "antlr4ng -Dlanguage=TypeScript -visitor -Xlog ./server/src/antlr/vba.g4 -o ./server/src/antlr/out/",
193194
"antlr4ngPre": "antlr4ng -Dlanguage=TypeScript -visitor ./server/src/antlr/vbapre.g4 -o ./server/src/antlr/out/",
194195
"antlr4ngFmt": "antlr4ng -Dlanguage=TypeScript -visitor ./server/src/antlr/vbafmt.g4 -o ./server/src/antlr/out/",
@@ -198,7 +199,7 @@
198199
"tmUnitTest": "vscode-tmgrammar-test ./test/textmate/**/*.vba",
199200
"tmSnapTest": "vscode-tmgrammar-snap ./test/textmate/snapshot/*.??s",
200201
"tmSnapUpdate": "vscode-tmgrammar-snap --updateSnapshot ./test/textmate/snapshot/*.??s",
201-
"vsctest": "vscode-test"
202+
"vsctest": "npm run build-test && vscode-test"
202203
},
203204
"dependencies": {
204205
"antlr4ng": "^3.0.16",

scripts/e2e.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
$ENV:CODE_TESTS_PATH="$(Get-Location)\client\out\test"
2-
$ENV:CODE_TESTS_WORKSPACE="$(Get-Location)\client\testFixture"
3-
Invoke-Expression "node $(Get-Location)\client\out\test\runTest.js"
1+
$ENV:CODE_TESTS_PATH="$(Get-Location)\dist\client\out\test"
2+
$ENV:CODE_TESTS_WORKSPACE="$(Get-Location)\test\fixtures"
3+
Invoke-Expression "node $(Get-Location)\dist\client\out\test\runTest.js"

0 commit comments

Comments
 (0)