UNPKG

greybel-languageserver-core

Version:
122 lines 5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoreContext = void 0; const events_1 = __importDefault(require("events")); const types_1 = require("./types"); const semantic_token_builder_1 = require("./helper/semantic-token-builder"); function createConfig(preset) { return { fileExtensions: preset?.fileExtensions ? preset.fileExtensions.split(',') : types_1.DefaultFileExtensions, formatter: preset?.formatter ?? true, autocomplete: preset?.autocomplete ?? true, hoverdocs: preset?.hoverdocs ?? true, diagnostic: preset?.diagnostic ?? true, transpiler: { beautify: { keepParentheses: preset?.transpiler?.beautify?.keepParentheses ?? true, indentation: preset?.transpiler?.beautify?.indentation ?? types_1.IndentationType.Tab, indentationSpaces: preset?.transpiler?.beautify?.indentationSpaces ?? 2 } }, typeAnalyzer: { strategy: preset?.typeAnalyzer?.strategy ?? types_1.TypeAnalyzerStrategy.Dependency, exclude: preset?.typeAnalyzer?.exclude ?? undefined } }; } class CoreContext extends events_1.default { constructor() { super(); this._configuration = createConfig(); this._features = { configuration: false, workspaceFolder: false }; } get features() { return this._features; } getConfiguration() { return this._configuration; } async syncConfiguraton() { const configuration = await this.connection.workspace.getConfiguration(types_1.ConfigurationNamespace); const newConfiguration = createConfig(configuration); // check for analyzer changes to clear type analyzer cache const newTypeAnalyzerConfig = newConfiguration.typeAnalyzer; const oldTypeAnalyzerConfig = this._configuration.typeAnalyzer; if (newTypeAnalyzerConfig.strategy !== oldTypeAnalyzerConfig.strategy || newTypeAnalyzerConfig.exclude !== oldTypeAnalyzerConfig.exclude) { this.documentMerger.cache.flushCache(); } this._configuration = newConfiguration; } configureCapabilties(capabilities) { this._features.configuration = !!(capabilities.workspace && !!capabilities.workspace.configuration); this._features.workspaceFolder = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders); } async onInitialize(params) { this.configureCapabilties(params.capabilities); const result = { capabilities: { completionProvider: { triggerCharacters: ['.'], resolveProvider: true }, hoverProvider: true, colorProvider: true, definitionProvider: true, foldingRangeProvider: true, documentFormattingProvider: true, signatureHelpProvider: { triggerCharacters: [',', '('] }, documentSymbolProvider: true, workspaceSymbolProvider: true, diagnosticProvider: { identifier: types_1.LanguageId, interFileDependencies: false, workspaceDiagnostics: false }, semanticTokensProvider: { legend: { tokenTypes: semantic_token_builder_1.semanticTokensLegend.tokenTypes, tokenModifiers: semantic_token_builder_1.semanticTokensLegend.tokenModifiers, }, full: true }, textDocumentSync: 2 // incremental } }; if (this._features.workspaceFolder) { result.capabilities.workspace = { workspaceFolders: { supported: true } }; } this.emit('ready', this); return result; } async onInitialized(_params) { if (this._features.configuration) { await this.syncConfiguraton(); this.connection.onDidChangeConfiguration(async () => { const oldConfiguration = this._configuration; await this.syncConfiguraton(); this.emit('configuration-change', this, this._configuration, oldConfiguration); }); } this.emit('loaded', this); } async listen() { this.fs.listen(this.connection); this.connection.onInitialize(this.onInitialize.bind(this)); this.connection.onInitialized(this.onInitialized.bind(this)); this.connection.listen(); } } exports.CoreContext = CoreContext; //# sourceMappingURL=context.js.map