Skip to content

Commit 5d8eb18

Browse files
committed
updated the playground to support langium 4.1
1 parent 7428549 commit 5d8eb18

5 files changed

Lines changed: 1179 additions & 331 deletions

File tree

hugo/content/playground/common.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { render } from './Tree.js';
1414
import { overlay, throttle } from "./utils.js";
1515
import { addMonacoStyles, createUserConfig, MonacoEditorLanguageClientWrapper } from "langium-website-core/bundle";
1616
import { DocumentChangeResponse } from "langium-ast-helper";
17-
import { DefaultAstNodeLocator } from "langium";
17+
import { DefaultAstNodeLocator, LanguageMetaData } from "langium";
1818
import { createServicesForGrammar } from "langium/grammar";
1919
import { generateTextMate } from "langium-cli/textmate";
2020
export { share, overlay } from './utils.js';
@@ -209,8 +209,16 @@ async function getFreshDSLWrapper(
209209
code: string,
210210
grammarText: string
211211
): Promise<MonacoEditorLanguageClientWrapper | undefined> {
212+
213+
const languageMetaData: LanguageMetaData = {
214+
caseInsensitive: false,
215+
fileExtensions: [`.${languageId}`],
216+
languageId: languageId,
217+
mode: 'development'
218+
};
219+
212220
// construct and set a new monarch syntax onto the editor
213-
const { Grammar } = await createServicesForGrammar({ grammar: grammarText });
221+
const { Grammar } = await createServicesForGrammar({ grammar: grammarText, languageMetaData });
214222
const worker = await getLSWorkerForGrammar(grammarText);
215223
const wrapper = new MonacoEditorLanguageClientWrapper();
216224
const textmateGrammar = JSON.parse(generateTextMate(Grammar, { id: languageId, grammar: 'UserGrammar' }));

hugo/content/playground/user-validator.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ export class PlaygroundValidator extends DefaultDocumentValidator {
1111
const linkingError = reference.error;
1212
if (linkingError) {
1313
const info: DiagnosticInfo<AstNode, string> = {
14-
node: linkingError.container,
15-
property: linkingError.property,
16-
index: linkingError.index,
14+
node: linkingError.info.container,
15+
range: reference.$refNode?.range,
16+
property: linkingError.info.property,
17+
index: linkingError.info.index,
1718
data: {
1819
code: DocumentValidator.LinkingError,
19-
containerType: linkingError.container.$type,
20-
property: linkingError.property,
21-
refText: linkingError.reference.$refText
20+
containerType: linkingError.info.container.$type,
21+
property: linkingError.info.property,
22+
refText: linkingError.info.reference.$refText
2223
} satisfies LinkingErrorData
2324
};
2425
diagnostics.push(this.toDiagnostic('warning', `${linkingError.message}\nIn case you want to adjust the linking rules, please consult the learning section in the Langium documentation.`, info));

hugo/content/playground/user-worker.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import { NotificationType } from 'vscode-languageserver/browser.js';
88
import { DocumentChange, createServerConnection } from './worker-utils.js';
9-
import { LangiumServices, startLanguageServer } from 'langium/lsp';
10-
import { DocumentState } from 'langium';
11-
import { createServicesForGrammar } from 'langium/grammar';
9+
import { createDefaultModule, LangiumServices, startLanguageServer } from 'langium/lsp';
10+
import { DefaultServiceRegistry, DocumentState, inject } from 'langium';
11+
import { createServicesForGrammar, LangiumGrammarGeneratedModule } from 'langium/grammar';
1212
import { PlaygroundValidator } from './user-validator.js';
1313

1414
// listen for messages to trigger starting the LS with a given grammar
@@ -34,21 +34,22 @@ async function startWithGrammar(grammarText: string): Promise<void> {
3434
// create a fresh connection for the LS
3535
const connection = createServerConnection();
3636

37-
// create shared services & serializer for the given grammar grammar
38-
const { shared, serializer } = await createServicesForGrammar({
37+
const module = {
3938
grammar: grammarText,
4039
module: {
4140
validation: {
4241
DocumentValidator: (services: LangiumServices) => new PlaygroundValidator(services)
4342
}
4443
},
4544
sharedModule: {
46-
4745
lsp: {
4846
Connection: () => connection,
4947
}
5048
},
51-
});
49+
};
50+
51+
// create shared services & serializer for the given grammar grammar
52+
const { shared, serializer } = await createServicesForGrammar(module);
5253

5354
// listen for validated documents, and send the AST back to the language client
5455
shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Validated, documents => {
@@ -61,7 +62,7 @@ async function startWithGrammar(grammarText: string): Promise<void> {
6162
});
6263
}
6364
});
64-
65+
6566
// start the LS
6667
startLanguageServer(shared);
6768

hugo/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
"clsx": "^1.2.1",
4040
"d3": "^7.8.5",
4141
"hugo-extended": "~0.89.4",
42-
"langium": "^3.0.0",
43-
"langium-arithmetics-dsl": "^3.0.0",
42+
"langium": "^4.1.0",
43+
"langium-arithmetics-dsl": "^4.1.0",
4444
"langium-ast-helper": "0.1.2",
45-
"langium-cli": "^3.0.3",
46-
"langium-domainmodel-dsl": "^3.0.0",
47-
"langium-minilogo": "^3.0.0",
45+
"langium-cli": "^4.1.0",
46+
"langium-domainmodel-dsl": "^4.1.0",
47+
"langium-minilogo": "^3.0.1",
4848
"langium-sql": "^0.3.2",
49-
"langium-statemachine-dsl": "^3.0.0",
49+
"langium-statemachine-dsl": "^4.1.0",
5050
"langium-website-core": "~1.0.0",
5151
"lz-string": "^1.4.4",
5252
"monaco-editor-workers": "~0.44.0",

0 commit comments

Comments
 (0)