Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
npm run antlr4ngPre
npm run antlr4ngFmt
mv ./server/src/antlr/out/server/src/antlr/* ./server/src/antlr/out
- run: npm run compile
- run: npm run build
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
Expand Down
8 changes: 3 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"--extensionDevelopmentPath=${workspaceRoot}",
"${workspaceFolder}/sample"
],
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
"preLaunchTask": {
"type": "npm",
"script": "compile"
Expand All @@ -23,7 +22,6 @@
"name": "Attach to Server",
"port": 6009,
"restart": true,
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
},
{
"name": "Language Server E2E Test",
Expand All @@ -32,10 +30,10 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/client/out/test/index",
"${workspaceRoot}/client/testFixture"
"--extensionTestsPath=${workspaceRoot}/dist/client/out/test/index",
"${workspaceRoot}/test/fixtures"
],
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
"outFiles": ["${workspaceRoot}/dist/client/out/test/**/*.js"]
},
{
"name": "Debug ANTLR4 grammar",
Expand Down
9 changes: 6 additions & 3 deletions client/src/test/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, activate } from './helper';
import { getDocUri, activate, runOnActivate } from './helper';
import { toRange } from './util';

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

const actualDiagnostics = vscode.languages.getDiagnostics(docUri);

// Use this method first to ensure the extension is activated.
const actualDiagnostics = await runOnActivate(
() => vscode.languages.getDiagnostics(docUri),
(result) => result.length > 0
);
assert.equal(actualDiagnostics.length, expectedDiagnostics.length, "Count");

expectedDiagnostics.forEach((expectedDiagnostic, i) => {
Expand Down
10 changes: 8 additions & 2 deletions client/src/test/foldingRanges.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, activate } from './helper';
import { getDocUri, activate, runOnActivate } from './helper';

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

async function testFoldingRanges(docUri: vscode.Uri, expectedFoldingRanges: vscode.FoldingRange[]) {
await activate(docUri);
const actualFoldingRanges = await vscode.commands.executeCommand<vscode.FoldingRange[]>(
const action = () => vscode.commands.executeCommand<vscode.FoldingRange[]>(
'vscode.executeFoldingRangeProvider',
docUri
)

// Use this method first to ensure the extension is activated.
const actualFoldingRanges = await runOnActivate(
action,
(result) => Array.isArray(result) && result.length > 0
);

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

Expand Down
13 changes: 10 additions & 3 deletions client/src/test/formatting.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, activate } from './helper';
import { getDocUri, activate, runOnActivate } from './helper';
import { toRange } from './util';

suite('Should get text edits', () => {
Expand Down Expand Up @@ -42,11 +42,18 @@ suite('Should get text edits', () => {

async function testTextEdits(docUri: vscode.Uri, expectedTextEdits: vscode.TextEdit[]) {
await activate(docUri);
const actualEdits = await vscode.commands.executeCommand<vscode.TextEdit[]>(
await vscode.window.showTextDocument(docUri);
const action = () => vscode.commands.executeCommand<vscode.TextEdit[]>(
'vscode.executeFormatDocumentProvider',
docUri,
{ tabSize: 4, insertSpaces: true }
)
);

// Use this method first to ensure the extension is activated.
const actualEdits = await runOnActivate(
action,
(result) => Array.isArray(result) && result.length > 0
);

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

Expand Down
18 changes: 17 additions & 1 deletion client/src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export let doc: vscode.TextDocument;
export let editor: vscode.TextEditor;
export let documentEol: string;
export let platformEol: string;
const TIMEOUTMS = 5000;

/**
* Activates the vscode.lsp-sample extension
Expand All @@ -21,16 +22,31 @@ export async function activate(docUri: vscode.Uri) {
try {
doc = await vscode.workspace.openTextDocument(docUri);
editor = await vscode.window.showTextDocument(doc);
await sleep(500); // Wait for server activation
} catch (e) {
console.error(e);
}
}

export function getTimeout() {
return Date.now() + TIMEOUTMS;
}

async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

export async function runOnActivate<T>(action: () => T|Thenable<T>, test: (result: T) => boolean): Promise<T> {
const timeout = getTimeout();
while (Date.now() < timeout) {
const result = await action();
if (test(result)) {
return result;
}
await sleep(100);
}
throw new Error(`Timed out after ${TIMEOUTMS}`);
}

export const getDocPath = (p: string) => {
return path.resolve(__dirname, '../../../../test/fixtures', p);
};
Expand Down
11 changes: 6 additions & 5 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const esbuild = require('esbuild');

const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
const test = process.argv.includes('--test');

/**
* @type {import('esbuild').Plugin}
Expand Down Expand Up @@ -77,11 +78,11 @@ async function buildTests() {
}

async function main() {
const buildTasks = [
buildClient(),
buildServer(),
buildTests()
]
const buildTasks = test ? [] : [
buildClient(),
buildServer(),
];
buildTasks.push(buildTests());
const buildContexts = await Promise.all(buildTasks);

if (watch) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"icon": "images/vba-lsp-icon.png",
"author": "SSlinky",
"license": "MIT",
"version": "1.5.6",
"version": "1.5.7",
"repository": {
"type": "git",
"url": "https://github.com/SSlinky/VBA-LanguageServer"
Expand Down Expand Up @@ -179,7 +179,8 @@
},
"scripts": {
"vscode:prepublish": "npm run package",
"compile": "npm run check-types && node esbuild.js",
"build": "npm run check-types && node esbuild.js",
"build-test": "node esbuild.js --test",
"check-types": "tsc --noEmit",
"watch": "npm-run-all -p watch:*",
"watch:esbuild": "node esbuild.js --watch",
Expand All @@ -188,7 +189,7 @@
"lint": "eslint ./client/src ./server/src --ext .ts,.tsx",
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
"textMate": "npx js-yaml client/syntaxes/vba.tmLanguage.yaml > client/syntaxes/vba.tmLanguage.json && npm run tmSnapTest",
"antlr": "npm run antlr4ngPre && npm run antlr4ng && npm run antlr4ngFmt && npm run compile",
"antlr": "npm run antlr4ngPre && npm run antlr4ng && npm run antlr4ngFmt && npm run build",
"antlr4ng": "antlr4ng -Dlanguage=TypeScript -visitor -Xlog ./server/src/antlr/vba.g4 -o ./server/src/antlr/out/",
"antlr4ngPre": "antlr4ng -Dlanguage=TypeScript -visitor ./server/src/antlr/vbapre.g4 -o ./server/src/antlr/out/",
"antlr4ngFmt": "antlr4ng -Dlanguage=TypeScript -visitor ./server/src/antlr/vbafmt.g4 -o ./server/src/antlr/out/",
Expand All @@ -198,7 +199,7 @@
"tmUnitTest": "vscode-tmgrammar-test ./test/textmate/**/*.vba",
"tmSnapTest": "vscode-tmgrammar-snap ./test/textmate/snapshot/*.??s",
"tmSnapUpdate": "vscode-tmgrammar-snap --updateSnapshot ./test/textmate/snapshot/*.??s",
"vsctest": "vscode-test"
"vsctest": "npm run build-test && vscode-test"
},
"dependencies": {
"antlr4ng": "^3.0.16",
Expand Down
6 changes: 3 additions & 3 deletions scripts/e2e.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$ENV:CODE_TESTS_PATH="$(Get-Location)\client\out\test"
$ENV:CODE_TESTS_WORKSPACE="$(Get-Location)\client\testFixture"
Invoke-Expression "node $(Get-Location)\client\out\test\runTest.js"
$ENV:CODE_TESTS_PATH="$(Get-Location)\dist\client\out\test"
$ENV:CODE_TESTS_WORKSPACE="$(Get-Location)\test\fixtures"
Invoke-Expression "node $(Get-Location)\dist\client\out\test\runTest.js"
6 changes: 3 additions & 3 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

export CODE_TESTS_PATH="$(pwd)/client/out/test"
export CODE_TESTS_WORKSPACE="$(pwd)/client/testFixture"
export CODE_TESTS_PATH="$(pwd)/dist/client/out/test"
export CODE_TESTS_WORKSPACE="$(pwd)/test/fixtures"

node "$(pwd)/client/out/test/runTest"
node "$(pwd)/dist/client/out/test/runTest"
9 changes: 8 additions & 1 deletion server/src/capabilities/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class DuplicateDeclarationDiagnostic extends BaseDiagnostic {
// test
export class ShadowDeclarationDiagnostic extends BaseDiagnostic {
message = "Declaration is shadowed in the local scope.";
severity = DiagnosticSeverity.Error;
severity = DiagnosticSeverity.Warning;
constructor(range: Range) {
super(range);
}
Expand Down Expand Up @@ -124,4 +124,11 @@ export class LegacyFunctionalityDiagnostic extends BaseDiagnostic {
constructor(range: Range, functionalityType: string) {
super(range, `${functionalityType} are legacy functionality and should be avoided.`);
}
}

export class ParserErrorDiagnostic extends BaseDiagnostic {
severity = DiagnosticSeverity.Error;
constructor(range: Range, msg: string) {
super(range, msg);
}
}
21 changes: 21 additions & 0 deletions server/src/project/elements/generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Core
import { TextDocument } from 'vscode-languageserver-textdocument';

// Antlr
import { ErrorNode, ParserRuleContext } from 'antlr4ng';

// Project
import { BaseContextSyntaxElement, BaseSyntaxElement } from './base';
import { DiagnosticCapability } from '../../capabilities/capabilities';
import { ParserErrorDiagnostic } from '../../capabilities/diagnostics';


export class ErrorRuleElement extends BaseContextSyntaxElement<ParserRuleContext> {
constructor(node: ErrorNode, doc: TextDocument) {
super(node.parent as ParserRuleContext, doc);
this.diagnosticCapability = new DiagnosticCapability(this);
this.diagnosticCapability.diagnostics.push(
new ParserErrorDiagnostic(this.context.range, node.getText())
);
}
}
4 changes: 3 additions & 1 deletion server/src/project/elements/procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export class SubDeclarationElement extends BaseProcedureElement<SubroutineDeclar
this.identifierCapability = new IdentifierCapability({
element: this,
getNameContext: () => ctx.subroutineName()?.ambiguousIdentifier(),
// For some reason the IdentifierCapability throws if no default is given
// despite it not actually ever needing it. Most unusual.
defaultRange: () => this.context.range
});
this.foldingRangeCapability.openWord = `Sub ${this.identifierCapability.name}`;
this.foldingRangeCapability.closeWord = 'End Sub';

}
}

Expand Down
Loading