Skip to content

Commit

Permalink
Complete commands
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Oct 30, 2024
1 parent 4d619c5 commit 030149f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lua/fittencode/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ local function reload_workspace_templates()
end
end

reload_builtin_templates()
-- reload_builtin_templates()

local function reload_conversation_types()
reload_builtin_templates()
Expand Down
47 changes: 41 additions & 6 deletions lua/fittencode/command.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
local Client = require('fittencode.client')

-- reload_templates
-- delete_all_chats
local Chat = require('fittencode.chat')
local Log = require('fittencode.log')

local commands = {
login = {
function()
execute = function()
local username = vim.fn.input('Username/Email/Phone(+CountryCode): ')
local password = vim.fn.inputsecret('Password: ')
Client.login(username, password)
end },
end
},
login3rd = {
function(source) Client.login3rd(source) end,
execute = function(source) Client.login3rd(source) end,
complete = Client.login_providers
},
start_chat = {
execute = function()
Chat.start_chat()
end
},
reload_templates = {
execute = function()
Chat.reload_templates()
end
},
delete_all_chats = {
execute = function()
Chat.delete_all_chats()
end
},
}

local function execute(input)
end

local function complete(arg_lead, cmd_line, cursor_pos)
local eles = vim.split(vim.trim(cmd_line), '%s+')
if cmd_line:sub(-1) == ' ' then
eles[#eles + 1] = ''
end
-- 1: FittenCode
table.remove(eles, 1)
-- action or nil
local prefix = table.remove(eles, 1) or ''
if #eles > 0 then
if commands[prefix] and commands[prefix].complete then
local next = table.remove(eles, 1) or ''
return vim.tbl_filter(function(key)
return key:find(next, 1, true) == 1
end, commands[prefix].complete)
end
else
return vim.tbl_filter(function(key)
return key:find(prefix, 1, true) == 1
end, vim.tbl_keys(commands))
end
end

vim.api.nvim_create_user_command('FittenCode', function(input)
Expand Down
2 changes: 1 addition & 1 deletion lua/fittencode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local M = {}
function M.setup(opts)
require('fittencode.config').setup(opts)
require('fittencode.client').load_last_session()
require('fittencode.chat')
require('fittencode.command')
end

return setmetatable(M, {
Expand Down

0 comments on commit 030149f

Please sign in to comment.