'use strict';

var grammarConfig = require('./languages/grammar-config.js');
var completionParserBuilder = require('./parser/completion-parser-builder.js');
var langiumParserBuilder = require('./parser/langium-parser-builder.js');
var tokenBuilder = require('./parser/token-builder.js');
var valueConverter = require('./parser/value-converter.js');
var linker = require('./references/linker.js');
var nameProvider = require('./references/name-provider.js');
var references = require('./references/references.js');
var scopeComputation = require('./references/scope-computation.js');
var scopeProvider = require('./references/scope-provider.js');
var jsonSerializer = require('./serializer/json-serializer.js');
var serviceRegistry = require('./service-registry.js');
var documentValidator = require('./validation/document-validator.js');
var validationRegistry = require('./validation/validation-registry.js');
var astDescriptions = require('./workspace/ast-descriptions.js');
var astNodeLocator = require('./workspace/ast-node-locator.js');
var configuration = require('./workspace/configuration.js');
var documentBuilder = require('./workspace/document-builder.js');
var documents = require('./workspace/documents.js');
var indexManager = require('./workspace/index-manager.js');
var workspaceManager = require('./workspace/workspace-manager.js');
var lexer = require('./parser/lexer.js');
var documentationProvider = require('./documentation/documentation-provider.js');
var commentProvider = require('./documentation/comment-provider.js');
var langiumParser = require('./parser/langium-parser.js');
var asyncParser = require('./parser/async-parser.js');
var workspaceLock = require('./workspace/workspace-lock.js');
var hydrator = require('./serializer/hydrator.js');

/******************************************************************************
 * Copyright 2021 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.
******************************************************************************/
/**
 * Creates a dependency injection module configuring the default core services.
 * This is a set of services that are dedicated to a specific language.
 */
function createDefaultCoreModule(context) {
    return {
        documentation: {
            CommentProvider: (services) => new commentProvider.DefaultCommentProvider(services),
            DocumentationProvider: (services) => new documentationProvider.JSDocDocumentationProvider(services)
        },
        parser: {
            AsyncParser: (services) => new asyncParser.DefaultAsyncParser(services),
            GrammarConfig: (services) => grammarConfig.createGrammarConfig(services),
            LangiumParser: (services) => langiumParserBuilder.createLangiumParser(services),
            CompletionParser: (services) => completionParserBuilder.createCompletionParser(services),
            ValueConverter: () => new valueConverter.DefaultValueConverter(),
            TokenBuilder: () => new tokenBuilder.DefaultTokenBuilder(),
            Lexer: (services) => new lexer.DefaultLexer(services),
            ParserErrorMessageProvider: () => new langiumParser.LangiumParserErrorMessageProvider(),
            LexerErrorMessageProvider: () => new lexer.DefaultLexerErrorMessageProvider()
        },
        workspace: {
            AstNodeLocator: () => new astNodeLocator.DefaultAstNodeLocator(),
            AstNodeDescriptionProvider: (services) => new astDescriptions.DefaultAstNodeDescriptionProvider(services),
            ReferenceDescriptionProvider: (services) => new astDescriptions.DefaultReferenceDescriptionProvider(services)
        },
        references: {
            Linker: (services) => new linker.DefaultLinker(services),
            NameProvider: () => new nameProvider.DefaultNameProvider(),
            ScopeProvider: (services) => new scopeProvider.DefaultScopeProvider(services),
            ScopeComputation: (services) => new scopeComputation.DefaultScopeComputation(services),
            References: (services) => new references.DefaultReferences(services)
        },
        serializer: {
            Hydrator: (services) => new hydrator.DefaultHydrator(services),
            JsonSerializer: (services) => new jsonSerializer.DefaultJsonSerializer(services)
        },
        validation: {
            DocumentValidator: (services) => new documentValidator.DefaultDocumentValidator(services),
            ValidationRegistry: (services) => new validationRegistry.ValidationRegistry(services)
        },
        shared: () => context.shared
    };
}
/**
 * Creates a dependency injection module configuring the default shared core services.
 * This is the set of services that are shared between multiple languages.
 */
function createDefaultSharedCoreModule(context) {
    return {
        ServiceRegistry: (services) => new serviceRegistry.DefaultServiceRegistry(services),
        workspace: {
            LangiumDocuments: (services) => new documents.DefaultLangiumDocuments(services),
            LangiumDocumentFactory: (services) => new documents.DefaultLangiumDocumentFactory(services),
            DocumentBuilder: (services) => new documentBuilder.DefaultDocumentBuilder(services),
            IndexManager: (services) => new indexManager.DefaultIndexManager(services),
            WorkspaceManager: (services) => new workspaceManager.DefaultWorkspaceManager(services),
            FileSystemProvider: (services) => context.fileSystemProvider(services),
            WorkspaceLock: () => new workspaceLock.DefaultWorkspaceLock(),
            ConfigurationProvider: (services) => new configuration.DefaultConfigurationProvider(services)
        }
    };
}

exports.createDefaultCoreModule = createDefaultCoreModule;
exports.createDefaultSharedCoreModule = createDefaultSharedCoreModule;
