local Meta = require "cave.meta" local Python = require "cave.python" local Context = require "cave.context" local Map = Meta.Map local Optional = Meta.Optional local Str = Meta.String local validate = Meta.validate local Table = Meta.Table ---@class cave.Config ---@field python_interpreters table local Config = Meta.derive "Config" ---@return overseer.TemplateDefinition[] function Config:templates() local templates = {} for _, python_interpreter in pairs(self.python_interpreters) do vim.list_extend(templates, python_interpreter:templates()) end return templates end ---@class cave.Config.Factory : cave.Context ---@field python_interpreters_ cave.Python.Interpreter.Factory[] ---@field context_ cave.Context local Factory = Meta.derive("Config.Factory", Context) function Factory:init(context) Context.init(self, context.dir, context.name, context.uuid) self.python_interpreters_ = {} self.context_ = context end ---@param context cave.Context ---@return cave.Config.Factory function Factory.new(context) validate { context = { context, Context } } local factory = setmetatable({}, Factory) factory:init(context) return factory end ---@return cave.Python.Interpreter.Factory[] function Factory:get_python_interpreters() return self.python_interpreters_ end ---@return cave.Python.Interpreter.Factory function Factory:python() local python_interpreter = Python.Interpreter.Factory.new(self.context_) table.insert(self.python_interpreters_, python_interpreter) return python_interpreter end ---@param config cave.Config function Factory:init_config(config) config.python_interpreters = {} for _, python_interpreter_factory in pairs(self:get_python_interpreters()) do local python_interpreter = python_interpreter_factory:build() assert(config.python_interpreters[python_interpreter.id] == nil) config.python_interpreters[python_interpreter.id] = python_interpreter end end ---@return cave.Config function Factory:build() local config = setmetatable({}, Config) self:init_config(config) return config end ---@alias cave.Config.Builder fun(config: cave.Config.Factory) Config.Factory = Factory return Config