From a8e2bcf9dc003de52fe815f9b04c5f5d678a75f9 Mon Sep 17 00:00:00 2001 From: Jette Petzold Date: Fri, 21 Jun 2024 15:57:47 +0200 Subject: [PATCH] update diagram without resetting viewport --- .../src-language-server/diagram-server.ts | 8 +++--- extension/src-language-server/stpa/actions.ts | 26 ++++++++++++++++++- extension/src/actions.ts | 24 +++++++++++++++++ extension/src/extension.ts | 15 +++++++++-- 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/extension/src-language-server/diagram-server.ts b/extension/src-language-server/diagram-server.ts index 5a739bfe..23d2a46d 100644 --- a/extension/src-language-server/diagram-server.ts +++ b/extension/src-language-server/diagram-server.ts @@ -17,12 +17,13 @@ import { Action, DiagramServices, JsonMap, RequestAction, RequestModelAction, ResponseAction } from "sprotty-protocol"; import { Connection } from "vscode-languageserver"; +import { FtaServices } from "./fta/fta-module"; import { SetSynthesisOptionsAction, UpdateOptionsAction } from "./options/actions"; import { DropDownOption } from "./options/option-models"; import { SnippetDiagramServer } from "./snippets/snippet-diagram-server"; import { LanguageSnippet } from "./snippets/snippet-model"; import { StpaDiagramSnippets } from "./snippets/stpa-snippets"; -import { GenerateSVGsAction, RequestSvgAction, SvgAction } from "./stpa/actions"; +import { GenerateSVGsAction, RequestSvgAction, SvgAction, UpdateDiagramAction } from "./stpa/actions"; import { StpaSynthesisOptions, filteringUCAsID } from "./stpa/diagram/stpa-synthesis-options"; import { COMPLETE_GRAPH_PATH, @@ -48,9 +49,8 @@ import { setScenarioWithNoUCAGraphOptions, setSystemConstraintGraphOptions, } from "./stpa/result-report/svg-generator"; -import { SynthesisOptions } from "./synthesis-options"; import { StpaServices } from "./stpa/stpa-module"; -import { FtaServices } from "./fta/fta-module"; +import { SynthesisOptions } from "./synthesis-options"; export class PastaDiagramServer extends SnippetDiagramServer { protected synthesisOptions: SynthesisOptions | undefined; @@ -100,6 +100,8 @@ export class PastaDiagramServer extends SnippetDiagramServer { return this.handleSetSynthesisOption(action as SetSynthesisOptionsAction); case GenerateSVGsAction.KIND: return this.handleGenerateSVGDiagrams(action as GenerateSVGsAction); + case UpdateDiagramAction.KIND: + return this.updateView(this.state.options); } return super.handleAction(action); } diff --git a/extension/src-language-server/stpa/actions.ts b/extension/src-language-server/stpa/actions.ts index ffb03775..831ba1eb 100644 --- a/extension/src-language-server/stpa/actions.ts +++ b/extension/src-language-server/stpa/actions.ts @@ -78,4 +78,28 @@ export namespace SvgAction { responseId: requestId }; } -} \ No newline at end of file +} + +/** Send to server to update the diagram. */ +export interface UpdateDiagramAction extends Action { + kind: typeof UpdateDiagramAction.KIND + options?: JsonMap; +} + +export namespace UpdateDiagramAction { + export const KIND = "updateDiagram"; + + + export function create( + options?: JsonMap + ): UpdateDiagramAction { + return { + kind: KIND, + options + }; + } + + export function isThisAction(action: Action): action is UpdateDiagramAction { + return action.kind === UpdateDiagramAction.KIND; + } +} diff --git a/extension/src/actions.ts b/extension/src/actions.ts index e59d875f..58bb6945 100644 --- a/extension/src/actions.ts +++ b/extension/src/actions.ts @@ -134,3 +134,27 @@ export namespace SendDefaultSnippetsAction { return action.kind === SendDefaultSnippetsAction.KIND; } } + +/** Send to server to update the diagram. */ +export interface UpdateDiagramAction extends Action { + kind: typeof UpdateDiagramAction.KIND + options?: JsonMap; +} + +export namespace UpdateDiagramAction { + export const KIND = "updateDiagram"; + + + export function create( + options?: JsonMap + ): UpdateDiagramAction { + return { + kind: KIND, + options + }; + } + + export function isThisAction(action: Action): action is UpdateDiagramAction { + return action.kind === UpdateDiagramAction.KIND; + } +} diff --git a/extension/src/extension.ts b/extension/src/extension.ts index bbcf352a..200cf017 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -16,8 +16,9 @@ */ import * as path from "path"; +import { ActionMessage } from "sprotty-protocol"; import { createFileUri, registerDefaultCommands } from "sprotty-vscode"; -import { LspSprottyEditorProvider, LspSprottyViewProvider } from "sprotty-vscode/lib/lsp"; +import { LspSprottyEditorProvider, LspSprottyViewProvider, acceptMessageType } from "sprotty-vscode/lib/lsp"; import * as vscode from "vscode"; import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from "vscode-languageclient/node"; import { Messenger } from "vscode-messenger"; @@ -29,6 +30,7 @@ import { StpaResult } from "./report/utils"; import { createSBMs } from "./sbm/sbm-generation"; import { LTLFormula } from "./sbm/utils"; import { createFile, createOutputChannel, createQuickPickForWorkspaceOptions } from "./utils"; +import { UpdateDiagramAction } from './actions'; let languageClient: LanguageClient; @@ -325,7 +327,16 @@ function registerTextEditorSync(manager: StpaLspVscodeExtension, context: vscode if (currentCursorPosition) { await languageClient.sendNotification("editor/save", document.offsetAt(currentCursorPosition)); } - manager.openDiagram(document.uri, { preserveFocus: true }); + + // update diagram without reseting viewport + const mes: ActionMessage = { + clientId: manager.clientId!, + action: { + kind: UpdateDiagramAction.KIND, + } as UpdateDiagramAction, + }; + languageClient.sendNotification(acceptMessageType, mes); + if (manager.contextTable) { languageClient.sendNotification("contextTable/getData", document.uri.toString()); }