How to extend parsing-only Langium language #1479
-
If I have a language that is a parsing-only language, it uses sample code/** Declaration of `Example` services. */
interface ExampleAddedServices {}
/** Union of Langium default services and `Example` services. */
export type ExampleServices = LangiumCoreServices & ExampleAddedServices;
/**
* Dependency injection module that overrides Langium default services
* and contributes the declared `Example` services.
*/
export const ExampleModule: Module<
ExampleServices,
PartialLangiumCoreServices & ExampleAddedServices
> = {}; How can I extend it so it uses the I tried the following code: /** Declaration of `Example` lsp services. */
interface ExampleLspAddedServices {}
/** Union of Langium default services and `Example` lsp services. */
export type ExampleLspServices = LangiumServices & ExampleServices & ExampleLspAddedServices;
/**
* Dependency injection module that overrides Langium default services
* and contributes the declared `Example` lsp services.
*/
export const ExampleLspModule: Module<
ExampleLspServices,
PartialLangiumServices & ExampleLspAddedServices
> = {
...ExampleModule,
}; But it throws an error, because the
I tried to do the following: export const ExampleLspModule: Module<
ExampleLspServices,
PartialLangiumServices & ExampleLspAddedServices
> = {
...ExampleModule,
shared: {
...ExampleModule?.shared,
workspace: {
...ExampleModule?.shared?.workspace,
TextDocuments: undefined,
},
},
}; But I can't access the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @Yokozuna59, you're not supposed to override the export const ExampleLspModule: Module<
ExampleLspServices,
PartialLangiumServices & ExampleLspAddedServices
> = {
lsp: {
completion: () => ... // only override a specific LSP service
}
};
...
// in the createModule function
const shared = inject(
createDefaultSharedModule(context),
ExampleGeneratedSharedModule
);
const example= inject(
createDefaultModule({ shared }),
ExampleGeneratedModule,
ExampleModule, // reuse the non-LSP module here
ExampleLspModule // add LSP specific modules here
); Though we can probably document this a bit better. This probably deserves a small guide on our website. |
Beta Was this translation helpful? Give feedback.
Hey @Yokozuna59,
you're not supposed to override the
shared
service instance at all in a language specific service module, since it is set from outside of the module, see here, which is probably why the (pretty cryptic) error message appears. Instead of using the operator on the fullExampleModule
, we imagined that adopters would use the API like this: