Skip to content

Commit

Permalink
renaming + restructuring (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Apr 19, 2024
1 parent 97a6e66 commit b5a6af6
Show file tree
Hide file tree
Showing 24 changed files with 379 additions and 278 deletions.
24 changes: 14 additions & 10 deletions extension/src-language-server/diagram-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
import { Connection } from "vscode-languageserver";
import { SetSynthesisOptionsAction, UpdateOptionsAction } from "./options/actions";
import { DropDownOption } from "./options/option-models";
import { StpaDiagramSnippets } from './snippets/stpa-templates';
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 { StpaSynthesisOptions, filteringUCAsID } from "./stpa/diagram/stpa-synthesis-options";
import {
Expand Down Expand Up @@ -54,13 +56,10 @@ import {
setSystemConstraintGraphOptions,
} from "./stpa/result-report/svg-generator";
import { SynthesisOptions } from "./synthesis-options";
import { SnippetDiagramServer } from './snippets/snippet-diagram-server';
import { LanguageSnippet } from './snippets/snippet-model';

export class PastaDiagramServer extends SnippetDiagramServer {
protected synthesisOptions: SynthesisOptions | undefined;
protected stpaTemps: StpaDiagramSnippets | undefined;
// clientId: string;
protected stpaSnippets: StpaDiagramSnippets | undefined;
protected connection: Connection | undefined;

constructor(
Expand All @@ -70,10 +69,10 @@ export class PastaDiagramServer extends SnippetDiagramServer {
options: JsonMap | undefined,
connection: Connection | undefined,
synthesisOptions?: SynthesisOptions,
stpaTemps?: StpaDiagramSnippets
stpaSnippets?: StpaDiagramSnippets
) {
super(dispatch, services, clientId, stpaTemps?.getSnippets() ?? [], options, connection);
this.stpaTemps = stpaTemps;
super(dispatch, services, clientId, stpaSnippets?.getSnippets() ?? [], options, connection);
this.stpaSnippets = stpaSnippets;
this.synthesisOptions = synthesisOptions;
this.clientId = clientId;
this.connection = connection;
Expand All @@ -99,8 +98,13 @@ export class PastaDiagramServer extends SnippetDiagramServer {
return super.handleAction(action);
}

protected createTempFromString(text: string): LanguageSnippet {
return this.stpaTemps?.createTemp(text) ?? {} as LanguageSnippet;
/**
* Creates a snippet from a string.
* @param text The text that should be inserted when clicking on the snippet.
* @returns a snippet for the given {@code text}
*/
protected createSnippetFromString(text: string): LanguageSnippet {
return this.stpaSnippets?.createSnippet(text) ?? {} as LanguageSnippet;
}

/**
Expand Down
29 changes: 12 additions & 17 deletions extension/src-language-server/fta/fta-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,14 @@
import ElkConstructor from "elkjs/lib/elk.bundled";
import { Module, PartialLangiumServices } from "langium";
import { LangiumSprottyServices, SprottyDiagramServices } from "langium-sprotty";
import {
DefaultElementFilter,
ElkFactory,
IElementFilter,
ILayoutConfigurator
} from "sprotty-elk/lib/elk-layout";
import { DefaultElementFilter, ElkFactory, IElementFilter, ILayoutConfigurator } from "sprotty-elk/lib/elk-layout";
import { LayoutEngine } from "../layout-engine";
import { StpaDiagramSnippets } from "../snippets/stpa-snippets";
import { FtaDiagramGenerator } from "./diagram/fta-diagram-generator";
import { FtaLayoutConfigurator } from "./diagram/fta-layout-config";
import { FtaSynthesisOptions } from "./diagram/fta-synthesis-options";
import { FtaScopeProvider } from "./fta-scopeProvider";
import { FtaValidationRegistry, FtaValidator } from "./fta-validator";
import { StpaTemplates } from '../stpa-templates';

/**
* Declaration of custom services.
Expand All @@ -50,8 +45,8 @@ export type FtaAddedServices = {
options: {
SynthesisOptions: FtaSynthesisOptions;
};
templates: {
StpaTemplates: StpaTemplates;
snippets: {
StpaDiagramSnippets: StpaDiagramSnippets;
};
};

Expand All @@ -68,20 +63,20 @@ export type FtaServices = LangiumSprottyServices & FtaAddedServices;
*/
export const FtaModule: Module<FtaServices, PartialLangiumServices & SprottyDiagramServices & FtaAddedServices> = {
diagram: {
DiagramGenerator: (services) => new FtaDiagramGenerator(services),
ModelLayoutEngine: (services) =>
DiagramGenerator: services => new FtaDiagramGenerator(services),
ModelLayoutEngine: services =>
new LayoutEngine(
services.layout.ElkFactory,
services.layout.ElementFilter,
services.layout.LayoutConfigurator
) as any,
},
references: {
ScopeProvider: (services) => new FtaScopeProvider(services),
FtaScopeProvider: (services) => new FtaScopeProvider(services),
ScopeProvider: services => new FtaScopeProvider(services),
FtaScopeProvider: services => new FtaScopeProvider(services),
},
validation: {
ValidationRegistry: (services) => new FtaValidationRegistry(services),
ValidationRegistry: services => new FtaValidationRegistry(services),
FtaValidator: () => new FtaValidator(),
},
layout: {
Expand All @@ -92,7 +87,7 @@ export const FtaModule: Module<FtaServices, PartialLangiumServices & SprottyDiag
options: {
SynthesisOptions: () => new FtaSynthesisOptions(),
},
templates: {
StpaTemplates: services => new StpaTemplates(services)
}
snippets: {
StpaDiagramSnippets: services => new StpaDiagramSnippets(services),
},
};
2 changes: 1 addition & 1 deletion extension/src-language-server/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import { LangiumSprottySharedServices } from "langium-sprotty";
import { Connection, Range } from "vscode-languageserver";
import { getRangeOfNodeFTA } from "./fta/utils";
import { Model, isModel, isModelFTA } from "./generated/ast";
import { getRangeOfNodeSTPA } from "./stpa/utils";
import { getModel } from "./utils";
import { getRangeOfNodeFTA } from "./fta/utils";

/**
* Adds handler for notifications.
Expand Down
2 changes: 1 addition & 1 deletion extension/src-language-server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ addFTANotificationHandler(connection, fta, shared);
addNotificationHandler(connection, shared);

// handle configuration changes for the validation checks
connection.onNotification("configuration", (options) => {
connection.onNotification("configuration", options => {
for (const option of options) {
switch (option.id) {
case "checkResponsibilitiesForConstraints":
Expand Down
20 changes: 8 additions & 12 deletions extension/src-language-server/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
DefaultDiagramServerManager,
DiagramActionNotification,
LangiumSprottySharedServices,
SprottySharedServices
SprottySharedServices,
} from "langium-sprotty";
import { DiagramOptions } from "sprotty-protocol";
import { URI } from "vscode-uri";
Expand Down Expand Up @@ -49,11 +49,7 @@ export function createServices(context: DefaultSharedModuleContext): {
stpa: StpaServices;
fta: FtaServices;
} {
const shared = inject(
createDefaultSharedModule(context),
PastaGeneratedSharedModule,
PastaSprottySharedModule
);
const shared = inject(createDefaultSharedModule(context), PastaGeneratedSharedModule, PastaSprottySharedModule);
const stpa = inject(createDefaultModule({ shared }), StpaGeneratedModule, STPAModule);
const fta = inject(createDefaultModule({ shared }), FtaGeneratedModule, FtaModule);
shared.ServiceRegistry.register(stpa);
Expand All @@ -71,20 +67,20 @@ const pastaDiagramServerFactory = (
if (!sourceUri) {
throw new Error("Missing 'sourceUri' option in request.");
}
const language = serviceRegistry.getServices(URI.parse(sourceUri as string)) as (StpaServices | FtaServices);
const language = serviceRegistry.getServices(URI.parse(sourceUri as string)) as StpaServices | FtaServices;
if (!language.diagram) {
throw new Error(`The '${language.LanguageMetaData.languageId}' language does not support diagrams.`);
}
return new PastaDiagramServer(
async (action) => {
async action => {
connection?.sendNotification(DiagramActionNotification.type, { clientId, action });
},
language.diagram,
clientId,
options,
connection,
language.options.SynthesisOptions,
language.templates.StpaTemplates
language.options.SynthesisOptions,
language.snippets.StpaDiagramSnippets
);
};
};
Expand All @@ -95,6 +91,6 @@ const pastaDiagramServerFactory = (
const PastaSprottySharedModule: Module<LangiumSprottySharedServices, SprottySharedServices> = {
diagram: {
diagramServerFactory: pastaDiagramServerFactory,
DiagramServerManager: (services) => new DefaultDiagramServerManager(services),
DiagramServerManager: services => new DefaultDiagramServerManager(services),
},
};
};
4 changes: 2 additions & 2 deletions extension/src-language-server/options/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export namespace UpdateOptionsAction {

/** Change the value of one or multiple synthesis options. */
export interface SetSynthesisOptionsAction extends Action {
kind: typeof SetSynthesisOptionsAction.KIND;
options: SynthesisOption[];
kind: typeof SetSynthesisOptionsAction.KIND
options: SynthesisOption[]
}

export namespace SetSynthesisOptionsAction {
Expand Down
8 changes: 4 additions & 4 deletions extension/src-language-server/snippets/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { VNode } from "snabbdom";
import { Action, RequestAction, ResponseAction, generateRequestId } from "sprotty-protocol";
import { WebviewSnippet } from "./snippet-model";

/** Request message from the server to get the svgs of the snippets. */
/** Request message from the server to the client to get the svgs of the snippets. */
export interface RequestWebviewSnippetsAction extends RequestAction<SendWebviewSnippetsAction> {
kind: typeof RequestWebviewSnippetsAction.KIND;
snippets: WebviewSnippet[];
Expand Down Expand Up @@ -88,10 +88,10 @@ export namespace ExecuteSnippetAction {
}
}

/** Message containing snippets as string. */
/** Message from extension to langauge server containing snippets as string. (Used to add default snippets) */
export interface SendSnippetsAction extends Action {
kind: typeof SendSnippetsAction.KIND;
temps: string[];
snippets: string[];
}

export namespace SendSnippetsAction {
Expand All @@ -100,7 +100,7 @@ export namespace SendSnippetsAction {
export function create(temps: string[]): SendSnippetsAction {
return {
kind: KIND,
temps,
snippets: temps,
};
}

Expand Down
Loading

0 comments on commit b5a6af6

Please sign in to comment.