Skip to content

feat: add option to have a slim file header #262

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions lua/gp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ local config = {
chat_assistant_prefix = { "🤖:", "[{{agent}}]" },
-- The banner shown at the top of each chat file.
chat_template = require("gp.defaults").chat_template,
slim_template_header = true,
-- if you want more real estate in your chat files and don't need the helper text
-- chat_template = require("gp.defaults").short_chat_template,
-- chat topic generation prompt
chat_topic_gen_prompt = "Summarize the topic of our conversation above"
.. " in two or three words. Respond only with those words.",
.. " in two or three words. Respond only with those words.",
-- chat topic model (string with model name or table with model name and parameters)
-- explicitly confirm deletion of a chat file
chat_confirm_delete = true,
Expand Down Expand Up @@ -378,16 +379,16 @@ local config = {

-- templates
template_selection = "I have the following from {{filename}}:"
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}",
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}",
template_rewrite = "I have the following from {{filename}}:"
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}"
.. "\n\nRespond exclusively with the snippet that should replace the selection above.",
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}"
.. "\n\nRespond exclusively with the snippet that should replace the selection above.",
template_append = "I have the following from {{filename}}:"
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}"
.. "\n\nRespond exclusively with the snippet that should be appended after the selection above.",
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}"
.. "\n\nRespond exclusively with the snippet that should be appended after the selection above.",
template_prepend = "I have the following from {{filename}}:"
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}"
.. "\n\nRespond exclusively with the snippet that should be prepended before the selection above.",
.. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}"
.. "\n\nRespond exclusively with the snippet that should be prepended before the selection above.",
template_command = "{{command}}",

-- https://platform.openai.com/docs/guides/speech-to-text/quickstart
Expand Down Expand Up @@ -569,9 +570,9 @@ local config = {
-- GpImplement rewrites the provided selection/range based on comments in it
Implement = function(gp, params)
local template = "Having following from {{filename}}:\n\n"
.. "```{{filetype}}\n{{selection}}\n```\n\n"
.. "Please rewrite this according to the contained instructions."
.. "\n\nRespond exclusively with the snippet that should replace the selection above."
.. "```{{filetype}}\n{{selection}}\n```\n\n"
.. "Please rewrite this according to the contained instructions."
.. "\n\nRespond exclusively with the snippet that should replace the selection above."

local agent = gp.get_command_agent()
gp.logger.info("Implementing selection with agent: " .. agent.name)
Expand All @@ -582,7 +583,7 @@ local config = {
agent,
template,
nil, -- command will run directly without any prompting for user input
nil -- no predefined instructions (e.g. speech-to-text from Whisper)
nil -- no predefined instructions (e.g. speech-to-text from Whisper)
)
end,

Expand Down
78 changes: 41 additions & 37 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
local config = require("gp.config")

local M = {
_Name = "Gp", -- plugin name
_state = {}, -- table of state variables
agents = {}, -- table of agents
cmd = {}, -- default command functions
config = {}, -- config variables
hooks = {}, -- user defined command functions
defaults = require("gp.defaults"), -- some useful defaults
_Name = "Gp", -- plugin name
_state = {}, -- table of state variables
agents = {}, -- table of agents
cmd = {}, -- default command functions
config = {}, -- config variables
hooks = {}, -- user defined command functions
defaults = require("gp.defaults"), -- some useful defaults
deprecator = require("gp.deprecator"), -- handle deprecated options
dispatcher = require("gp.dispatcher"), -- handle communication with LLM providers
helpers = require("gp.helper"), -- helper functions
imager = require("gp.imager"), -- image generation module
logger = require("gp.logger"), -- logger module
render = require("gp.render"), -- render module
spinner = require("gp.spinner"), -- spinner module
tasker = require("gp.tasker"), -- tasker module
vault = require("gp.vault"), -- handles secrets
whisper = require("gp.whisper"), -- whisper module
helpers = require("gp.helper"), -- helper functions
imager = require("gp.imager"), -- image generation module
logger = require("gp.logger"), -- logger module
render = require("gp.render"), -- render module
spinner = require("gp.spinner"), -- spinner module
tasker = require("gp.tasker"), -- tasker module
vault = require("gp.vault"), -- handles secrets
whisper = require("gp.whisper"), -- whisper module
}

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -137,11 +137,11 @@ M.setup = function(opts)
elseif not agent.model or not agent.system_prompt then
M.logger.warning(
"Agent "
.. name
.. " is missing model or system_prompt\n"
.. "If you want to disable an agent, use: { name = '"
.. name
.. "', disable = true },"
.. name
.. " is missing model or system_prompt\n"
.. "If you want to disable an agent, use: { name = '"
.. name
.. "', disable = true },"
)
M.agents[name] = nil
end
Expand Down Expand Up @@ -282,9 +282,9 @@ end

M.Target = {
rewrite = 0, -- for replacing the selection, range or the current line
append = 1, -- for appending after the selection, range or the current line
append = 1, -- for appending after the selection, range or the current line
prepend = 2, -- for prepending before the selection, range or the current line
popup = 3, -- for writing into the popup window
popup = 3, -- for writing into the popup window

-- for writing into a new buffer
---@param filetype nil | string # nil = same as the original buffer
Expand Down Expand Up @@ -378,22 +378,22 @@ M._toggle = {}

M._toggle_kind = {
unknown = 0, -- unknown toggle
chat = 1, -- chat toggle
popup = 2, -- popup toggle
chat = 1, -- chat toggle
popup = 2, -- popup toggle
context = 3, -- context toggle
}

---@param kind number # kind of toggle
---@return boolean # true if toggle was closed
M._toggle_close = function(kind)
if
M._toggle[kind]
and M._toggle[kind].win
and M._toggle[kind].buf
and M._toggle[kind].close
and vim.api.nvim_win_is_valid(M._toggle[kind].win)
and vim.api.nvim_buf_is_valid(M._toggle[kind].buf)
and vim.api.nvim_win_get_buf(M._toggle[kind].win) == M._toggle[kind].buf
M._toggle[kind]
and M._toggle[kind].win
and M._toggle[kind].buf
and M._toggle[kind].close
and vim.api.nvim_win_is_valid(M._toggle[kind].win)
and vim.api.nvim_buf_is_valid(M._toggle[kind].buf)
and vim.api.nvim_win_get_buf(M._toggle[kind].win) == M._toggle[kind].buf
then
if #vim.api.nvim_list_wins() == 1 then
M.logger.warning("Can't close the last window.")
Expand Down Expand Up @@ -473,7 +473,11 @@ M.not_chat = function(buf, file_name)
end
end
if not header_found then
return "missing file header"
if M.config.slim_template_header then
return nil
else
return "missing file header"
end
end

return nil
Expand Down Expand Up @@ -609,10 +613,10 @@ end

M.BufTarget = {
current = 0, -- current window
popup = 1, -- popup window
split = 2, -- split window
vsplit = 3, -- vsplit window
tabnew = 4, -- new tab
popup = 1, -- popup window
split = 2, -- split window
vsplit = 3, -- vsplit window
tabnew = 4, -- new tab
}

---@param params table | string # table with args or string args
Expand Down Expand Up @@ -1233,7 +1237,7 @@ M.cmd.ChatFinder = function()
local command_buf, command_win, command_close, command_resize = M.render.popup(
nil,
"Search: <Tab>/<Shift+Tab>|navigate <Esc>|picker <C-c>|exit "
.. "<Enter>/<C-f>/<C-x>/<C-v>/<C-t>/<C-g>t|open/float/split/vsplit/tab/toggle",
.. "<Enter>/<C-f>/<C-x>/<C-v>/<C-t>/<C-g>t|open/float/split/vsplit/tab/toggle",
function(w, h)
return w - left - right, 1, h - bottom, left
end,
Expand Down