Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
"type": {
"$ref": "#/types@0"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ export class DomainModelRenameProvider extends DefaultRenameProvider {
const offset = document.textDocument.offsetAt(params.position);
const leafNode = CstUtils.findDeclarationNodeAtOffset(rootNode, offset, this.grammarConfig.nameRegexp);
if (!leafNode) return undefined;
const targetNode = this.references.findDeclaration(leafNode);
if (!targetNode) return undefined;
if (isNamed(targetNode)) targetNode.name = params.newName;
const location = this.getNodeLocation(targetNode);
if (location) {
const change = TextEdit.replace(location.range, params.newName);
const uri = location.uri;
if (uri) {
if (changes[uri]) {
changes[uri].push(change);
} else {
changes[uri] = [change];
const targetNodes = this.references.findDeclarations(leafNode);
if (!targetNodes.length) return undefined;
for (const node of targetNodes) {
if (isNamed(node)) node.name = params.newName;
const location = this.getNodeLocation(node);
if (location) {
const change = TextEdit.replace(location.range, params.newName);
const uri = location.uri;
if (uri) {
if (changes[uri]) {
changes[uri].push(change);
} else {
changes[uri] = [change];
}
}
}
}

const targetNode = targetNodes[0];
for (const node of AstUtils.streamAst(targetNode)) {
const qn = this.buildQualifiedName(node);
if (qn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DataType:
'datatype' name=ID;

Entity:
'entity' name=ID ('extends' superType=[Entity:QualifiedName])? '{'
'entity' name=ID ('extends' superType=[+Entity:QualifiedName])? '{'
(features+=Feature)*
'}';

Expand Down
2 changes: 1 addition & 1 deletion examples/domainmodel/src/language-server/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface Entity extends langium.AstNode {
readonly $type: 'Entity';
features: Array<Feature>;
name: string;
superType?: langium.Reference<Entity>;
superType?: langium.MultiReference<Entity>;
}

export const Entity = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
"operator": "=",
"terminal": {
"$type": "CrossReference",
"isMulti": true,
"type": {
"$ref": "#/rules@5"
},
Expand Down Expand Up @@ -287,7 +288,8 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
]
Expand Down
24 changes: 16 additions & 8 deletions examples/requirements/src/language-server/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"type": {
"$ref": "#/rules@1"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand All @@ -181,7 +182,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"type": {
"$ref": "#/rules@1"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
],
Expand Down Expand Up @@ -410,7 +412,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand All @@ -436,7 +439,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
],
Expand All @@ -462,7 +466,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"type": {
"$ref": "#/rules@3"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand All @@ -481,7 +486,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"type": {
"$ref": "#/rules@3"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
],
Expand Down Expand Up @@ -645,7 +651,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"type": {
"$ref": "#/rules@3"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand All @@ -664,7 +671,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"type": {
"$ref": "#/rules@3"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
],
Expand Down
12 changes: 8 additions & 4 deletions examples/statemachine/src/language-server/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"type": {
"$ref": "#/rules@3"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
},
"$comment": "/** The starting state for the machine */"
},
Expand Down Expand Up @@ -201,7 +202,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"type": {
"$ref": "#/rules@2"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
},
"cardinality": "+"
},
Expand Down Expand Up @@ -252,7 +254,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"type": {
"$ref": "#/rules@1"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
},
"$comment": "/** The event triggering the transition */"
},
Expand All @@ -269,7 +272,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"type": {
"$ref": "#/rules@3"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
},
"$comment": "/** The target state */"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/langium-cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function mapGrammarElements(grammars: Grammar[], visited: Set<string> = new Set(
.concat(grammar.types)
.concat(grammar.interfaces)
);
const importedGrammars = grammar.imports.map(e => resolveImport(documents, e)).filter((e): e is Grammar => e !== undefined);
const importedGrammars = grammar.imports.map(e => resolveImport(documents, e)).filter(e => e !== undefined);
mapGrammarElements(importedGrammars, visited, map);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/langium-cli/src/generator/ast-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { Grammar, LangiumCoreServices } from 'langium';
import { EOL, type Generated, expandToNode, joinToNode, toString } from 'langium/generate';
import type { AstTypes, Property, PropertyDefaultValue } from 'langium/grammar';
Expand Down
6 changes: 3 additions & 3 deletions packages/langium-cli/src/generator/grammar-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

/* eslint-disable @stylistic/indent */
import type { Grammar, LangiumCoreServices, Reference } from 'langium';
import type { Grammar, LangiumCoreServices } from 'langium';
import { expandToNode, joinToNode, normalizeEOL, toString } from 'langium/generate';
import type { URI } from 'vscode-uri';
import type { LangiumConfig } from '../package-types.js';
Expand All @@ -31,9 +31,9 @@ export function serializeGrammar(services: LangiumCoreServices, grammars: Gramma
grammar => {
const production = config.mode === 'production';
const delimiter = production ? "'" : '`';
const uriConverter = (uri: URI, ref: Reference) => {
const uriConverter = (uri: URI) => {
// We expect the grammar to be self-contained after the transformations we've done before
throw new Error(`Unexpected reference to symbol '${ref.$refText}' in document: ${uri.toString()}`);
throw new Error(`Unexpected reference to element in document: ${uri.toString()}`);
};
const serializedGrammar = services.serializer.JsonSerializer.serialize(grammar, {
space: production ? undefined : 2,
Expand Down
2 changes: 1 addition & 1 deletion packages/langium/src/documentation/jsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class JSDocCommentImpl implements JSDocComment {
}

private getAllTags(): JSDocTag[] {
return this.elements.filter((e): e is JSDocTag => 'name' in e);
return this.elements.filter(e => 'name' in e);
}

toString(): string {
Expand Down
53 changes: 42 additions & 11 deletions packages/langium/src/grammar/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand All @@ -177,7 +178,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
],
Expand Down Expand Up @@ -620,6 +622,16 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
}
},
{
"$type": "Assignment",
"feature": "isMulti",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "+"
},
"cardinality": "?"
}
]
}
Expand Down Expand Up @@ -688,7 +700,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -939,7 +952,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -1733,7 +1747,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -1942,7 +1957,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -2024,7 +2040,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -2303,7 +2320,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
"entry": false,
Expand Down Expand Up @@ -2400,7 +2418,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -2701,6 +2720,16 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
"$type": "Keyword",
"value": "["
},
{
"$type": "Assignment",
"feature": "isMulti",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "+"
},
"cardinality": "?"
},
{
"$type": "Assignment",
"feature": "type",
Expand All @@ -2710,7 +2739,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
"type": {
"$ref": "#/types@0"
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
},
{
Expand Down Expand Up @@ -3328,7 +3358,8 @@ export const LangiumGrammarGrammar = (): Grammar => loadedLangiumGrammarGrammar
},
"arguments": []
},
"deprecatedSyntax": false
"deprecatedSyntax": false,
"isMulti": false
}
}
]
Expand Down
Loading