Skip to content

Commit

Permalink
rename DefaultServiceRegistry -> CoreServiceRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
montymxb committed Nov 24, 2023
1 parent f92455a commit 5950b8e
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 34 deletions.
4 changes: 2 additions & 2 deletions packages/langium/src/default-module.ts
Expand Up @@ -19,7 +19,7 @@ import { DefaultReferences } from './references/references.js';
import { DefaultScopeComputation } from './references/scope-computation.js';
import { DefaultScopeProvider } from './references/scope-provider.js';
import { DefaultJsonSerializer } from './serializer/json-serializer.js';
import { DefaultServiceRegistry } from './service-registry.js';
import { CoreServiceRegistry } from './service-registry.js';
import { MutexLock } from './utils/promise-util.js';
import { DefaultDocumentValidator } from './validation/document-validator.js';
import { ValidationRegistry } from './validation/validation-registry.js';
Expand Down Expand Up @@ -108,7 +108,7 @@ export interface DefaultSharedModuleContext {
*/
export function createDefaultSharedModule(context: DefaultSharedModuleContext): Module<LangiumSharedCoreServices, LangiumDefaultSharedServices> {
return {
ServiceRegistry: () => new DefaultServiceRegistry(),
ServiceRegistry: () => new CoreServiceRegistry(),
workspace: {
LangiumDocuments: (services) => new DefaultLangiumDocuments(services),
LangiumDocumentFactory: (services) => new DefaultLangiumDocumentFactory(services),
Expand Down
6 changes: 3 additions & 3 deletions packages/langium/src/lsp/langium-lsp-module.ts
Expand Up @@ -12,7 +12,7 @@ import { DefaultDefinitionProvider } from './definition-provider.js';
import { MultilineCommentHoverProvider } from './hover-provider.js';
import { DefaultReferencesProvider } from './references-provider.js';
import { DefaultRenameProvider } from './rename-provider.js';
import type { LSPServiceRegistry, LangiumServices, LangiumLSPServices, LangiumSharedLSPServices, PartialLangiumSharedLSPServices, LangiumSharedServices } from './lsp-services.js';
import type { ServiceRegistryI, LangiumServices, LangiumLSPServices, LangiumSharedLSPServices, PartialLangiumSharedLSPServices, LangiumSharedServices } from './lsp-services.js';
import { inject, type Module } from '../dependency-injection.js';
import { TextDocuments } from 'vscode-languageserver';
import { createDefaultModule, createDefaultSharedModule, type DefaultSharedModuleContext } from '../default-module.js';
Expand All @@ -29,7 +29,7 @@ import { registerTypeValidationChecks } from '../grammar/validation/types-valida
import { LSPConfigurationProvider } from './workspace/default-configuration.js';
import { LSPLangiumDocumentFactory } from './workspace/documents.js';
import { LSPWorkspaceManager } from './workspace/workspace-manager.js';
import { DefaultServiceRegistry } from '../service-registry.js';
import { CoreServiceRegistry } from '../service-registry.js';

/**
* Context required for creating the default language-specific dependency injection module.
Expand Down Expand Up @@ -65,7 +65,7 @@ export function createLSPModule(context: LSPModuleContext): Module<LangiumServic
export function createSharedLSPModule(context: DefaultSharedModuleContext): Module<LangiumSharedLSPServices & LangiumSharedCoreServices, LangiumSharedLSPServices> {
return {
// use the regular registry as an LSP registry, assuming the registry itself is opaque
ServiceRegistry: () => (new DefaultServiceRegistry()) as LSPServiceRegistry,
ServiceRegistry: () => (new CoreServiceRegistry()) as ServiceRegistryI,
lsp: {
Connection: () => context.connection,
LanguageServer: (services) => new DefaultLanguageServer(services),
Expand Down
10 changes: 5 additions & 5 deletions packages/langium/src/lsp/lsp-services.ts
Expand Up @@ -39,12 +39,12 @@ import type { LangiumDocumentFactory } from './../workspace/documents.js';
import type { WorkspaceManager } from './../workspace/workspace-manager.js';

/**
* Combined Default + LSP services of Langium
* Combined Core + LSP services of Langium (total services)
*/
export type LangiumServices = LangiumCoreServices & LangiumLSPServices;

/**
* Combined Default + LSP shared services of Langium
* Combined Core + LSP shared services of Langium (total services)
*/
export type LangiumSharedServices = LangiumSharedCoreServices & LangiumSharedLSPServices;

Expand Down Expand Up @@ -81,11 +81,11 @@ export type LangiumLSPServices = {
} & LSPServices;

/**
* An LSP-specific service registry provides access to the language-specific services. These are resolved
* A core + lsp service registry provides access to the language-specific services. These are resolved
* via the URI of a text document.
* This LSP interface simply extends upon the regular service registry's interface
*/
export interface LSPServiceRegistry {
export interface ServiceRegistryI {

/**
* Register a language via its injected services.
Expand All @@ -108,7 +108,7 @@ export interface LSPServiceRegistry {
* LSP Services shared between multiple languages where Langium provides default implementations.
*/
export type LangiumSharedLSPServices = {
ServiceRegistry: LSPServiceRegistry
ServiceRegistry: ServiceRegistryI
lsp: {
Connection?: Connection
ExecuteCommandHandler?: ExecuteCommandHandler
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/lsp/workspace/default-configuration.ts
Expand Up @@ -6,7 +6,7 @@

import type { Connection, DidChangeConfigurationParams } from 'vscode-languageserver';
import type { ConfigurationItem } from 'vscode-languageserver-protocol';
import type { ServiceRegistry } from '../../service-registry.js';
import type { CoreServiceRegistryI } from '../../service-registry.js';
import { DidChangeConfigurationNotification } from 'vscode-languageserver-protocol';
import type { ConfigurationProvider } from '../../workspace/configuration.js';
import type { LangiumSharedServices } from '../lsp-services.js';
Expand All @@ -21,7 +21,7 @@ export class LSPConfigurationProvider implements ConfigurationProvider {
protected settings: Record<string, Record<string, any>> = {};
protected workspaceConfig = false;
protected initialized = false;
protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly connection: Connection | undefined;

constructor(services: LangiumSharedServices) {
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/lsp/workspace/documents.ts
Expand Up @@ -6,7 +6,7 @@

import type { TextDocuments } from 'vscode-languageserver';
import type { ParseResult } from '../../parser/langium-parser.js';
import type { ServiceRegistry } from '../../service-registry.js';
import type { CoreServiceRegistryI } from '../../service-registry.js';
import type { AstNode } from '../../syntax-tree.js';
import type { Mutable } from '../../utils/ast-util.js';
import type { FileSystemProvider } from './../../workspace/file-system-provider.js';
Expand All @@ -20,7 +20,7 @@ import type { LangiumSharedServices } from '../lsp-services.js';
*/
export class LSPLangiumDocumentFactory implements LangiumDocumentFactory {

protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly textDocuments: TextDocuments<TextDocument>;
protected readonly fileSystemProvider: FileSystemProvider;

Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/lsp/workspace/workspace-manager.ts
Expand Up @@ -9,7 +9,7 @@ import { interruptAndCheck } from '../../utils/promise-util.js';
import { URI, UriUtils } from '../../utils/uri-util.js';
import type { WorkspaceManager } from './../../workspace/workspace-manager.js';
import type { WorkspaceFolder } from 'vscode-languageserver';
import type { ServiceRegistry } from '../../service-registry.js';
import type { CoreServiceRegistryI } from '../../service-registry.js';
import type { MutexLock } from '../../utils/promise-util.js';
import type { BuildOptions, DocumentBuilder } from './../../workspace/document-builder.js';
import type { LangiumDocument, LangiumDocuments } from './../../workspace/documents.js';
Expand All @@ -23,7 +23,7 @@ export class LSPWorkspaceManager implements WorkspaceManager {

initialBuildOptions: BuildOptions = {};

protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly langiumDocuments: LangiumDocuments;
protected readonly documentBuilder: DocumentBuilder;
protected readonly fileSystemProvider: FileSystemProvider;
Expand Down
9 changes: 6 additions & 3 deletions packages/langium/src/service-registry.ts
Expand Up @@ -8,10 +8,10 @@ import type { LangiumCoreServices } from './services.js';
import { UriUtils, type URI } from './utils/uri-util.js';

/**
* The service registry provides access to the language-specific services. These are resolved
* The core service registry provides access to the core language-specific services. These are resolved
* via the URI of a text document.
*/
export interface ServiceRegistry {
export interface CoreServiceRegistryI {

/**
* Register a language via its injected services.
Expand All @@ -30,7 +30,10 @@ export interface ServiceRegistry {
readonly all: readonly LangiumCoreServices[];
}

export class DefaultServiceRegistry implements ServiceRegistry {
/**
* Registry for Langium's core services
*/
export class CoreServiceRegistry implements CoreServiceRegistryI {

protected singleton?: LangiumCoreServices;
protected map?: Record<string, LangiumCoreServices>;
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/services.ts
Expand Up @@ -21,7 +21,7 @@ import type { References } from './references/references.js';
import type { ScopeComputation } from './references/scope-computation.js';
import type { ScopeProvider } from './references/scope-provider.js';
import type { JsonSerializer } from './serializer/json-serializer.js';
import type { ServiceRegistry } from './service-registry.js';
import type { CoreServiceRegistryI } from './service-registry.js';
import type { AstReflection } from './syntax-tree.js';
import type { MutexLock } from './utils/promise-util.js';
import type { DocumentValidator } from './validation/document-validator.js';
Expand Down Expand Up @@ -107,7 +107,7 @@ export type LangiumGeneratedSharedServices = {
* Services shared between multiple languages where Langium provides default implementations.
*/
export type LangiumDefaultSharedServices = {
ServiceRegistry: ServiceRegistry
ServiceRegistry: CoreServiceRegistryI
workspace: {
DocumentBuilder: DocumentBuilder
IndexManager: IndexManager
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/workspace/configuration.ts
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { DidChangeConfigurationParams } from 'vscode-languageserver';
import type { ServiceRegistry } from '../service-registry.js';
import type { CoreServiceRegistryI } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -37,7 +37,7 @@ export class EmptyConfigurationProvider implements ConfigurationProvider {
protected settings: Record<string, Record<string, any>> = {};
protected workspaceConfig = false;
protected initialized = false;
protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;

constructor(services: LangiumSharedCoreServices) {
this.serviceRegistry = services.ServiceRegistry;
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/workspace/document-builder.ts
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { URI } from '../utils/uri-util.js';
import type { ServiceRegistry } from '../service-registry.js';
import type { CoreServiceRegistryI } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { AstNode } from '../syntax-tree.js';
import type { MaybePromise } from '../utils/promise-util.js';
Expand Down Expand Up @@ -95,7 +95,7 @@ export class DefaultDocumentBuilder implements DocumentBuilder {
protected readonly langiumDocuments: LangiumDocuments;
protected readonly langiumDocumentFactory: LangiumDocumentFactory;
protected readonly indexManager: IndexManager;
protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly updateListeners: DocumentUpdateListener[] = [];
protected readonly buildPhaseListeners: MultiMap<DocumentState, DocumentBuildListener> = new MultiMap();
protected readonly buildState: Map<string, DocumentBuildState> = new Map();
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/workspace/documents.ts
Expand Up @@ -7,7 +7,7 @@
import type { Range } from 'vscode-languageserver-textdocument';
import type { Diagnostic } from 'vscode-languageserver';
import type { ParseResult } from '../parser/langium-parser.js';
import type { ServiceRegistry } from '../service-registry.js';
import type { CoreServiceRegistryI } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { AstNode, AstNodeDescription, Reference } from '../syntax-tree.js';
import type { Mutable } from '../utils/ast-util.js';
Expand Down Expand Up @@ -140,7 +140,7 @@ export interface LangiumDocumentFactory {

export class DefaultLangiumDocumentFactory implements LangiumDocumentFactory {

protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly fileSystemProvider: FileSystemProvider;

constructor(services: LangiumSharedCoreServices) {
Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/workspace/index-manager.ts
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { URI } from '../utils/uri-util.js';
import type { ServiceRegistry } from '../service-registry.js';
import type { CoreServiceRegistryI } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { AstNode, AstNodeDescription, AstReflection } from '../syntax-tree.js';
import type { Stream } from '../utils/stream.js';
Expand Down Expand Up @@ -83,7 +83,7 @@ export interface IndexManager {

export class DefaultIndexManager implements IndexManager {

protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly documents: LangiumDocuments;
protected readonly astReflection: AstReflection;

Expand Down
4 changes: 2 additions & 2 deletions packages/langium/src/workspace/workspace-manager.ts
Expand Up @@ -6,7 +6,7 @@

import { URI, UriUtils } from '../utils/uri-util.js';
import type { CancellationToken, WorkspaceFolder } from 'vscode-languageserver';
import type { ServiceRegistry } from '../service-registry.js';
import type { CoreServiceRegistryI } from '../service-registry.js';
import type { LangiumSharedCoreServices } from '../services.js';
import type { MutexLock } from '../utils/promise-util.js';
import type { BuildOptions, DocumentBuilder } from './document-builder.js';
Expand Down Expand Up @@ -37,7 +37,7 @@ export class DefaultWorkspaceManager implements WorkspaceManager {

initialBuildOptions: BuildOptions = {};

protected readonly serviceRegistry: ServiceRegistry;
protected readonly serviceRegistry: CoreServiceRegistryI;
protected readonly langiumDocuments: LangiumDocuments;
protected readonly documentBuilder: DocumentBuilder;
protected readonly fileSystemProvider: FileSystemProvider;
Expand Down
6 changes: 3 additions & 3 deletions packages/langium/test/service-registry.test.ts
Expand Up @@ -8,13 +8,13 @@

import type { LangiumCoreServices } from 'langium';
import { describe, expect, test } from 'vitest';
import { DefaultServiceRegistry, URI } from 'langium';
import { CoreServiceRegistry, URI } from 'langium';

describe('DefaultServiceRegistry', () => {

test('should work with a single language', () => {
const language: LangiumCoreServices = { foo: 'bar' } as any;
const registry = new DefaultServiceRegistry();
const registry = new CoreServiceRegistry();
registry.register(language);
expect(registry.getServices(URI.parse('file:/foo.bar'))).toBe(language);
expect(registry.all).toHaveLength(1);
Expand All @@ -23,7 +23,7 @@ describe('DefaultServiceRegistry', () => {
test('should work with two languages', () => {
const language1: LangiumCoreServices = { LanguageMetaData: { fileExtensions: ['.foo'] } } as any;
const language2: LangiumCoreServices = { LanguageMetaData: { fileExtensions: ['.bar'] } } as any;
const registry = new DefaultServiceRegistry();
const registry = new CoreServiceRegistry();
registry.register(language1);
registry.register(language2);
expect(registry.getServices(URI.parse('file:/test.foo'))).toBe(language1);
Expand Down

0 comments on commit 5950b8e

Please sign in to comment.