Skip to content

Commit 844da20

Browse files
committed
Support multi-target references
1 parent f53d8c7 commit 844da20

File tree

41 files changed

+734
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+734
-284
lines changed

examples/arithmetics/src/language-server/generated/grammar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
388388
"type": {
389389
"$ref": "#/types@0"
390390
},
391-
"deprecatedSyntax": false
391+
"deprecatedSyntax": false,
392+
"isMulti": false
392393
}
393394
},
394395
{

examples/domainmodel/src/language-server/domain-model-rename-refactoring.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ export class DomainModelRenameProvider extends DefaultRenameProvider {
3131
const offset = document.textDocument.offsetAt(params.position);
3232
const leafNode = CstUtils.findDeclarationNodeAtOffset(rootNode, offset, this.grammarConfig.nameRegexp);
3333
if (!leafNode) return undefined;
34-
const targetNode = this.references.findDeclaration(leafNode);
35-
if (!targetNode) return undefined;
36-
if (isNamed(targetNode)) targetNode.name = params.newName;
37-
const location = this.getNodeLocation(targetNode);
38-
if (location) {
39-
const change = TextEdit.replace(location.range, params.newName);
40-
const uri = location.uri;
41-
if (uri) {
42-
if (changes[uri]) {
43-
changes[uri].push(change);
44-
} else {
45-
changes[uri] = [change];
34+
const targetNodes = this.references.findDeclarations(leafNode);
35+
if (!targetNodes.length) return undefined;
36+
for (const node of targetNodes) {
37+
if (isNamed(node)) node.name = params.newName;
38+
const location = this.getNodeLocation(node);
39+
if (location) {
40+
const change = TextEdit.replace(location.range, params.newName);
41+
const uri = location.uri;
42+
if (uri) {
43+
if (changes[uri]) {
44+
changes[uri].push(change);
45+
} else {
46+
changes[uri] = [change];
47+
}
4648
}
4749
}
4850
}
49-
51+
const targetNode = targetNodes[0];
5052
for (const node of AstUtils.streamAst(targetNode)) {
5153
const qn = this.buildQualifiedName(node);
5254
if (qn) {

examples/domainmodel/src/language-server/domain-model.langium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DataType:
1818
'datatype' name=ID;
1919

2020
Entity:
21-
'entity' name=ID ('extends' superType=[Entity:QualifiedName])? '{'
21+
'entity' name=ID ('extends' superType=[*Entity:QualifiedName])? '{'
2222
(features+=Feature)*
2323
'}';
2424

examples/domainmodel/src/language-server/generated/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface Entity extends langium.AstNode {
7878
readonly $type: 'Entity';
7979
features: Array<Feature>;
8080
name: string;
81-
superType?: langium.Reference<Entity>;
81+
superType?: langium.MultiReference<Entity>;
8282
}
8383

8484
export const Entity = 'Entity';

examples/domainmodel/src/language-server/generated/grammar.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
211211
"operator": "=",
212212
"terminal": {
213213
"$type": "CrossReference",
214+
"isMulti": true,
214215
"type": {
215216
"$ref": "#/rules@5"
216217
},
@@ -305,7 +306,8 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
305306
},
306307
"arguments": []
307308
},
308-
"deprecatedSyntax": false
309+
"deprecatedSyntax": false,
310+
"isMulti": false
309311
}
310312
}
311313
]

examples/requirements/src/language-server/generated/grammar.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
168168
"type": {
169169
"$ref": "#/rules@1"
170170
},
171-
"deprecatedSyntax": false
171+
"deprecatedSyntax": false,
172+
"isMulti": false
172173
}
173174
},
174175
{
@@ -187,7 +188,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
187188
"type": {
188189
"$ref": "#/rules@1"
189190
},
190-
"deprecatedSyntax": false
191+
"deprecatedSyntax": false,
192+
"isMulti": false
191193
}
192194
}
193195
],
@@ -428,7 +430,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
428430
},
429431
"arguments": []
430432
},
431-
"deprecatedSyntax": false
433+
"deprecatedSyntax": false,
434+
"isMulti": false
432435
}
433436
},
434437
{
@@ -454,7 +457,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
454457
},
455458
"arguments": []
456459
},
457-
"deprecatedSyntax": false
460+
"deprecatedSyntax": false,
461+
"isMulti": false
458462
}
459463
}
460464
],
@@ -480,7 +484,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
480484
"type": {
481485
"$ref": "#/rules@3"
482486
},
483-
"deprecatedSyntax": false
487+
"deprecatedSyntax": false,
488+
"isMulti": false
484489
}
485490
},
486491
{
@@ -499,7 +504,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
499504
"type": {
500505
"$ref": "#/rules@3"
501506
},
502-
"deprecatedSyntax": false
507+
"deprecatedSyntax": false,
508+
"isMulti": false
503509
}
504510
}
505511
],
@@ -672,7 +678,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
672678
"type": {
673679
"$ref": "#/rules@3"
674680
},
675-
"deprecatedSyntax": false
681+
"deprecatedSyntax": false,
682+
"isMulti": false
676683
}
677684
},
678685
{
@@ -691,7 +698,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
691698
"type": {
692699
"$ref": "#/rules@3"
693700
},
694-
"deprecatedSyntax": false
701+
"deprecatedSyntax": false,
702+
"isMulti": false
695703
}
696704
}
697705
],

examples/statemachine/src/language-server/generated/grammar.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
9696
"type": {
9797
"$ref": "#/rules@3"
9898
},
99-
"deprecatedSyntax": false
99+
"deprecatedSyntax": false,
100+
"isMulti": false
100101
},
101102
"$comment": "/** The starting state for the machine */"
102103
},
@@ -210,7 +211,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
210211
"type": {
211212
"$ref": "#/rules@2"
212213
},
213-
"deprecatedSyntax": false
214+
"deprecatedSyntax": false,
215+
"isMulti": false
214216
},
215217
"cardinality": "+"
216218
},
@@ -264,7 +266,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
264266
"type": {
265267
"$ref": "#/rules@1"
266268
},
267-
"deprecatedSyntax": false
269+
"deprecatedSyntax": false,
270+
"isMulti": false
268271
},
269272
"$comment": "/** The event triggering the transition */"
270273
},
@@ -281,7 +284,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
281284
"type": {
282285
"$ref": "#/rules@3"
283286
},
284-
"deprecatedSyntax": false
287+
"deprecatedSyntax": false,
288+
"isMulti": false
285289
},
286290
"$comment": "/** The target state */"
287291
}

packages/langium-cli/src/generator/ast-generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* This program and the accompanying materials are made available under the
44
* terms of the MIT License, which is available in the project root.
55
******************************************************************************/
6+
67
import type { Grammar, LangiumCoreServices } from 'langium';
78
import { EOL, type Generated, expandToNode, joinToNode, toString } from 'langium/generate';
89
import type { AstTypes, Property, PropertyDefaultValue } from 'langium/grammar';

packages/langium-cli/src/generator/grammar-serializer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
******************************************************************************/
66

77
/* eslint-disable @stylistic/indent */
8-
import type { Grammar, LangiumCoreServices, Reference } from 'langium';
8+
import type { Grammar, LangiumCoreServices } from 'langium';
99
import { expandToNode, joinToNode, normalizeEOL, toString } from 'langium/generate';
1010
import type { URI } from 'vscode-uri';
1111
import type { LangiumConfig } from '../package-types.js';
@@ -31,9 +31,9 @@ export function serializeGrammar(services: LangiumCoreServices, grammars: Gramma
3131
grammar => {
3232
const production = config.mode === 'production';
3333
const delimiter = production ? "'" : '`';
34-
const uriConverter = (uri: URI, ref: Reference) => {
34+
const uriConverter = (uri: URI) => {
3535
// We expect the grammar to be self-contained after the transformations we've done before
36-
throw new Error(`Unexpected reference to symbol '${ref.$refText}' in document: ${uri.toString()}`);
36+
throw new Error(`Unexpected reference to element in document: ${uri.toString()}`);
3737
};
3838
const serializedGrammar = services.serializer.JsonSerializer.serialize(grammar, {
3939
space: production ? undefined : 2,

0 commit comments

Comments
 (0)