Skip to content

Commit ad8268e

Browse files
fix : align entity operations with data model scope and type constants
1 parent d78cec0 commit ad8268e

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

packages/server/src/glsp-server/system-diagram/handler/apply-edit-operation-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class SystemDiagramApplyLabelEditOperationHandler extends JsonOperationHa
1818
createCommand(operation: ApplyLabelEditOperation): Command {
1919
const entityNode = getOrThrow(this.modelState.index.findLogicalEntityNode(operation.labelId), 'Entity node not found');
2020
const entity = getOrThrow(entityNode.entity.ref, 'Entity not found');
21+
const document = findDocument<CrossModelRoot>(entity)!;
2122
const oldName = entity.name;
2223
return new CrossModelCommand(
2324
this.modelState,
@@ -26,7 +27,7 @@ export class SystemDiagramApplyLabelEditOperationHandler extends JsonOperationHa
2627
this.renameEntity(
2728
getOrThrow(this.modelState.index.findLogicalEntityNode(operation.labelId), 'Entity node not found'),
2829
getOrThrow(entityNode.entity.ref, 'Entity not found'),
29-
oldName ?? this.modelState.idProvider.findNextGlobalId(LogicalEntity, 'NewEntity')
30+
oldName ?? this.modelState.idProvider.findNextLocalId(LogicalEntity, 'NewEntity', document.uri)
3031
),
3132
() =>
3233
this.renameEntity(

packages/server/src/glsp-server/system-diagram/handler/create-entity-operation-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class SystemDiagramCreateEntityOperationHandler extends JsonCreateNodeOpe
7070
const entityRoot: CrossModelRoot = { $type: 'CrossModelRoot' };
7171
const name = operation.args?.name?.toString() ?? 'NewEntity';
7272

73-
const id = this.modelState.idProvider.findNextLocalId('LogicalEntity', name, dataModel.uri);
73+
const id = this.modelState.idProvider.findNextLocalId(LogicalEntity, name, dataModel.uri);
7474

7575
const entity: LogicalEntity = {
7676
$type: 'LogicalEntity',

packages/server/src/language-server/cross-model-index-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class CrossModelIndexManager extends DefaultIndexManager {
2222
});
2323
}
2424

25-
allElementsInDataModelOfType(type: string, dataModelId: string): ReturnType<typeof this.allElements> {
25+
allElementsInDataModelOfType(dataModelId: string, type: string): ReturnType<typeof this.allElements> {
2626
return this.allElementsInDataModel(dataModelId).filter(desc => desc.type === type);
2727
}
2828

packages/server/src/language-server/cross-model-naming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class DefaultIdProvider implements IdProvider {
162162
const dataModelId = this.dataModelManager.getDataModelIdByUri(uri);
163163

164164
const knownIds = this.services.shared.workspace.IndexManager
165-
.allElementsInDataModelOfType(type, dataModelId)
165+
.allElementsInDataModelOfType(dataModelId, type)
166166
.map(element => element.name)
167167
.toArray();
168168

packages/server/src/language-server/cross-model-scope.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
isSourceObject,
2020
isTargetObject
2121
} from './generated/ast.js';
22-
import { setAttributes, setImplicitId, setOwner } from './util/ast-util.js';
22+
import { fixDocument, setAttributes, setImplicitId, setOwner } from './util/ast-util.js';
2323

2424
/**
2525
* Custom node description that wraps a given description under a potentially new name and also stores the datamodel id for faster access.
@@ -148,22 +148,16 @@ export class CrossModelScopeComputation extends DefaultScopeComputation {
148148
.map(attribute => this.descriptions.createDescription(attribute, combineIds(nodeId, attribute.id!), document));
149149
}
150150

151-
protected getLogicalEntity(node: AstNode & { entity?: Reference<LogicalEntity> }, document: LangiumDocument): LogicalEntity | undefined {
152-
const reference = node.entity;
153-
if (!reference) {
151+
protected getLogicalEntity(
152+
node: AstNode & { entity?: Reference<LogicalEntity> },
153+
document: LangiumDocument
154+
): LogicalEntity | undefined {
155+
try {
156+
return fixDocument(node, document).entity?.ref;
157+
} catch (error) {
158+
console.error(error);
154159
return undefined;
155160
}
156-
if (reference.ref) {
157-
return reference.ref;
158-
}
159-
160-
const scope = this.services.references.ScopeProvider.getScope({
161-
container: node,
162-
property: 'entity',
163-
reference: reference
164-
});
165-
const description = scope.getElement(reference.$refText);
166-
return this.services.shared.workspace.IndexManager.resolveElement(description) as LogicalEntity;
167161
}
168162

169163
protected processSourceObject(node: SourceObject, nodeId: string, document: LangiumDocument): AstNodeDescription[] {

0 commit comments

Comments
 (0)