Skip to content

Commit

Permalink
Merge pull request #38 from kieler/jep/utility
Browse files Browse the repository at this point in the history
Jep/utility
  • Loading branch information
Drakae authored Aug 26, 2024
2 parents 8da5226 + 74a0eed commit ef24bb1
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 138 deletions.
166 changes: 131 additions & 35 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,40 @@
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.checkConstraintsForUCAs",
"command": "pasta.stpa.checks.unsetCheckResponsibilitiesForConstraints",
"title": "✓ Set the responsibilities for constraints check",
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.setCheckConstraintsForUCAs",
"title": "Set the constraints for UCA check",
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.checkScenariosForUCAs",
"command": "pasta.stpa.checks.unsetCheckConstraintsForUCAs",
"title": "✓ Set the constraints for UCA check",
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.setCheckScenariosForUCAs",
"title": "Set the scenarios for UCA check",
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.checkSafetyRequirementsForUCAs",
"command": "pasta.stpa.checks.unsetCheckScenariosForUCAs",
"title": "✓ Set the scenarios for UCA check",
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.setCheckSafetyRequirementsForUCAs",
"title": "Set the safety requirements for UCA check",
"category": "STPA Checks"
},
{
"command": "pasta.stpa.checks.unsetCheckSafetyRequirementsForUCAs",
"title": "✓ Set the safety requirements for UCA check",
"category": "STPA Checks"
},
{
"command": "pasta.IDs.undo",
"title": "Executes the undo action",
Expand Down Expand Up @@ -161,6 +181,16 @@
"command": "pasta.stpa.snippets.add",
"title": "Add STPA Diagram Snippet",
"category": "STPA Snippets"
},
{
"command": "pasta.stpa.setIDGeneration",
"title": "Automatic ID Generation",
"category": "STPA ID Enforcement"
},
{
"command": "pasta.stpa.unsetIDGeneration",
"title": "✓ Automatic ID Generation",
"category": "STPA ID Enforcement"
}
],
"menus": {
Expand Down Expand Up @@ -198,19 +228,35 @@
},
{
"command": "pasta.stpa.checks.setCheckResponsibilitiesForConstraints",
"when": "editorLangId == 'stpa'"
"when": "editorLangId == 'stpa' && checkResponsibilitiesForConstraints == false"
},
{
"command": "pasta.stpa.checks.checkConstraintsForUCAs",
"when": "editorLangId == 'stpa'"
"command": "pasta.stpa.checks.unsetCheckResponsibilitiesForConstraints",
"when": "editorLangId == 'stpa' && checkResponsibilitiesForConstraints == true"
},
{
"command": "pasta.stpa.checks.checkScenariosForUCAs",
"when": "editorLangId == 'stpa'"
"command": "pasta.stpa.checks.setCheckConstraintsForUCAs",
"when": "editorLangId == 'stpa' && checkConstraintsForUCAs == false"
},
{
"command": "pasta.stpa.checks.checkSafetyRequirementsForUCAs",
"when": "editorLangId == 'stpa'"
"command": "pasta.stpa.checks.unsetCheckConstraintsForUCAs",
"when": "editorLangId == 'stpa' && checkConstraintsForUCAs == true"
},
{
"command": "pasta.stpa.checks.setCheckScenariosForUCAs",
"when": "editorLangId == 'stpa' && checkScenariosForUCAs == false"
},
{
"command": "pasta.stpa.checks.unsetCheckScenariosForUCAs",
"when": "editorLangId == 'stpa' && checkScenariosForUCAs == true"
},
{
"command": "pasta.stpa.checks.setCheckSafetyRequirementsForUCAs",
"when": "editorLangId == 'stpa' && checkSafetyRequirementsForUCAs == false"
},
{
"command": "pasta.stpa.checks.unsetCheckSafetyRequirementsForUCAs",
"when": "editorLangId == 'stpa' && checkSafetyRequirementsForUCAs == true"
},
{
"command": "pasta.stpa.SBM.generation",
Expand All @@ -228,6 +274,14 @@
"command": "pasta.stpa.snippets.add",
"when": "editorLangId == 'stpa'"
},
{
"command": "pasta.stpa.setIDGeneration",
"when": "editorLangId == 'stpa' && pasta.idGeneration == false"
},
{
"command": "pasta.stpa.unsetIDGeneration",
"when": "editorLangId == 'stpa' && pasta.idGeneration == true"
},
{
"command": "pasta.fta.cutSets",
"when": "editorLangId == 'fta'"
Expand All @@ -248,67 +302,105 @@
"when": "editorLangId == 'stpa'",
"group": "navigation"
},
{
"submenu": "pasta",
"group": "pasta"
}
],
"pasta": [
{
"submenu": "pasta.stpa.checks",
"group": "checks"
"group": "stpa@2"
},
{
"submenu": "pasta.fta.generate",
"group": "generate"
"command": "pasta.stpa.snippets.add",
"when": "editorLangId == 'stpa'",
"group": "stpa@6"
},
{
"command": "pasta.stpa.SBM.generation",
"when": "editorLangId == 'stpa'",
"group": "stpa"
"group": "stpa@5"
},
{
"command": "pasta.stpa.md.creation",
"when": "editorLangId == 'stpa'",
"group": "stpa"
"group": "stpa@3"
},
{
"command": "pasta.stpa.ft.generation",
"when": "editorLangId == 'stpa'",
"group": "stpa"
"group": "stpa@4"
},
{
"command": "pasta.stpa.snippets.add",
"when": "editorLangId == 'stpa'",
"group": "navigation"
"command": "pasta.stpa.setIDGeneration",
"when": "editorLangId == 'stpa' && pasta.idGeneration == false",
"group": "stpa@1"
},
{
"command": "pasta.stpa.unsetIDGeneration",
"when": "editorLangId == 'stpa' && pasta.idGeneration == true",
"group": "stpa@1"
},
{
"command": "pasta.fta.cutSets",
"when": "editorLangId == 'fta'",
"group": "fta@1"
},
{
"command": "pasta.fta.minimalCutSets",
"when": "editorLangId == 'fta'",
"group": "fta@2"
}
],
"pasta.stpa.checks": [
{
"command": "pasta.stpa.checks.setCheckResponsibilitiesForConstraints",
"title": "editorLangId == 'stpa'",
"group": "navigation"
"when": "editorLangId == 'stpa' && pasta.checkResponsibilitiesForConstraints == false",
"group": "checks@1"
},
{
"command": "pasta.stpa.checks.checkConstraintsForUCAs",
"command": "pasta.stpa.checks.unsetCheckResponsibilitiesForConstraints",
"title": "editorLangId == 'stpa'",
"group": "navigation"
"when": "editorLangId == 'stpa' && pasta.checkResponsibilitiesForConstraints == true",
"group": "checks@1"
},
{
"command": "pasta.stpa.checks.checkScenariosForUCAs",
"command": "pasta.stpa.checks.setCheckConstraintsForUCAs",
"title": "editorLangId == 'stpa'",
"group": "navigation"
"when": "editorLangId == 'stpa' && pasta.checkConstraintsForUCAs == false",
"group": "checks@2"
},
{
"command": "pasta.stpa.checks.checkSafetyRequirementsForUCAs",
"command": "pasta.stpa.checks.unsetCheckConstraintsForUCAs",
"title": "editorLangId == 'stpa'",
"group": "navigation"
}
],
"pasta.fta.generate": [
"when": "editorLangId == 'stpa' && pasta.checkConstraintsForUCAs == true",
"group": "checks@2"
},
{
"command": "pasta.fta.cutSets",
"when": "editorLangId == 'fta'",
"group": "navigation"
"command": "pasta.stpa.checks.setCheckScenariosForUCAs",
"title": "editorLangId == 'stpa'",
"when": "editorLangId == 'stpa' && pasta.checkScenariosForUCAs == false",
"group": "checks@3"
},
{
"command": "pasta.fta.minimalCutSets",
"when": "editorLangId == 'fta'",
"group": "navigation"
"command": "pasta.stpa.checks.unsetCheckScenariosForUCAs",
"title": "editorLangId == 'stpa'",
"when": "editorLangId == 'stpa' && pasta.checkScenariosForUCAs == true",
"group": "checks@3"
},
{
"command": "pasta.stpa.checks.setCheckSafetyRequirementsForUCAs",
"title": "editorLangId == 'stpa'",
"when": "editorLangId == 'stpa' && pasta.checkSafetyRequirementsForUCAs == false",
"group": "checks@4"
},
{
"command": "pasta.stpa.checks.unsetCheckSafetyRequirementsForUCAs",
"title": "editorLangId == 'stpa'",
"when": "editorLangId == 'stpa' && pasta.checkSafetyRequirementsForUCAs == true",
"group": "checks@4"
}
],
"editor/title": [
Expand Down Expand Up @@ -337,6 +429,10 @@
]
},
"submenus": [
{
"id": "pasta",
"label": "PASTA"
},
{
"id": "pasta.stpa.checks",
"label": "Validation Checks"
Expand Down
51 changes: 24 additions & 27 deletions extension/src-language-server/fta/fta-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,6 @@ export function addFTANotificationHandler(
sharedServices: LangiumSprottySharedServices
): void {
addCutSetsHandler(connection, ftaServices, sharedServices);
addStorageHandler(connection, ftaServices);
}

/**
* Adds handlers for notifications regarding the storage.
* @param connection
* @param ftaServices
*/
function addStorageHandler(connection: Connection, ftaServices: FtaServices): void {
// handle configuration/storage init
connection.onNotification("config/init", ({ clientId, options }) => {
// update synthesis options
if (options["synthesisOptions"] && clientId !== "") {
Object.entries(options["synthesisOptions"]).forEach(([key, value]) => {
ftaServices.options.SynthesisOptions.setOption(key, value);
});
}
});

// handle reset of the storage
connection.onRequest("config/reset", () => {
// reset synthesis options
ftaServices.options.SynthesisOptions.resetAll();
return;
});
}

/**
Expand Down Expand Up @@ -104,7 +79,7 @@ async function cutSetsRequested(
if (model.topEvent) {
nodes.push(model.topEvent);
}
const startNode = startId ? nodes.find((node) => node.name === startId) : undefined;
const startNode = startId ? nodes.find(node => node.name === startId) : undefined;
const cutSets = minimal ? determineMinimalCutSets(nodes, startNode) : determineCutSetsForFT(nodes, startNode);
// determine single points of failure
const spofs: string[] = [];
Expand All @@ -116,7 +91,7 @@ async function cutSetsRequested(
ftaServices.options.SynthesisOptions.setSpofs(spofs);
// create dropdown values
const cutSetsString = cutSetsToString(cutSets);
const dropdownValues = cutSetsString.map((cutSet) => {
const dropdownValues = cutSetsString.map(cutSet => {
return { displayName: cutSet, id: cutSet };
});
ftaServices.options.SynthesisOptions.updateCutSetsOption(dropdownValues);
Expand All @@ -127,3 +102,25 @@ function resetCutSets(ftaServices: FtaServices): void {
ftaServices.options.SynthesisOptions.resetCutSets();
return;
}

/**
* Handles the initialization of the FTA configuration.
* @param clientId The client id.
* @param options The options for the configuration.
* @param ftaServices The services for FTA.
*/
export function handleFTAConfigInit(clientId: string, options: Record<string, any>, ftaServices: FtaServices): void {
if (options["synthesisOptions"] && clientId !== "") {
Object.entries(options["synthesisOptions"]).forEach(([key, value]) => {
ftaServices.options.SynthesisOptions.setOption(key, value);
});
}
}

/**
* Resets the FTA configuration.
* @param ftaServices The services for FTA.
*/
export function handleFTAConfigReset(ftaServices: FtaServices): void {
ftaServices.options.SynthesisOptions.resetAll();
}
17 changes: 16 additions & 1 deletion extension/src-language-server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

import { LangiumSprottySharedServices } from "langium-sprotty";
import { Connection, Range } from "vscode-languageserver";
import { handleFTAConfigInit, handleFTAConfigReset } from './fta/fta-message-handler';
import { FtaServices } from './fta/fta-module';
import { getRangeOfNodeFTA } from "./fta/utils";
import { Model, isModel, isModelFTA } from "./generated/ast";
import { handleSTPAConfigInit, handleSTPAConfigReset } from './stpa/message-handler';
import { StpaServices } from './stpa/stpa-module';
import { getRangeOfNodeSTPA } from "./stpa/utils";
import { getModel } from "./utils";

Expand All @@ -27,7 +31,7 @@ import { getModel } from "./utils";
* @param connection Connection to the extension.
* @param shared Shared services containing the workspace.
*/
export function addNotificationHandler(connection: Connection, shared: LangiumSprottySharedServices): void {
export function addNotificationHandler(connection: Connection, shared: LangiumSprottySharedServices,stpaServices: StpaServices, ftaServices: FtaServices): void {
// node selection in diagram
connection.onNotification("diagram/selected", async (msg: { label: string; uri: string }) => {
// get the current model
Expand All @@ -53,4 +57,15 @@ export function addNotificationHandler(connection: Connection, shared: LangiumSp
console.log("The selected element could not be found in the editor.");
}
});
// handle configuration/storage init
connection.onNotification("config/init", ({ clientId, options }) => {
handleSTPAConfigInit(clientId, options, stpaServices);
handleFTAConfigInit(clientId, options, ftaServices);
});

// handle reset of the storage
connection.onRequest("config/reset", () => {
handleSTPAConfigReset(stpaServices);
handleFTAConfigReset(ftaServices);
});
}
2 changes: 1 addition & 1 deletion extension/src-language-server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ addDiagramHandler(connection, shared);

addSTPANotificationHandler(connection, stpa, shared);
addFTANotificationHandler(connection, fta, shared);
addNotificationHandler(connection, shared);
addNotificationHandler(connection, shared, stpa, fta);

connection.onInitialized(() => connection.sendNotification("ready"));
Loading

0 comments on commit ef24bb1

Please sign in to comment.