diff --git a/examples/domainmodel/test/refs-index.test.ts b/examples/domainmodel/test/refs-index.test.ts index 8bd939e32..227e0d349 100644 --- a/examples/domainmodel/test/refs-index.test.ts +++ b/examples/domainmodel/test/refs-index.test.ts @@ -30,9 +30,9 @@ describe('Cross references indexed after affected process', () => { 'entity SuperEntity {}' ) ); - await shared.shared.workspace.DocumentBuilder.update([superDoc.uri], []); + await shared.workspace.DocumentBuilder.update([superDoc.uri], []); - const updatedSuperDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(superDoc.uri); + const updatedSuperDoc = shared.workspace.LangiumDocuments.getOrCreateDocument(superDoc.uri); const superEntity = (updatedSuperDoc.parseResult.value as Domainmodel).elements[0]; allRefs = await getReferences(superEntity); expect(allRefs.length).toEqual(1); // re-linked diff --git a/packages/langium-sprotty/src/default-module.ts b/packages/langium-sprotty/src/default-module.ts index 7bf02077e..21296d551 100644 --- a/packages/langium-sprotty/src/default-module.ts +++ b/packages/langium-sprotty/src/default-module.ts @@ -4,7 +4,8 @@ * terms of the MIT License, which is available in the project root. ******************************************************************************/ -import type { Module, PartialLangiumServices } from 'langium'; +import type { Module } from 'langium'; +import type { PartialLangiumServices } from 'langium/lsp'; import type { DiagramOptions } from 'sprotty-protocol'; import type { LangiumSprottyServices, LangiumSprottySharedServices, SprottyDefaultServices, SprottySharedServices } from './sprotty-services.js'; import { DiagramServer } from 'sprotty-protocol'; diff --git a/packages/langium-sprotty/src/position-tracker.ts b/packages/langium-sprotty/src/position-tracker.ts index 5c4078437..9abd72c80 100644 --- a/packages/langium-sprotty/src/position-tracker.ts +++ b/packages/langium-sprotty/src/position-tracker.ts @@ -8,7 +8,7 @@ import type { LangiumDocument, MaybePromise } from 'langium'; import type { Position } from 'vscode-languageserver'; import type { DocumentHighlight, DocumentHighlightParams } from 'vscode-languageserver'; import type { LangiumSprottyServices } from './sprotty-services.js'; -import { DefaultDocumentHighlightProvider } from 'langium'; +import { DefaultDocumentHighlightProvider } from 'langium/lsp'; /** * This service provides access to the user's current cursor position. diff --git a/packages/langium-sprotty/src/sprotty-services.ts b/packages/langium-sprotty/src/sprotty-services.ts index 0aeadd5f0..31e69069b 100644 --- a/packages/langium-sprotty/src/sprotty-services.ts +++ b/packages/langium-sprotty/src/sprotty-services.ts @@ -4,8 +4,7 @@ * terms of the MIT License, which is available in the project root. ******************************************************************************/ -import type { LangiumCoreServices } from 'langium'; -import type { LangiumSharedServices } from 'langium/lsp'; +import type { LangiumServices, LangiumSharedServices } from 'langium/lsp'; import type { DiagramOptions, DiagramServer, DiagramServices } from 'sprotty-protocol'; import type { ServerActionHandlerRegistry } from 'sprotty-protocol/lib/action-handler.js'; import type { DiagnosticMarkerProvider } from './diagnostic-marker-provider.js'; @@ -35,7 +34,7 @@ export type SprottyDefaultServices = { /** * Extension of the `LangiumServices` with the diagram-related services. */ -export type LangiumSprottyServices = LangiumCoreServices & SprottyDiagramServices & SprottyDefaultServices & { +export type LangiumSprottyServices = LangiumServices & SprottyDiagramServices & SprottyDefaultServices & { shared: LangiumSprottySharedServices } diff --git a/packages/langium-sprotty/test/trace-provider.test.ts b/packages/langium-sprotty/test/trace-provider.test.ts index d1667a4d7..ac37d17a0 100644 --- a/packages/langium-sprotty/test/trace-provider.test.ts +++ b/packages/langium-sprotty/test/trace-provider.test.ts @@ -5,7 +5,7 @@ ******************************************************************************/ import type { AstNode } from 'langium'; -import type { TracedModelElement } from 'langium-sprotty'; +import type { LangiumSprottyServices, LangiumSprottySharedServices, TracedModelElement } from 'langium-sprotty'; import type { SModelRoot } from 'sprotty-protocol'; import { beforeEach, describe, expect, test } from 'vitest'; import { createServicesForGrammar } from 'langium/grammar'; @@ -22,7 +22,7 @@ describe('DefaultTraceProvider', async () => { hidden terminal WS: /\\s+/; terminal ID: /[_a-zA-Z][\\w_]*/; `; - const services = await createServicesForGrammar({ + const services = await createServicesForGrammar({ grammar, module: SprottyDefaultModule, sharedModule: SprottySharedModule diff --git a/packages/langium/src/lsp/document-update-handler.ts b/packages/langium/src/lsp/document-update-handler.ts index 3952f7b61..20f18e868 100644 --- a/packages/langium/src/lsp/document-update-handler.ts +++ b/packages/langium/src/lsp/document-update-handler.ts @@ -6,7 +6,7 @@ import type { DidChangeWatchedFilesParams, DidChangeWatchedFilesRegistrationOptions, TextDocumentChangeEvent } from 'vscode-languageserver'; import type { TextDocument } from 'vscode-languageserver-textdocument'; -import type { LangiumSharedServices } from '../services.js'; +import type { LangiumSharedServices } from './lsp-services.js'; import type { WorkspaceLock } from '../workspace/workspace-lock.js'; import type { DocumentBuilder } from '../workspace/document-builder.js'; import { DidChangeWatchedFilesNotification, FileChangeType } from 'vscode-languageserver'; diff --git a/packages/langium/src/lsp/language-server.ts b/packages/langium/src/lsp/language-server.ts index 1d05c2ade..4255e87c8 100644 --- a/packages/langium/src/lsp/language-server.ts +++ b/packages/langium/src/lsp/language-server.ts @@ -225,8 +225,15 @@ export function startLanguageServer(services: LangiumSharedServices): void { connection.listen(); } +/** + * Adds a handler for document updates when content changes, or watch catches a change. + * In the case there is no handler service registered, this function does nothing. + */ export function addDocumentUpdateHandler(connection: Connection, services: LangiumSharedServices): void { const handler = services.lsp.DocumentUpdateHandler; + if (!handler) { + return; + } const documents = services.workspace.TextDocuments; documents.onDidChangeContent(change => handler.didChangeContent(change)); connection.onDidChangeWatchedFiles(params => handler.didChangeWatchedFiles(params)); diff --git a/packages/langium/test/workspace/document-factory.test.ts b/packages/langium/test/workspace/document-factory.test.ts index 3ff52bf2c..9f8c78ade 100644 --- a/packages/langium/test/workspace/document-factory.test.ts +++ b/packages/langium/test/workspace/document-factory.test.ts @@ -4,7 +4,8 @@ * terms of the MIT License, which is available in the project root. ******************************************************************************/ -import type { Grammar, LangiumServices } from 'langium'; +import type { Grammar } from 'langium'; +import type { LangiumServices } from 'langium/lsp'; import { describe, expect, test } from 'vitest'; import { TextDocument } from 'vscode-languageserver-textdocument'; import { DocumentState, EmptyFileSystem } from 'langium';