-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathlangium-worker.ts
32 lines (27 loc) · 1.48 KB
/
langium-worker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/******************************************************************************
* Copyright 2022 TypeFox GmbH
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/
import { NotificationType } from 'vscode-languageserver/browser.js';
import { DocumentChange, createServerConnection } from './worker-utils.js';
import { EmptyFileSystem, DocumentState } from 'langium';
import { startLanguageServer } from 'langium/lsp';
import { createLangiumGrammarServices } from 'langium/grammar';
// establish a browser server connection
const connection = createServerConnection();
// Inject the shared services and language-specific services
const { shared } = createLangiumGrammarServices({ connection, ...EmptyFileSystem });
// Start the language server with the shared services
startLanguageServer(shared);
// Send a notification with the serialized AST after every document change
const documentChangeNotification = new NotificationType<DocumentChange>('browser/DocumentChange');
shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Validated, documents => {
for (const document of documents) {
connection.sendNotification(documentChangeNotification, {
uri: document.uri.toString(),
content: document.textDocument.getText(),
diagnostics: document.diagnostics ?? []
});
}
});