Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ For each minor and major version, there is a corresponding [milestone on GitHub]
- Typir core: `createTypirServicesWithAdditionalServices<..., AdditionalServices>(Module<AdditionalServices>, ...)`, see `customization-example.test.ts` for examples and explanations
- Typir-Langium: `createTypirLangiumServicesWithAdditionalServices<..., AdditionalServices>(..., Module<AdditionalServices>, ...)` works in the same way
- The `$name`s of kinds are configurable now.
- Typir-Langium: The Langium services are stored in the `TypirLangiumAddedServices` now as `services.langium.LangiumServices` in order to make them available for all Typir services.

### Fixed bugs

Expand Down
11 changes: 6 additions & 5 deletions packages/typir-langium/src/features/langium-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import { AstNode, DocumentCache, DocumentState, LangiumSharedCoreServices } from 'langium';
import { AstNode, DocumentCache, DocumentState } from 'langium';
import { CachePending, LanguageNodeInferenceCaching, Type } from 'typir';
import { getDocumentKey } from '../utils/typir-langium-utils.js';
import { TypirLangiumServices } from '../typir-langium.js';
import { getDocumentKey, LangiumAstTypes } from '../utils/typir-langium-utils.js';

// cache AstNodes
export class LangiumLanguageNodeInferenceCaching implements LanguageNodeInferenceCaching {
export class LangiumLanguageNodeInferenceCaching<AstTypes extends LangiumAstTypes> implements LanguageNodeInferenceCaching {
protected readonly cache: DocumentCache<unknown, Type | CachePending>; // removes cached AstNodes, if their underlying LangiumDocuments are invalidated

constructor(langiumServices: LangiumSharedCoreServices) {
this.cache = new DocumentCache(langiumServices, DocumentState.IndexedReferences);
constructor(typirServices: TypirLangiumServices<AstTypes>) {
this.cache = new DocumentCache(typirServices.langium.LangiumServices, DocumentState.IndexedReferences);
Comment thread
insafuhrmann marked this conversation as resolved.
}

cacheSet(languageNode: AstNode, type: Type): void {
Expand Down
8 changes: 4 additions & 4 deletions packages/typir-langium/src/features/langium-type-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import { AstNode, AstUtils, DocumentState, interruptAndCheck, LangiumDocument, LangiumSharedCoreServices } from 'langium';
import { AstNode, AstUtils, DocumentState, interruptAndCheck, LangiumDocument } from 'langium';
import { Type, TypeGraph, TypeGraphListener } from 'typir';
import { TypirLangiumServices } from '../typir-langium.js';
import { getDocumentKeyForDocument, getDocumentKeyForURI, LangiumAstTypes } from '../utils/typir-langium-utils.js';
Expand Down Expand Up @@ -55,14 +55,14 @@ export class DefaultLangiumTypeCreator<AstTypes extends LangiumAstTypes> impleme
protected readonly typeGraph: TypeGraph;
protected readonly typeSystemDefinition: LangiumTypeSystemDefinition<AstTypes>;

constructor(typirServices: TypirLangiumServices<AstTypes>, langiumServices: LangiumSharedCoreServices) {
constructor(typirServices: TypirLangiumServices<AstTypes>) {
this.typir = typirServices;
this.typeGraph = typirServices.infrastructure.Graph;
this.typeSystemDefinition = typirServices.langium.TypeSystemDefinition;

// for new and updated documents:
// Create Typir types after completing the Langium 'ComputedScopes' phase, since they need to be available for the following Linking phase
langiumServices.workspace.DocumentBuilder.onBuildPhase(DocumentState.ComputedScopes, async (documents, cancelToken) => {
typirServices.langium.LangiumServices.workspace.DocumentBuilder.onBuildPhase(DocumentState.ComputedScopes, async (documents, cancelToken) => {
for (const document of documents) {
await interruptAndCheck(cancelToken);

Expand All @@ -73,7 +73,7 @@ export class DefaultLangiumTypeCreator<AstTypes extends LangiumAstTypes> impleme

// for deleted documents:
// Delete Typir types which are derived from AstNodes of deleted documents
langiumServices.workspace.DocumentBuilder.onUpdate((_changed, deleted) => {
typirServices.langium.LangiumServices.workspace.DocumentBuilder.onUpdate((_changed, deleted) => {
deleted
.map(del => getDocumentKeyForURI(del))
.forEach(del => this.invalidateTypesOfDocument(del));
Expand Down
12 changes: 7 additions & 5 deletions packages/typir-langium/src/typir-langium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { LangiumAstTypes } from './utils/typir-langium-utils.js';
export type TypirLangiumAddedServices<AstTypes extends LangiumAstTypes> = {
readonly Inference: LangiumTypeInferenceCollector<AstTypes>; // concretizes the TypeInferenceCollector for Langium
readonly langium: { // new services which are specific for Langium
readonly LangiumServices: LangiumSharedCoreServices; // store the Langium services to make them usable for all Typir services
readonly TypeCreator: LangiumTypeCreator;
readonly TypeSystemDefinition: LangiumTypeSystemDefinition<AstTypes>;
};
Expand All @@ -40,12 +41,12 @@ export type PartialTypirLangiumServices<AstTypes extends LangiumAstTypes> = Deep
* @param langiumServices Typir-Langium needs to interact with the Langium lifecycle
* @returns (only) the replaced implementations
*/
export function createLangiumSpecificTypirServicesModule(langiumServices: LangiumSharedCoreServices): Module<PartialTypirServices<AstNode>> {
export function createLangiumSpecificTypirServicesModule<AstTypes extends LangiumAstTypes>(_langiumServices: LangiumSharedCoreServices): Module<TypirLangiumServices<AstTypes>, PartialTypirServices<AstNode>> {
return {
Printer: () => new LangiumProblemPrinter(),
Language: () => { throw new Error('Use new LangiumLanguageService(undefined), and replace "undefined" by the generated XXXAstReflection!'); }, // to be replaced later
caching: {
LanguageNodeInference: () => new LangiumLanguageNodeInferenceCaching(langiumServices),
LanguageNodeInference: (typirServices) => new LangiumLanguageNodeInferenceCaching(typirServices),
},
};
}
Expand All @@ -59,7 +60,8 @@ export function createDefaultTypirLangiumServicesModule<AstTypes extends Langium
return {
Inference: (typirServices) => new DefaultLangiumTypeInferenceCollector(typirServices),
langium: {
TypeCreator: (typirServices) => new DefaultLangiumTypeCreator(typirServices, langiumServices),
LangiumServices: () => langiumServices,
TypeCreator: (typirServices) => new DefaultLangiumTypeCreator(typirServices),
TypeSystemDefinition: () => { throw new Error('The type system needs to be specified!'); }, // to be replaced later
},
validation: {
Expand Down Expand Up @@ -93,7 +95,7 @@ export function createTypirLangiumServices<AstTypes extends LangiumAstTypes>(
// use the default implementations for all core Typir services ...
createDefaultTypirServicesModule<AstNode>(),
// ... with adapted implementations for Typir-Langium
createLangiumSpecificTypirServicesModule(langiumServices),
createLangiumSpecificTypirServicesModule<AstTypes>(langiumServices),
// add the additional services for the Typir-Langium binding
createDefaultTypirLangiumServicesModule<AstTypes>(langiumServices),
// add the language-specific parts provided by Langium into the Typir-Services
Expand Down Expand Up @@ -138,7 +140,7 @@ export function createTypirLangiumServicesWithAdditionalServices<AstTypes extend
// use the default implementations for all core Typir services ...
createDefaultTypirServicesModule<AstNode>(),
// ... with adapted implementations for Typir-Langium
createLangiumSpecificTypirServicesModule(langiumServices),
createLangiumSpecificTypirServicesModule<AstTypes>(langiumServices),
// add the additional services for the Typir-Langium binding
createDefaultTypirLangiumServicesModule<AstTypes>(langiumServices),
// add the language-specific parts provided by Langium into the Typir-Services
Expand Down