Skip to content

Commit

Permalink
feat: use commands from the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Feb 8, 2024
1 parent 3e1899f commit 456a670
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lua/codecompanion/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ M.toggle = function()
end

local _cached_actions = {}
M.actions = function()
M.actions = function(args)
local client = M.get_client()
if not client then
return
end

local actions = require("codecompanion.actions")
local context = util.get_context(vim.api.nvim_get_current_buf())
local context = util.get_context(vim.api.nvim_get_current_buf(), args)

local function picker(items, opts, callback)
opts = opts or {}
Expand Down
4 changes: 3 additions & 1 deletion lua/codecompanion/utils/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ end
function M.get_context(bufnr, args)
bufnr = bufnr or api.nvim_get_current_buf()
local winid = api.nvim_get_current_win()
local mode = vim.fn.mode()
local cursor_pos = api.nvim_win_get_cursor(api.nvim_get_current_win())

-- Detect if we've made a visual selection via the command line
local mode = vim.fn.visualmode() == "" and vim.fn.mode() or vim.fn.visualmode()

local lines, start_line, start_col, end_line, end_col = {}, cursor_pos[1], cursor_pos[2], cursor_pos[1], cursor_pos[2]

if (args and args.range > 0) or is_visual_mode(mode) then
Expand Down
10 changes: 5 additions & 5 deletions plugin/codecompanion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ local codecompanion = require("codecompanion")

vim.api.nvim_create_user_command("CodeCompanionChat", function(opts)
codecompanion.chat(opts)
end, { desc = "", range = true })
end, { desc = "Open a Code Companion chat buffer", range = true })

vim.api.nvim_create_user_command("CodeCompanionActions", function()
codecompanion.actions()
end, { desc = "", range = true })
vim.api.nvim_create_user_command("CodeCompanionActions", function(opts)
codecompanion.actions(opts)
end, { desc = "Open the Code Companion actions palette", range = true })

vim.api.nvim_create_user_command("CodeCompanionToggle", function()
codecompanion.toggle()
end, { desc = "" })
end, { desc = "Toggle a Code Companion chat buffer" })

vim.g.loaded_codecompanion = true

0 comments on commit 456a670

Please sign in to comment.