Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Support Mod Actions #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"url": "https://github.com/Cosmoteer-Modding-Tools/cosmoteer-lsp"
},
"engines": {
"vscode": "^1.75.0"
"vscode": "^1.90.0"
},
"dependencies": {
"@vscode/l10n": "^0.0.18",
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@types/vscode": "^1.75.1",
"@vscode/test-electron": "^2.3.9"
"@types/vscode": "^1.90.0",
"@vscode/test-electron": "^2.4.1"
}
}
}
4 changes: 2 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } f

let client: LanguageClient;

export function activate(context: ExtensionContext) {
export async function activate(context: ExtensionContext) {
// The server is implemented in node
const serverModule = context.asAbsolutePath(path.join('out', 'server', 'src', 'server.js'));

Expand Down Expand Up @@ -48,7 +48,7 @@ export function activate(context: ExtensionContext) {
await commands.executeCommand('workbench.action.openSettings2', params);
});

client.start();
return client.start();
}

export function deactivate(): Thenable<void> | undefined {
Expand Down
27 changes: 7 additions & 20 deletions client/src/test/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@ import * as assert from 'assert';
import { getDocUri, activate } from './helper';

suite('Should get diagnostics', () => {
const docUri = getDocUri('diagnostics.txt');

test('Diagnoses uppercase texts', async () => {
await testDiagnostics(docUri, [
{
message: 'ANY is all uppercase.',
range: toRange(0, 0, 0, 3),
severity: vscode.DiagnosticSeverity.Warning,
source: 'ex',
},
{
message: 'ANY is all uppercase.',
range: toRange(0, 14, 0, 17),
severity: vscode.DiagnosticSeverity.Warning,
source: 'ex',
},
test('Diagnoses inheritances', async () => {
await testDiagnostics(getDocUri('diagnostics_inheritance.rules'), [
{
message: 'OS is all uppercase.',
range: toRange(0, 18, 0, 20),
severity: vscode.DiagnosticSeverity.Warning,
source: 'ex',
message: 'Expected reference value after reference value but found Number',
range: toRange(0, 7, 0, 12),
severity: vscode.DiagnosticSeverity.Error,
source: 'cosmoteer-language-server',
},
]);
});
Expand All @@ -52,5 +38,6 @@ async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.D
assert.equal(actualDiagnostic.message, expectedDiagnostic.message);
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);
assert.equal(actualDiagnostic.source, expectedDiagnostic.source);
});
}
12 changes: 7 additions & 5 deletions client/src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export let platformEol: string;
/**
* Activates the vscode.lsp-sample extension
*/
export async function activate(docUri: vscode.Uri) {
export async function activate(docUri: vscode.Uri, timeout = 2_000) {
// The extensionId is `publisher.name` from package.json
const ext = vscode.extensions.getExtension('vscode-samples.lsp-sample')!;
await ext.activate();
const ext = vscode.extensions.getExtension('TrustNoOneElse.cosmoteer-language-server');
if (!ext.isActive) {
await ext.activate();
}
try {
doc = await vscode.workspace.openTextDocument(docUri);
editor = await vscode.window.showTextDocument(doc);
await sleep(2000); // Wait for server activation
await sleep(timeout); // Wait for init
} catch (e) {
console.error(e);
}
Expand All @@ -32,7 +34,7 @@ async function sleep(ms: number) {
}

export const getDocPath = (p: string) => {
return path.resolve(__dirname, '../../testFixture', p);
return path.resolve(__dirname, '../../client/testFixture', p);
};
export const getDocUri = (p: string) => {
return vscode.Uri.file(getDocPath(p));
Expand Down
6 changes: 3 additions & 3 deletions client/src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
import path from 'path';
import Mocha from 'mocha';
import glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
Expand Down
1 change: 0 additions & 1 deletion client/testFixture/diagnostics.txt

This file was deleted.

3 changes: 3 additions & 0 deletions client/testFixture/diagnostics_inheritance.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Test : 12356 {

}
1 change: 1 addition & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"rootDir": "src",
"sourceMap": true,
"incremental": true,
"esModuleInterop": true,
"tsBuildInfoFile": "../out/tsbuildinfo.json"
},
"include": ["src"],
Expand Down
66 changes: 46 additions & 20 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,55 @@ import { context } from 'esbuild';

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

async function main() {
const ctx = await context({
entryPoints: ['client/src/extension.ts', 'server/src/server.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outdir: 'out',
external: ['vscode'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
if (!test) {
const ctx = await context({
entryPoints: ['client/src/extension.ts', 'server/src/server.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outdir: 'out',
external: ['vscode'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
} else {
await ctx.rebuild();
await ctx.dispose();
console.log('Compiling tests...');
const testCtx = await context({
entryPoints: ['client/src/test/**/*.ts'],
bundle: false,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outdir: 'out/test',
logLevel: 'debug',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await testCtx.watch();
} else {
await testCtx.rebuild();
await testCtx.dispose();
}
}
}

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,26 @@
"compile:tsc": "tsc -b",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"watch:esbuild": "node esbuild.mjs --watch",
"watch:esbuild-test": "node esbuild.mjs --watch --test",
"lint": "eslint ./client/src ./server/src",
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
"test": "sh ./scripts/e2e.sh",
"check-types": "tsc --noEmit",
"l10n": "npx @vscode/l10n-dev export --outDir ./l10n .\\server"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.9",
"@types/node": "^20.15.0",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"@typescript-eslint/eslint-plugin": "^8.9.0",
"@typescript-eslint/parser": "^8.9.0",
"@vscode/l10n-dev": "^0.0.35",
"esbuild": "^0.24.0",
"eslint": "^9.12.0",
"eslint-config-prettier": "^9.1.0",
"mocha": "^10.3.0",
"mocha": "^10.7.3",
"npm-run-all": "^4.1.5",
"prettier": "3.3.3",
"typescript": "^5.5.4"
"typescript": "^5.6.3"
}
}
}
4 changes: 2 additions & 2 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_PATH="$(pwd)/out/test"
export CODE_TESTS_WORKSPACE="$(pwd)/client/testFixture"

node "$(pwd)/client/out/test/runTest"
node "$(pwd)/out/test/runTest"
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,18 @@ const traversePath = async (
const traverseOwnPath = async (parts: string[], node: AbstractNode, cancellationToken: CancellationToken) => {
const currentLocation = getStartOfAstNode(node).uri;
if (parts.some((part) => part.endsWith('.rules>'))) {
const indexOfRules = parts.findIndex((part) => part.endsWith('.rules>'));
const ownPath = join(
filePathToDirectoryPath(currentLocation),
parts
.slice(
0,
parts.findIndex((part) => part.endsWith('.rules'))
)
.slice(0, indexOfRules === 0 ? 1 : indexOfRules)
.join('/')
.replaceAll(/[<>]/g, EMPTY_STRING)
);
if (cancellationToken.isCancellationRequested) throw new CancellationError();
const nextNode = await parseFilePath(ownPath, cancellationToken);
return await traversePath(
parts.slice(parts.findIndex((part) => part.endsWith('.rules'))).join('/'),
parts.slice(indexOfRules === 0 ? 1 : indexOfRules).join('/'),
nextNode,
cancellationToken
);
Expand Down Expand Up @@ -294,12 +292,9 @@ const traverseReferencePath = async (parts: string[], node: AbstractNode, cancel
) {
const value = (isValueNode(currentNode) ? currentNode : currentNode.right) as ValueNode;
if (value.valueType.type !== 'Reference') return [];
const node = await navigation.navigate(
value.valueType.value,
currentNode,
getStartOfAstNode(currentNode).uri,
cancellationToken
);
const node = await navigation
.navigate(value.valueType.value, currentNode, getStartOfAstNode(currentNode).uri, cancellationToken)
.catch(() => undefined);
if (node?.type === 'File') {
if (cancellationToken.isCancellationRequested) throw new CancellationError();
const parsedDocument = await parseFile(node);
Expand Down
12 changes: 11 additions & 1 deletion server/src/lexer/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,18 @@ export const lexer = (input: string): Token[] => {
lineOffset++;
if (current >= input.length) break;
}
const untrimmedValue = value;
value = value.trim();
tokens.push(createToken(TOKEN_TYPES.VALUE, lineOffsetBefore, lineNumber, start, current, value));
tokens.push(
createToken(
TOKEN_TYPES.VALUE,
lineOffsetBefore,
lineNumber,
start,
current - (untrimmedValue.length - value.length),
value
)
);
continue;
}
if (char === '\\') {
Expand Down
Loading