/**
 * Language Plugin Registry
 *
 * Manages registration and lookup of language plugins.
 */
/**
 * Default language registry implementation
 */
class DefaultLanguageRegistry {
    plugins = new Map();
    extensionMap = new Map();
    register(plugin) {
        this.plugins.set(plugin.id, plugin);
        // Map extensions to plugin
        for (const ext of plugin.extensions) {
            const normalizedExt = ext.startsWith('.') ? ext : `.${ext}`;
            this.extensionMap.set(normalizedExt, plugin);
        }
    }
    get(language) {
        return this.plugins.get(language);
    }
    getForFile(filePath) {
        // Extract extension
        const lastDot = filePath.lastIndexOf('.');
        if (lastDot === -1)
            return undefined;
        const ext = filePath.substring(lastDot).toLowerCase();
        return this.extensionMap.get(ext);
    }
    getAll() {
        return Array.from(this.plugins.values());
    }
    getSupportedLanguages() {
        return Array.from(this.plugins.keys());
    }
}
// Singleton registry instance
let globalRegistry = null;
/**
 * Get the global language registry
 */
export function getLanguageRegistry() {
    if (!globalRegistry) {
        globalRegistry = new DefaultLanguageRegistry();
    }
    return globalRegistry;
}
/**
 * Register a language plugin in the global registry
 */
export function registerLanguage(plugin) {
    getLanguageRegistry().register(plugin);
}
/**
 * Get a language plugin by language ID
 */
export function getLanguagePlugin(language) {
    return getLanguageRegistry().get(language);
}
/**
 * Get a language plugin for a file path
 */
export function getLanguageForFile(filePath) {
    return getLanguageRegistry().getForFile(filePath);
}
/**
 * Detect language from file path
 */
export function detectLanguage(filePath) {
    const plugin = getLanguageForFile(filePath);
    return plugin?.id;
}
/**
 * Check if a language is supported
 */
export function isLanguageSupported(language) {
    return getLanguageRegistry().getSupportedLanguages().includes(language);
}
//# sourceMappingURL=registry.js.map