Skip to content

Commit 61f56e8

Browse files
authored
chore: can output plugin version (#2715)
Co-authored-by: Oli Morris <[email protected]>
1 parent 2245532 commit 61f56e8

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

lua/codecompanion/init.lua

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ local log = require("codecompanion.utils.log")
44

55
local api = vim.api
66

7+
local _version
8+
79
-- Lazy load context_utils
810
local context_utils
911
local function get_context(bufnr, args)
@@ -342,11 +344,37 @@ CodeCompanion.has = function(feature)
342344
return features
343345
end
344346

347+
---Output the plugin version
348+
---@return string|nil
349+
CodeCompanion.version = function()
350+
if _version then
351+
return _version
352+
end
353+
354+
local ok, version = pcall(function()
355+
return require("codecompanion.utils.files")
356+
.read(
357+
vim.fs.joinpath(
358+
string.sub(debug.getinfo(1).source, 2, string.len("/lua/codecompanion/init.lua") * -1),
359+
"version.txt"
360+
)
361+
)
362+
:gsub("%s+", "")
363+
end)
364+
365+
if ok then
366+
_version = version
367+
return _version
368+
end
369+
370+
return nil
371+
end
372+
345373
---Handle adapter configuration merging
346374
---@param adapter_type string
347375
---@param opts table
348376
---@return nil
349-
local function handle_adapter_config(adapter_type, opts)
377+
local function adapter_config(adapter_type, opts)
350378
if opts and opts.adapters and opts.adapters[adapter_type] then
351379
if config.adapters[adapter_type].opts.show_presets then
352380
local adapters_util = require("codecompanion.utils.adapters")
@@ -367,8 +395,8 @@ CodeCompanion.setup = function(opts)
367395
-- Setup the plugin's config
368396
config.setup(opts)
369397

370-
handle_adapter_config("acp", opts)
371-
handle_adapter_config("http", opts)
398+
adapter_config("acp", opts)
399+
adapter_config("http", opts)
372400

373401
local cmds = require("codecompanion.commands")
374402
for _, cmd in ipairs(cmds) do

0 commit comments

Comments
 (0)