Skip to content

Commit

Permalink
update diagram without resetting viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Jun 21, 2024
1 parent 0cabd9d commit a8e2bcf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
8 changes: 5 additions & 3 deletions extension/src-language-server/diagram-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 25 additions & 1 deletion extension/src-language-server/stpa/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,28 @@ export namespace SvgAction {
responseId: requestId
};
}
}
}

/** 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;
}
}
24 changes: 24 additions & 0 deletions extension/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 13 additions & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit a8e2bcf

Please sign in to comment.