From d222a3b94e54af4650f22a4cb6412fad9aedb13b Mon Sep 17 00:00:00 2001 From: skyfire Date: Fri, 15 Sep 2023 23:08:58 +0800 Subject: [PATCH] Add Some Prompt Command --- plugin/neoai.lua | 135 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 29 deletions(-) diff --git a/plugin/neoai.lua b/plugin/neoai.lua index 48c6f37..79cf48a 100644 --- a/plugin/neoai.lua +++ b/plugin/neoai.lua @@ -1,75 +1,75 @@ -- Plain GUI vim.api.nvim_create_user_command("NeoAI", function(opts) - require("neoai").smart_toggle(opts.args) + require("neoai").smart_toggle(opts.args) end, { - nargs = "*", +nargs = "*", }) vim.api.nvim_create_user_command("NeoAIToggle", function(opts) - require("neoai").toggle(opts.args) + require("neoai").toggle(opts.args) end, { - nargs = "*", +nargs = "*", }) vim.api.nvim_create_user_command("NeoAIOpen", function(opts) - require("neoai").toggle(true, opts.args) + require("neoai").toggle(true, opts.args) end, { - nargs = "*", +nargs = "*", }) vim.api.nvim_create_user_command("NeoAIClose", function() - require("neoai").toggle(false) + require("neoai").toggle(false) end, {}) -- Context GUI vim.api.nvim_create_user_command("NeoAIContext", function(opts) - require("neoai").context_smart_toggle(opts.args, opts.line1, opts.line2) + require("neoai").context_smart_toggle(opts.args, opts.line1, opts.line2) end, { - range = "%", - nargs = "*", +range = "%", +nargs = "*", }) vim.api.nvim_create_user_command("NeoAIContextOpen", function(opts) - require("neoai").context_toggle(true, opts.args, opts.line1, opts.line2) + require("neoai").context_toggle(true, opts.args, opts.line1, opts.line2) end, { - range = "%", - nargs = "*", +range = "%", +nargs = "*", }) vim.api.nvim_create_user_command("NeoAIContextClose", function() - require("neoai").context_toggle(false, "", nil, nil) + require("neoai").context_toggle(false, "", nil, nil) end, {}) -- Inject Mode vim.api.nvim_create_user_command("NeoAIInject", function(opts) - require("neoai").inject(opts.args) + require("neoai").inject(opts.args) end, { - nargs = "+", +nargs = "+", }) vim.api.nvim_create_user_command("NeoAIInjectCode", function(opts) - local extract_code_snippets = require("neoai.utils").extract_code_snippets - require("neoai").inject(opts.args, extract_code_snippets) + local extract_code_snippets = require("neoai.utils").extract_code_snippets + require("neoai").inject(opts.args, extract_code_snippets) end, { - nargs = "+", +nargs = "+", }) vim.api.nvim_create_user_command("NeoAIInjectContext", function(opts) - require("neoai").context_inject(opts.args, nil, opts.line1, opts.line2) + require("neoai").context_inject(opts.args, nil, opts.line1, opts.line2) end, { - range = "%", - nargs = "+", +range = "%", +nargs = "+", }) vim.api.nvim_create_user_command("NeoAIInjectContextCode", function(opts) - local extract_code_snippets = require("neoai.utils").extract_code_snippets - require("neoai").context_inject(opts.args, extract_code_snippets, opts.line1, opts.line2) + local extract_code_snippets = require("neoai.utils").extract_code_snippets + require("neoai").context_inject(opts.args, extract_code_snippets, opts.line1, opts.line2) end, { - range = "%", - nargs = "+", +range = "%", +nargs = "+", }) vim.api.nvim_create_user_command("NeoAIShortcut", function (opts) @@ -87,7 +87,84 @@ vim.api.nvim_create_user_command("NeoAIShortcut", function (opts) end func() end, { - nargs = 1, - range = true, - complete = require("neoai.shortcuts").complete_shortcut +nargs = 1, +range = true, +complete = require("neoai.shortcuts").complete_shortcut }) + +-- Versions of the commands that use vim.ui.input for retrieving the prompt/context +-- Plain +vim.api.nvim_create_user_command("NeoAIPrompt", function(_) + vim.ui.input({ prompt = "Prompt: " }, function(text) + if text == nil or string.len(text) == 0 then return end + require("neoai").smart_toggle(text) + end) +end, { +nargs = 0, +}) + +-- Context +vim.api.nvim_create_user_command("NeoAIContextPrompt", function(opts) + vim.ui.input({ prompt = "Context: " }, function(text) + if text == nil or string.len(text) == 0 then return end + require("neoai").context_smart_toggle(text, opts.line1, opts.line2) + end) +end, { +nargs = 0, +range = "%", +}) + +-- Inject +vim.api.nvim_create_user_command( +"NeoAIInjectPrompt", +function(_) + vim.ui.input({ prompt = "Prompt: " }, function(text) + if text == nil or string.len(text) == 0 then return end + require("neoai").inject(text) + end) +end, +{ + nargs = 0, +} +) + +vim.api.nvim_create_user_command( +"NeoAIInjectCodePrompt", +function(_) + vim.ui.input({ prompt = "Prompt: " }, function(text) + if text == nil or string.len(text) == 0 then return end + require("neoai").inject(text, require('neoai.utils').extract_code_snippets) + end) +end, +{ + nargs = 0, +} +) + +vim.api.nvim_create_user_command( +"NeoAIInjectContextPrompt", +function(opts) + vim.ui.input({ prompt = "Context: " }, function(text) + if text == nil or string.len(text) == 0 then return end + require("neoai").context_inject(text, nil, opts.line1, opts.line2) + end) +end, +{ + range = "%", + nargs = 0, +} +) + +vim.api.nvim_create_user_command( +"NeoAIInjectContextCodePrompt", +function(opts) + vim.ui.input({ prompt = "Context: " }, function(text) + if text == nil or string.len(text) == 0 then return end + require("neoai").context_inject(text, require('neoai.utils').extract_code_snippets, opts.line1, opts.line2) + end) +end, +{ + range = "%", + nargs = 0, +} +)