Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: establish language server service for the graphical editor #1315

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion packages/safe-ds-lang/src/language/communication/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { MessageDirection, NotificationType0, RequestType0 } from 'vscode-languageserver';
import { NotificationType } from 'vscode-languageserver-protocol';
import { NotificationType, RequestType } from 'vscode-languageserver-protocol';
import { UUID } from 'node:crypto';
import { Buildin, Collection } from '../graphical-editor/global.js';
import { Uri } from 'vscode';

export namespace InstallRunnerNotification {
export const method = 'runner/install' as const;
Expand Down Expand Up @@ -91,3 +93,39 @@ export namespace IsRunnerReadyRequest {
export const messageDirection = MessageDirection.clientToServer;
export const type = new RequestType0(method);
}

export namespace GraphicalEditorSyncEventNotification {
export const method = 'graphical-editor/sync-event' as const;
export const messageDirection = MessageDirection.serverToClient;
export const type = new NotificationType<Collection>(method);
}

export namespace GraphicalEditorOpenSyncChannelRequest {
export const method = 'graphical-editor/openSyncChannel' as const;
export const messageDirection = MessageDirection.clientToServer;
export const type = new RequestType<Uri, void, void>(method);
}

export namespace GraphicalEditorCloseSyncChannelRequest {
export const method = 'graphical-editor/closeSyncChannel' as const;
export const messageDirection = MessageDirection.clientToServer;
export const type = new RequestType<Uri, void, void>(method);
}

export namespace GraphicalEditorGetDocumentationRequest {
export const method = 'graphical-editor/getDocumentation' as const;
export const messageDirection = MessageDirection.clientToServer;
export const type = new RequestType<{ uri: Uri; uniquePath: string }, string | undefined, void>(method);
}

export namespace GraphicalEditorGetBuildinsRequest {
export const method = 'graphical-editor/getBuildins' as const;
export const messageDirection = MessageDirection.clientToServer;
export const type = new RequestType<void, Buildin[], void>(method);
}

export namespace GraphicalEditorParseDocumentRequest {
export const method = 'graphical-editor/parseDocument' as const;
export const messageDirection = MessageDirection.clientToServer;
export const type = new RequestType<Uri, Collection, void>(method);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { isSdsLiteral, SdsArgument } from '../../generated/ast.js';
import { Call } from './call.js';
import { Placeholder } from './placeholder.js';
import { Expression, GenericExpression } from './expression.js';
import { Parameter } from './parameter.js';
import { Parser } from './parser.js';
import { CustomError } from '../types.js';

export class Argument {
constructor(
public readonly text: string,
public readonly reference: GenericExpression | Call | Placeholder | Parameter | undefined,
public readonly parameterName?: string,
) {}

Check warning on line 14 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts#L11-L14

Added lines #L11 - L14 were not covered by tests

public static parse(node: SdsArgument, parser: Parser) {
if (!node.value.$cstNode) return parser.pushError('CstNode missing', node.value);
const text = node.value.$cstNode.text;

Check warning on line 18 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts#L17-L18

Added lines #L17 - L18 were not covered by tests

let expression;
if (!isSdsLiteral(node.value)) expression = Expression.parse(node.value, parser);
if (expression instanceof CustomError) return expression;

Check warning on line 22 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts#L20-L22

Added lines #L20 - L22 were not covered by tests

if (node.parameter && !node.parameter.ref) return parser.pushError('Missing Parameterreference', node);
const parameterName = node.parameter?.ref?.name;

Check warning on line 25 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts#L24-L25

Added lines #L24 - L25 were not covered by tests

return new Argument(text, expression, parameterName);
}

Check warning on line 28 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/argument.ts#L27-L28

Added lines #L27 - L28 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import {
SdsCall,
SdsClass,
SdsExpression,
SdsFunction,
SdsMemberAccess,
SdsPlaceholder,
SdsReference,
SdsSegment,
isSdsCall,
isSdsClass,
isSdsFunction,
isSdsMemberAccess,
isSdsPlaceholder,
isSdsReference,
isSdsSegment,
} from '../../generated/ast.js';
import { Argument } from './argument.js';
import { Edge, Port } from './edge.js';
import { GenericExpression } from './expression.js';
import { Parameter } from './parameter.js';
import { Placeholder } from './placeholder.js';
import { Result } from './result.js';
import { filterErrors } from './utils.js';
import { Parser } from './parser.js';
import { CustomError } from '../types.js';

export class Call {
private constructor(
public readonly id: number,
public readonly name: string,
public readonly self: string | undefined,
public readonly parameterList: Parameter[],
public readonly resultList: Result[],
public readonly category: string,
public readonly uniquePath: string,
) {}

Check warning on line 37 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L30-L37

Added lines #L30 - L37 were not covered by tests

public static parse(node: SdsCall, parser: Parser): Call | CustomError {
const id = parser.getNewId();

Check warning on line 40 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L40

Added line #L40 was not covered by tests

if (!isValidCallReceiver(node.receiver)) {
return parser.pushError(`Invalid Call receiver: ${debugInvalidCallReceiver(node.receiver)}`, node.receiver);
}

Check warning on line 44 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L42-L44

Added lines #L42 - L44 were not covered by tests

let name = '';
let self: string | undefined = undefined;
let category = '';
let argumentList: Argument[] = [];
let parameterList: Parameter[] = [];
let resultList: Result[] = [];

Check warning on line 51 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L46-L51

Added lines #L46 - L51 were not covered by tests

argumentList = filterErrors(node.argumentList.arguments.map((argument) => Argument.parse(argument, parser)));

Check warning on line 53 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L53

Added line #L53 was not covered by tests

if (isSdsMemberAccess(node.receiver)) {
const tmp = Call.parseSelf(node.receiver, id, parser);
if (tmp instanceof CustomError) return tmp;
self = tmp;

Check warning on line 58 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L55-L58

Added lines #L55 - L58 were not covered by tests

const functionDeclaration = node.receiver.member.target.ref;
name = functionDeclaration.name;
category = parser.getCategory(functionDeclaration)?.name ?? '';

Check warning on line 62 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L60-L62

Added lines #L60 - L62 were not covered by tests

resultList = filterErrors(
(functionDeclaration.resultList?.results ?? []).map((result) => Result.parse(result, parser)),
);
parameterList = filterErrors(
(functionDeclaration.parameterList?.parameters ?? []).map((parameter) =>
Parameter.parse(parameter, parser),
),
);
}

Check warning on line 72 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L64-L72

Added lines #L64 - L72 were not covered by tests

if (isSdsReference(node.receiver) && isSdsClass(node.receiver.target.ref)) {
const classDeclaration = node.receiver.target.ref;

Check warning on line 75 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L74-L75

Added lines #L74 - L75 were not covered by tests

name = 'new';
self = classDeclaration.name;
category = 'Modeling';

Check warning on line 79 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L77-L79

Added lines #L77 - L79 were not covered by tests

if (!classDeclaration.parameterList)
return parser.pushError('Missing constructor parameters', classDeclaration);
parameterList = filterErrors(
classDeclaration.parameterList.parameters.map((parameter) => Parameter.parse(parameter, parser)),
);
resultList = [new Result('new', classDeclaration.name)];
}

Check warning on line 87 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L81-L87

Added lines #L81 - L87 were not covered by tests

if (isSdsReference(node.receiver) && isSdsSegment(node.receiver.target.ref)) {
const segmentDeclaration = node.receiver.target.ref;

Check warning on line 90 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L89-L90

Added lines #L89 - L90 were not covered by tests

self = '';
name = segmentDeclaration.name;
category = 'Segment';

Check warning on line 94 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L92-L94

Added lines #L92 - L94 were not covered by tests

resultList = filterErrors(
(segmentDeclaration.resultList?.results ?? []).map((result) => Result.parse(result, parser)),
);
parameterList = filterErrors(
(segmentDeclaration.parameterList?.parameters ?? []).map((parameter) =>
Parameter.parse(parameter, parser),
),
);
}

Check warning on line 104 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L96-L104

Added lines #L96 - L104 were not covered by tests

const parameterListCompleted = matchArgumentsToParameter(parameterList, argumentList, node, id, parser);
if (parameterListCompleted instanceof CustomError) return parameterListCompleted;

Check warning on line 107 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L106-L107

Added lines #L106 - L107 were not covered by tests

const call = new Call(id, name, self, parameterListCompleted, resultList, category, parser.getUniquePath(node));
parser.graph.callList.push(call);
return call;
}

Check warning on line 112 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L109-L112

Added lines #L109 - L112 were not covered by tests

private static parseSelf(node: CallReceiver, id: number, parser: Parser) {
if (isSdsMemberAccess(node)) {
if (isSdsCall(node.receiver)) {
const call = Call.parse(node.receiver, parser);
if (call instanceof CustomError) return call;

Check warning on line 118 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L115-L118

Added lines #L115 - L118 were not covered by tests

if (call.resultList.length > 1) return parser.pushError('To many result', node.receiver);
if (call.resultList.length < 1) return parser.pushError('Missing result', node.receiver);

Check warning on line 121 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L120-L121

Added lines #L120 - L121 were not covered by tests

Edge.create(Port.fromResult(call.resultList[0]!, call.id), Port.fromName(id, 'self'), parser);
} else if (isSdsReference(node.receiver)) {
const receiver = node.receiver.target.ref;

Check warning on line 125 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L123-L125

Added lines #L123 - L125 were not covered by tests

if (isSdsClass(receiver)) {
return receiver.name;
} else if (isSdsPlaceholder(receiver)) {
const placeholder = Placeholder.parse(receiver, parser);
Edge.create(Port.fromPlaceholder(placeholder, false), Port.fromName(id, 'self'), parser);
}
}
}
return '';
}

Check warning on line 136 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L127-L136

Added lines #L127 - L136 were not covered by tests
}

const matchArgumentsToParameter = (
parameterList: Parameter[],
argumentList: Argument[],
callNode: SdsCall,
id: number,
parser: Parser,
): Parameter[] | CustomError => {
for (const [i, parameter] of parameterList.entries()) {
const argumentIndexMatched = argumentList[i];
if (argumentIndexMatched instanceof CustomError) return argumentIndexMatched;

Check warning on line 148 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L140-L148

Added lines #L140 - L148 were not covered by tests

const argumentNameMatched = argumentList.find(
(argument) => !(argument instanceof CustomError) && argument.parameterName === parameter.name,
) as Argument | undefined;

Check warning on line 152 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L150-L152

Added lines #L150 - L152 were not covered by tests

if (argumentIndexMatched && argumentNameMatched && argumentIndexMatched !== argumentNameMatched)
return parser.pushError(`To many matches for ${parameter.name}`, callNode.argumentList);
const argument = argumentIndexMatched ?? argumentNameMatched;

Check warning on line 156 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L154-L156

Added lines #L154 - L156 were not covered by tests

if (argument) {
parameter.argumentText = argument.text;
if (argument.reference instanceof Call) {
const call = argument.reference;
if (call.resultList.length !== 1) return parser.pushError('Type missmatch', callNode.argumentList);
Edge.create(Port.fromResult(call.resultList[0]!, call.id), Port.fromParameter(parameter, id), parser);
}
if (argument.reference instanceof GenericExpression) {
const experession = argument.reference;
Edge.create(Port.fromGenericExpression(experession, false), Port.fromParameter(parameter, id), parser);
}
if (argument.reference instanceof Placeholder) {
const placeholder = argument.reference;
Edge.create(Port.fromPlaceholder(placeholder, false), Port.fromParameter(parameter, id), parser);
}
if (argument.reference instanceof Parameter) {
const segmentParameter = argument.reference;
Edge.create(Port.fromParameter(segmentParameter, -1), Port.fromParameter(parameter, id), parser);
}
continue;
}

Check warning on line 178 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L158-L178

Added lines #L158 - L178 were not covered by tests

if (!argument && parameter.defaultValue) {
continue;
}

Check warning on line 182 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L180-L182

Added lines #L180 - L182 were not covered by tests

if (!argument && !parameter.defaultValue) {
return parser.pushError(`Missing Argument for ${parameter.name}`, callNode);
}
}
return parameterList;
};

Check warning on line 189 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L184-L189

Added lines #L184 - L189 were not covered by tests

type CallReceiver =
| (SdsReference & { target: { ref: SdsClass | SdsSegment } })
| (SdsMemberAccess & {
member: {
target: { ref: SdsFunction };
};
receiver: SdsCall | { target: { ref: SdsPlaceholder | SdsClass } };
});

const isValidCallReceiver = (receiver: SdsExpression): receiver is CallReceiver => {
/* eslint-disable no-implicit-coercion */
return (
(isSdsMemberAccess(receiver) &&
!!receiver.member &&
!!receiver.member.target.ref &&
isSdsFunction(receiver.member.target.ref) &&
((isSdsReference(receiver.receiver) &&
(isSdsClass(receiver.receiver.target.ref) || isSdsPlaceholder(receiver.receiver.target.ref))) ||
isSdsCall(receiver.receiver))) ||
(isSdsReference(receiver) && (isSdsClass(receiver.target.ref) || isSdsSegment(receiver.target.ref)))

Check warning on line 210 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L202-L210

Added lines #L202 - L210 were not covered by tests
);
};

Check warning on line 212 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L212

Added line #L212 was not covered by tests

const debugInvalidCallReceiver = (receiver: SdsExpression): string => {
/* eslint-disable no-implicit-coercion */
if (isSdsMemberAccess(receiver)) {
if (!receiver.member) return 'MemberAccess: Missing member';
if (!receiver.member.target.ref) return 'MemberAccess: Missing member declaration';
if (!isSdsFunction(receiver.member.target.ref)) return 'MemberAccess: Member is not a function';
if (!isSdsCall(receiver.receiver) && !isSdsReference(receiver.receiver))
return `MemberAccess: Receiver is not a Reference or Call but - ${receiver.receiver.$type}`;
if (
isSdsReference(receiver.receiver) &&
!isSdsClass(receiver.receiver.target.ref) &&
isSdsReference(receiver.receiver) &&
!isSdsPlaceholder(receiver.receiver.target.ref)

Check warning on line 226 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L216-L226

Added lines #L216 - L226 were not covered by tests
)
return 'MemberAccess: Reference Receiver is not Class of Placeholder';
}
if (isSdsReference(receiver)) {
if (!isSdsClass(receiver.target.ref) && !isSdsSegment(receiver.target.ref))
return 'Reference: Not a class or segment';
}

Check warning on line 233 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L228-L233

Added lines #L228 - L233 were not covered by tests

return receiver.$type;
};

Check warning on line 236 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/call.ts#L235-L236

Added lines #L235 - L236 were not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { GenericExpression } from './expression.js';
import { Parameter } from './parameter.js';
import { Parser } from './parser.js';
import { Placeholder } from './placeholder.js';
import { Result } from './result.js';
import { SegmentGroupId } from './segment.js';

export class Edge {
public constructor(
public readonly from: Port,
public readonly to: Port,
) {}

Check warning on line 12 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L10-L12

Added lines #L10 - L12 were not covered by tests

public static create(from: Port, to: Port, parser: Parser) {
parser.graph.edgeList.push(new Edge(from, to));
}

Check warning on line 16 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L15-L16

Added lines #L15 - L16 were not covered by tests
}

export class Port {
private constructor(
public readonly nodeId: string,
public readonly portIdentifier: string,
) {}

Check warning on line 23 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L21-L23

Added lines #L21 - L23 were not covered by tests

public static fromName = (nodeId: number, name: string): Port => {
return new Port(nodeId.toString(), name);
};

Check warning on line 27 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L26-L27

Added lines #L26 - L27 were not covered by tests

public static fromPlaceholder = (placeholder: Placeholder, input: boolean): Port => {
return new Port(placeholder.name, input ? 'target' : 'source');
};

Check warning on line 31 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L30-L31

Added lines #L30 - L31 were not covered by tests

public static fromResult = (result: Result, nodeId: number): Port => {
return new Port(nodeId.toString(), result.name);
};

Check warning on line 35 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L34-L35

Added lines #L34 - L35 were not covered by tests

public static fromParameter = (parameter: Parameter, nodeId: number): Port => {
return new Port(nodeId.toString(), parameter.name);
};

Check warning on line 39 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L38-L39

Added lines #L38 - L39 were not covered by tests

public static fromGenericExpression(node: GenericExpression, input: boolean) {
return new Port(node.id.toString(), input ? 'target' : 'source');
}

Check warning on line 43 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L42-L43

Added lines #L42 - L43 were not covered by tests

public static fromAssignee = (node: Placeholder | Result, input: boolean): Port => {
if (node instanceof Placeholder) {
return new Port(node.name, input ? 'target' : 'source');
}
return new Port(SegmentGroupId.toString(), node.name);
};

Check warning on line 50 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L46-L50

Added lines #L46 - L50 were not covered by tests

public static isPortList(object: any): object is Port[] {
return Array.isArray(object) && object.every((element) => element instanceof Port);
}

Check warning on line 54 in packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts

View check run for this annotation

Codecov / codecov/patch

packages/safe-ds-lang/src/language/graphical-editor/ast-parser/edge.ts#L53-L54

Added lines #L53 - L54 were not covered by tests
}
Loading
Loading