"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Settings = void 0;
const formatter_1 = require("@herb-tools/formatter");
class Settings {
    constructor(params, connection) {
        // The global settings, used when the `workspace/configuration` request is not supported by the client.
        // Please note that this is not the case when using this server with the client provided in this example
        // but could happen with other clients.
        this.defaultSettings = {
            formatter: {
                enabled: false,
                indentWidth: formatter_1.defaultFormatOptions.indentWidth,
                maxLineLength: formatter_1.defaultFormatOptions.maxLineLength
            }
        };
        this.globalSettings = this.defaultSettings;
        this.documentSettings = new Map();
        this.hasConfigurationCapability = false;
        this.hasWorkspaceFolderCapability = false;
        this.hasDiagnosticRelatedInformationCapability = false;
        this.params = params;
        this.capabilities = params.capabilities;
        this.connection = connection;
        // Does the client support the `workspace/configuration` request?
        // If not, we fall back using global settings.
        this.hasConfigurationCapability = !!(this.capabilities.workspace && !!this.capabilities.workspace.configuration);
        this.hasWorkspaceFolderCapability = !!(this.capabilities.workspace && !!this.capabilities.workspace.workspaceFolders);
        this.hasDiagnosticRelatedInformationCapability = !!(this.capabilities.textDocument &&
            this.capabilities.textDocument.publishDiagnostics &&
            this.capabilities.textDocument.publishDiagnostics.relatedInformation);
    }
    get projectPath() {
        var _a, _b;
        return ((_b = (_a = this.params.workspaceFolders) === null || _a === void 0 ? void 0 : _a.at(0)) === null || _b === void 0 ? void 0 : _b.uri) || "";
    }
    getDocumentSettings(resource) {
        if (!this.hasConfigurationCapability) {
            return Promise.resolve(this.globalSettings);
        }
        let result = this.documentSettings.get(resource);
        if (!result) {
            result = this.connection.workspace.getConfiguration({
                scopeUri: resource,
                section: "languageServerHerb",
            });
            this.documentSettings.set(resource, result);
        }
        return result;
    }
}
exports.Settings = Settings;
//# sourceMappingURL=settings.js.map