Skip to content

Commit

Permalink
Merge pull request #48 from kieler/jep/langiumV3
Browse files Browse the repository at this point in the history
Jep/langium v3
  • Loading branch information
Drakae authored Dec 19, 2024
2 parents 586e72e + 3648058 commit 746775b
Show file tree
Hide file tree
Showing 90 changed files with 1,728 additions and 1,605 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"--extensionDevelopmentPath=${workspaceFolder}/extension"
],
"outFiles": [
"${workspaceFolder}/extension/pack/*.js"
"${workspaceFolder}/extension/pack/**/*.cjs"
],
"sourceMaps": true
},
Expand All @@ -27,7 +27,7 @@
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/extension/pack/language-server.js"
"${workspaceFolder}/extension/pack/src-language-server/*.cjs"
],
"sourceMapPathOverrides": {
"meteor://💻app/*": "${workspaceFolder}/*",
Expand Down
89 changes: 89 additions & 0 deletions extension/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//@ts-check
import * as esbuild from 'esbuild';

const options = {
watch: process.argv.includes('--watch'),
minify: process.argv.includes('--minify'),
};

const successMessage = options.watch
? 'Watch build succeeded'
: 'Build succeeded';

/** @type {import('esbuild').Plugin[]} */
const plugins = [
{
name: 'watch-plugin',
setup(build) {
build.onEnd((result) => {
if (result.errors.length === 0) {
console.log(getTime() + successMessage);
}
});
},
},
];

const nodeContext = await esbuild.context({
entryPoints: [
'src/extension.ts',
'src-language-server/main.ts'
],
outdir: 'pack',
bundle: true,
target: 'es6',
format: 'cjs',
loader: { '.ts': 'ts' },
outExtension: {
'.js': '.cjs',
},
external: ['vscode'],
platform: 'node',
sourcemap: 'inline',
minify: options.minify,
plugins,
});

const browserContext = await esbuild.context({
entryPoints: [
'src-webview/main.ts',
'src-diagram-snippets/main.ts',
'src-context-table/main.ts',
],
outdir: 'pack',
bundle: true,
target: 'es6',
loader: { '.ts': 'ts', '.css': 'css' },
platform: 'browser',
sourcemap: 'inline',
minify: options.minify,
plugins,
});

if (options.watch) {
await Promise.all([
nodeContext.watch(),
browserContext.watch()
]);
} else {
await Promise.all([
nodeContext.rebuild(),
browserContext.rebuild()
]);
nodeContext.dispose();
browserContext.dispose();
}

function getTime() {
const date = new Date();
return `[${`${padZeroes(date.getHours())}:${padZeroes(
date.getMinutes()
)}:${padZeroes(date.getSeconds())}`}] `;
}

/**
* @param {number} i
*/
function padZeroes(i) {
return i.toString().padStart(2, '0');
}
53 changes: 29 additions & 24 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,51 +535,56 @@
"onCommand:pasta.getLTLFormula"
],
"files": [
"lib",
"extension",
"server",
"src",
"src-context-table",
"src-diagram-snippets",
"src-language-server",
"syntaxes",
"webview"
"src-webview",
"pack"
],
"main": "./pack/extension",
"main": "./pack/src/extension.cjs",
"dependencies": {
"langium": "^1.2.0",
"langium-sprotty": "^1.2.0",
"sprotty-elk": "^0.13.0",
"vscode-languageserver": "^8.0.2",
"vscode-languageclient": "^8.0.2",
"reflect-metadata": "^0.1.13",
"langium": "^3.0.0",
"langium-sprotty": "^3.0.0",
"sprotty-elk": "^1.2.0",
"vscode-languageserver": "^9.0.1",
"vscode-languageclient": "^9.0.1",
"reflect-metadata": "^0.2.2",
"feather-icons": "^4.28.0",
"sprotty-vscode-webview": "^0.5.0",
"@kieler/table-webview": "^0.0.5",
"sprotty-vscode-webview": "^1.0.0",
"@kieler/table-webview": "^0.0.7",
"snabbdom": "^3.5.1",
"dayjs": "^1.11.8"
},
"devDependencies": {
"@types/node": "^12.12.6",
"@types/vscode": "^1.80.0",
"@types/node": "^14.17.3",
"@types/vscode": "^1.50.0",
"@types/feather-icons": "^4.7.0",
"rimraf": "^3.0.2",
"source-map-loader": "^3.0.0",
"sprotty-vscode": "^0.5.0",
"ts-loader": "^9.4.2",
"source-map-loader": "^4.0.1",
"sprotty-vscode": "^1.0.0",
"ts-loader": "^9.5.1",
"typescript": "^4.9.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"css-loader": "^6.7.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"css-loader": "^6.8.1",
"file-loader": "^6.2.0",
"langium-cli": "^1.2.1",
"style-loader": "^3.3.1",
"langium-cli": "^3.0.3",
"style-loader": "^3.3.3",
"vsce": "^2.15.0",
"ovsx": "^0.6.0"
"ovsx": "^0.6.0",
"esbuild": "^0.21.2"
},
"type": "module",
"scripts": {
"prepare": "yarn run clean && yarn run langium:generate && yarn run build",
"clean": "rimraf pack",
"langium:generate": "langium generate",
"langium:watch": "langium generate --watch",
"lint": "eslint .",
"build": "yarn run langium:generate && webpack --mode development",
"build": "yarn run langium:generate && tsc -b src src-diagram-snippets src-language-server src-webview src-context-table && node esbuild.mjs",
"watch": "webpack --watch",
"package": "vsce package --yarn -o pasta.vsix",
"predistribute": "yarn run package",
Expand Down
9 changes: 3 additions & 6 deletions extension/src-context-table/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { ContextTableData } from "./utils";
import { ContextTableData } from "./utils-classes";

interface Action {
kind: string;
Expand All @@ -28,16 +28,13 @@ export interface SendContextTableDataAction extends Action {
data: ContextTableData;
}


export namespace SendContextTableDataAction {
export const KIND = "sendContextTableData";

export function create(
data: ContextTableData
): SendContextTableDataAction {
export function create(data: ContextTableData): SendContextTableDataAction {
return {
kind: SendContextTableDataAction.KIND,
data
data,
};
}

Expand Down
40 changes: 30 additions & 10 deletions extension/src-context-table/context-table-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { ContextCell, ContextTableRule, Type, ContextTableVariable } from "./utils";
import { ContextCell } from "./utils";
import { ContextTableRule, ContextTableVariable, Type } from "./utils-classes";

/**
/**
Expand All @@ -27,8 +28,13 @@ import { ContextCell, ContextTableRule, Type, ContextTableVariable } from "./uti
* @param selectedType The currently selected control action type.
* @returns the used rules, whereby the index determines the column they apply to.
*/
export function determineUsedRules(variables: ContextTableVariable[], rules: ContextTableRule[], selectedController: string,
selectedAction: string, selectedType: number): ContextTableRule[][] {
export function determineUsedRules(
variables: ContextTableVariable[],
rules: ContextTableRule[],
selectedController: string,
selectedAction: string,
selectedType: number
): ContextTableRule[][] {
// keeps track of the used rules, whereby the index determines the column
let usedRules: ContextTableRule[][] = [[], [], [], []];
switch (selectedType) {
Expand All @@ -46,19 +52,28 @@ export function determineUsedRules(variables: ContextTableVariable[], rules: Con
}
// determine the used rules
rules.forEach(rule => {
// compare control action of the rule with the selected one and
// compare control action of the rule with the selected one and
// the context of the rule with the current context
if (rule.controlAction.controller === selectedController && rule.controlAction.action === selectedAction
&& checkValues(rule.variables, variables)) {
if (
rule.controlAction.controller === selectedController &&
rule.controlAction.action === selectedAction &&
checkValues(rule.variables, variables)
) {
// determine the column for which the rule applies
const ruleType = rule.type.toLowerCase();
if (selectedType === Type.NOT_PROVIDED && ruleType === "not-provided") {
usedRules[0].push(rule);
} else if (selectedType !== Type.NOT_PROVIDED && ruleType === "provided") {
usedRules[0].push(rule);
} else if (selectedType !== Type.NOT_PROVIDED && (ruleType === "too-early" || ruleType === "too-late" || ruleType === "wrong-time")) {
} else if (
selectedType !== Type.NOT_PROVIDED &&
(ruleType === "too-early" || ruleType === "too-late" || ruleType === "wrong-time")
) {
usedRules[1].push(rule);
} else if (selectedType !== Type.NOT_PROVIDED && (ruleType === "stopped-too-soon" || ruleType === "applied-too-long")) {
} else if (
selectedType !== Type.NOT_PROVIDED &&
(ruleType === "stopped-too-soon" || ruleType === "applied-too-long")
) {
usedRules[2].push(rule);
} else if (selectedType === Type.BOTH && ruleType === "not-provided") {
usedRules[3].push(rule);
Expand All @@ -73,7 +88,7 @@ export function determineUsedRules(variables: ContextTableVariable[], rules: Con
* @param results The hazards and rules for the result columns.
* @returns The cells for the "Hazardous?"-column.
*/
export function createResults(results: { hazards: string[], rules: ContextTableRule[]; }[]): ContextCell[] {
export function createResults(results: { hazards: string[]; rules: ContextTableRule[] }[]): ContextCell[] {
const cells: ContextCell[] = [];
// keeps track on how many neihbouring columns have no rule applied
let noAppliedRuleCounter: number = 0;
Expand All @@ -95,7 +110,12 @@ export function createResults(results: { hazards: string[], rules: ContextTableR
}
const ucas = results[hazardColumn].rules.map(rule => rule.id);
// add the hazards, defined by the rule, as a cell
cells.push({ cssClass: "result", value: ucas.toString(), colSpan: 1, title: results[hazardColumn].hazards.toString() });
cells.push({
cssClass: "result",
value: ucas.toString(),
colSpan: 1,
title: results[hazardColumn].hazards.toString(),
});
}
}
return cells;
Expand Down
14 changes: 4 additions & 10 deletions extension/src-context-table/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
* SPDX-License-Identifier: EPL-2.0
*/

import "./css/table.css";
import { Table } from "@kieler/table-webview/lib/table";
import { VNode } from "snabbdom";
import { SendContextTableDataAction } from "./actions";
import { createResults, determineUsedRules } from "./context-table-logic";
import "./css/table.css";
import { createHeaderElement, createHeaderRow, createRow, createTable, createTHead, initContextTable, patch } from "./html";
import {
addSelector,
addText,
ContextCell,
ContextTableControlAction,
convertControlActionsToStrings,
replaceSelector,
ContextTableRule,
ContextTableSystemVariables,
Type,
ContextTableVariable,
ContextTableVariableValues,
Row,
} from "./utils";
import { VNode } from "snabbdom";
import { createResults, determineUsedRules } from "./context-table-logic";
import { ContextTableControlAction, ContextTableRule, ContextTableSystemVariables, ContextTableVariable, ContextTableVariableValues, Row, Type } from './utils-classes';

interface vscode {
postMessage(message: any): void;
Expand Down
15 changes: 15 additions & 0 deletions extension/src-context-table/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../pack/src-context-table",
"target": "ES2017",
"lib": [
"es2017",
"dom"
],
"module": "commonjs",
"moduleResolution": "node",
"jsx": "react",
"jsxFactory": "jsx"
}
}
Loading

0 comments on commit 746775b

Please sign in to comment.