diff --git a/extension/package.json b/extension/package.json index 225afbc1..223346b9 100644 --- a/extension/package.json +++ b/extension/package.json @@ -313,7 +313,7 @@ "editor/title": [ { "command": "pasta.diagram.open", - "when": "editorLangId == 'stpa' || editorLangId == 'fta'", + "when": "editorLangId in pasta.languages", "group": "navigation" }, { diff --git a/extension/src-language-server/fta/diagram/fta-layout-config.ts b/extension/src-language-server/fta/diagram/fta-layout-config.ts index 471adc02..004cb9a5 100644 --- a/extension/src-language-server/fta/diagram/fta-layout-config.ts +++ b/extension/src-language-server/fta/diagram/fta-layout-config.ts @@ -20,14 +20,14 @@ import { DefaultLayoutConfigurator } from "sprotty-elk/lib/elk-layout"; import { SGraph, SModelIndex, SNode } from "sprotty-protocol"; export class FtaLayoutConfigurator extends DefaultLayoutConfigurator { - protected graphOptions(sgraph: SGraph, index: SModelIndex): LayoutOptions { + protected graphOptions(_sgraph: SGraph, _index: SModelIndex): LayoutOptions { return { "org.eclipse.elk.direction": "DOWN", "org.eclipse.elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX", }; } - protected nodeOptions(snode: SNode, index: SModelIndex): LayoutOptions | undefined { + protected nodeOptions(_snode: SNode, _index: SModelIndex): LayoutOptions | undefined { return { "org.eclipse.elk.nodeLabels.placement": "INSIDE V_CENTER H_CENTER", }; diff --git a/extension/src-webview/css/fta-diagram.css b/extension/src-webview/css/fta-diagram.css index 68a9d134..edb0f761 100644 --- a/extension/src-webview/css/fta-diagram.css +++ b/extension/src-webview/css/fta-diagram.css @@ -38,8 +38,8 @@ } .fta-text{ - fill: var(--fta-kn-dark); - stroke-width: 0.5; + fill: dimgrey; + stroke-width: 0; font-size: 10px; } diff --git a/extension/src-webview/options/render-options-registry.ts b/extension/src-webview/options/render-options-registry.ts index 95ad0d19..9e74fc23 100644 --- a/extension/src-webview/options/render-options-registry.ts +++ b/extension/src-webview/options/render-options-registry.ts @@ -89,7 +89,6 @@ export class RenderOptionsRegistry extends Registry { handle(action: Action): void | Action | ICommand { if (SetRenderOptionAction.isThisAction(action)) { const option = this._renderOptions.get(action.id); - if (!option) {return;} option.currentValue = action.value; const sendAction = { kind: SendConfigAction.KIND, options: [{ id: action.id, value: action.value }] }; diff --git a/extension/src-webview/views-rendering.tsx b/extension/src-webview/views-rendering.tsx index 671d6ca1..48fea548 100644 --- a/extension/src-webview/views-rendering.tsx +++ b/extension/src-webview/views-rendering.tsx @@ -30,10 +30,6 @@ export function renderOval(node: SNode): VNode { cy={Math.max(node.size.height, 0) / 2.0} rx={Math.max(nodeWidth, 0) / 2.0} ry={Math.max(node.size.height, 0) / 2.0} />; - /* return ; */ } /** @@ -73,9 +69,9 @@ export function renderTriangle(node: SNode): VNode { const rightX = Math.max(node.size.width, 0); const botY = Math.max(node.size.height, 0); const topY = 0; - const d = 'M' + leftX + " " + botY + " L " + midX + " " + topY + " L " + rightX + " " + botY + 'Z'; + const path = 'M' + leftX + " " + botY + " L " + midX + " " + topY + " L " + rightX + " " + botY + 'Z'; return ; } @@ -90,9 +86,9 @@ export function renderMirroredTriangle(node: SNode): VNode { const rightX = Math.max(node.size.width, 0); const botY = Math.max(node.size.height, 0); const topY = 0; - const d = 'M' + leftX + " " + topY + " L " + midX + " " + botY + " L " + rightX + " " + topY + 'Z'; + const path = 'M' + leftX + " " + topY + " L " + midX + " " + botY + " L " + rightX + " " + topY + 'Z'; return ; } @@ -108,10 +104,10 @@ export function renderTrapez(node: SNode): VNode { const rightX = Math.max(node.size.width, 0); const botY = Math.max(node.size.height, 0); const topY = 0; - const d = 'M' + leftX + " " + botY + " L " + midX1 + " " + topY + " L " + midX2 + " " + topY + const path = 'M' + leftX + " " + botY + " L " + midX1 + " " + topY + " L " + midX2 + " " + topY + " L " + rightX + " " + botY + 'Z'; return ; } @@ -127,10 +123,10 @@ export function renderDiamond(node: SNode): VNode { const topY = 0; const midY = Math.max(node.size.height, 0) / 2.0; const botY = Math.max(node.size.height, 0); - const d = 'M' + leftX + " " + midY + " L " + midX + " " + topY + " L " + rightX + " " + midY + const path = 'M' + leftX + " " + midY + " L " + midX + " " + topY + " L " + rightX + " " + midY + " L " + midX + " " + botY + 'Z'; return ; } @@ -148,10 +144,10 @@ export function renderPentagon(node: SNode): VNode { const topY = 0; const midY = Math.max(node.size.height, 0) / 3.0; const botY = Math.max(node.size.height, 0); - const d = 'M' + startX + " " + botY + " L " + leftX + " " + midY + " L " + midX + " " + topY + const path = 'M' + startX + " " + botY + " L " + leftX + " " + midY + " L " + midX + " " + topY + " L " + rightX + " " + midY + " L " + endX + " " + botY + 'Z'; return ; } @@ -168,10 +164,10 @@ export function renderHexagon(node: SNode): VNode { const topY = 0; const midY = Math.max(node.size.height, 0) / 2.0; const botY = Math.max(node.size.height, 0); - const d = 'M' + leftX + " " + midY + " L " + midX1 + " " + botY + " L " + midX2 + " " + botY + const path = 'M' + leftX + " " + midY + " L " + midX1 + " " + botY + " L " + midX2 + " " + botY + " L " + rightX + " " + midY + " L " + midX2 + " " + topY + " L " + midX1 + " " + topY + 'Z'; return ; } @@ -188,12 +184,10 @@ export function renderAndGate(node: SNode): VNode { const midY = Math.max(node.size.height, 0) / 2.0; const topY = 0; - const d = `M ${leftX}, ${midY} V ${botY} H ${rightX} V ${midY} C ${rightX}, ${midY} ${rightX}, ${topY} ${midX}, ${topY} ${leftX}, ${topY} ${leftX}, ${midY} ${leftX}, ${midY} Z`; - // 'M' + leftX + " " + midY + " V " + botY + " H " + rightX + " V " + midY + " C " + rightX + " " + midY + " " + rightX + " " - // + topY + " " + midX + " " + topY + " " + leftX + " " + topY + " " + leftX + " " + midY + " " + leftX + " " + midY + 'Z'; + const path = `M ${leftX}, ${midY} V ${botY} H ${rightX} V ${midY} C ${rightX}, ${midY} ${rightX}, ${topY} ${midX}, ${topY} ${leftX}, ${topY} ${leftX}, ${midY} ${leftX}, ${midY} Z`; return ; } @@ -210,11 +204,11 @@ export function renderOrGate(node: SNode): VNode { const nearBotY = botY - 5; const midY = Math.max(node.size.height, 0) / 2; const topY = 0; - const d = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}` + const path = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}` + `V ${midY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${midX},${topY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${leftX},${midY} Z`; return ; } @@ -231,13 +225,13 @@ export function renderKnGate(node: SNode, k: number, n: number): VNode { const nearBotY = Math.max(node.size.height, 0) - (Math.max(node.size.height, 0) / 10.0); const midY = Math.max(node.size.height, 0) / 2; const topY = 0; - const d = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}` + const path = `M${leftX},${midY} V ${botY}` + `C ${leftX}, ${botY} ${leftX+10}, ${nearBotY} ${midX}, ${nearBotY} ${rightX-10}, ${nearBotY} ${rightX}, ${botY} ${rightX}, ${botY}` + `V ${midY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${midX},${topY} A ${node.size.width},${node.size.height-10},${0},${0},${0},${leftX},${midY} Z`; return ( - - + + {`${k}/${n}`} @@ -258,10 +252,9 @@ export function renderInhibitGate(node: SNode): VNode { const highY = Math.max(node.size.height, 0) / 4.0; const highestY = 0; - const d = 'M' + leftX + " " + lowY + " L " + leftX + " " + highY + " L " + midX + " " + highestY + " L " + rightX - + " " + highY + " L " + rightX + " " + lowY + " L " + midX + " " + lowestY + "Z"; + const path = `M${leftX},${lowY} L ${leftX} ${highY} L ${midX} ${highestY} L ${rightX} ${highY} L ${rightX} ${lowY} L ${midX} ${lowestY} Z`; return ; } \ No newline at end of file diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 3c80375c..484ca26e 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -31,6 +31,13 @@ import { createOutputChannel, createQuickPickForWorkspaceOptions } from './utils let languageClient: LanguageClient; +/** + * All file endings of the languages that are supported by pasta. + * The file ending should also be the language id, since it is also used to + * register document selectors in the language client. + */ +const supportedFileEndings = ['stpa', 'fta']; + export function activate(context: vscode.ExtensionContext): void { vscode.window.showInformationMessage('Activating STPA extension'); @@ -40,6 +47,8 @@ export function activate(context: vscode.ExtensionContext): void { } languageClient = createLanguageClient(context); + // Create context key of supported languages + vscode.commands.executeCommand('setContext', 'pasta.languages', supportedFileEndings); if (diagramMode === 'panel') { // Set up webview panel manager for freestyle webviews @@ -53,6 +62,7 @@ export function activate(context: vscode.ExtensionContext): void { registerDefaultCommands(webviewPanelManager, context, { extensionPrefix: 'pasta' }); registerTextEditorSync(webviewPanelManager, context); registerSTPACommands(webviewPanelManager, context, { extensionPrefix: 'pasta' }); + registerFTACommands(webviewPanelManager, context, { extensionPrefix: 'pasta' }); } if (diagramMode === 'editor') { @@ -186,7 +196,9 @@ function registerSTPACommands(manager: StpaLspVscodeExtension, context: vscode.E return formulas; }) ); +} +function registerFTACommands(manager: StpaLspVscodeExtension, context: vscode.ExtensionContext, options: { extensionPrefix: string; }): void { // commands for computing and displaying the (minimal) cut sets of the fault tree. context.subscriptions.push( vscode.commands.registerCommand(options.extensionPrefix + ".fta.cutSets", async (uri: vscode.Uri) => { @@ -228,8 +240,10 @@ function createLanguageClient(context: vscode.ExtensionContext): LanguageClient // Options to control the language client const clientOptions: LanguageClientOptions = { - documentSelector: [{ scheme: 'file', language: 'stpa' }, - { scheme: 'file', language: 'fta' }], + documentSelector: supportedFileEndings.map((ending) => ({ + scheme: 'file', + language: ending, + })), synchronize: { // Notify the server about file changes to files contained in the workspace fileEvents: fileSystemWatcher diff --git a/yarn.lock b/yarn.lock index 5f0fa116..0c932d95 100644 --- a/yarn.lock +++ b/yarn.lock @@ -238,10 +238,10 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@kieler/table-webview@^0.0.3": - version "0.0.3" - resolved "https://registry.yarnpkg.com/@kieler/table-webview/-/table-webview-0.0.3.tgz#33199d9b0d8cd88d0aad6d4230617b94942482aa" - integrity sha512-XiDfn/MwHzVEpXLWC5DT6Ysg/5Zke3GlbtjBDDPRD1mLFXIekOCxkGYAKu068djqSAg3hsoiIhwLwWBfm48VNQ== +"@kieler/table-webview@^0.0.4": + version "0.0.4" + resolved "https://registry.yarnpkg.com/@kieler/table-webview/-/table-webview-0.0.4.tgz#c68a0652423a3c5f74a635fc5432e1430f758ee3" + integrity sha512-ZUAdX8dUCq72UdpFJz61bPX8eoJqnRuiJBOIFgOb+NqUke13zo4QmkeapmgA4zSKFBx5GC6nhSDQvVr9CMD4AQ== dependencies: "@types/vscode" "^1.56.0" reflect-metadata "^0.1.13"