-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
130 lines (118 loc) · 4.15 KB
/
init.lua
File metadata and controls
130 lines (118 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
local M = {}
-- Imports
local ask = require("llmnvim.ask")
local chat = require("llmnvim.chat")
local logs = require("llmnvim.logs")
local model_selector = require("llmnvim.model_selector")
local fragments = require("llmnvim.wip_fragments")
local tabcomplete = require("llmnvim.tabcomplete")
-- Default configuration
M.config = {
no_stream = false,
key = nil,
system_prompt = nil,
template = nil,
continue_conversation = false,
conversation_id = nil,
params = {},
options = {},
window = {
type = "sidebar", -- "sidebar", "float", or "bottom"
sidebar = {
side = "right", -- "left" or "right"
width = 0.3, -- 30% of editor width
min_width = 40, -- Minimum 40 columns
},
bottom = {
height = 0.3, -- 30% of editor height
min_height = 15, -- Minimum 15 lines
},
float = {
border = "rounded",
width = 80,
height = 20,
title = "LLM Chat",
},
},
}
-- Utility function to create a window based on config
function M.create_window(buf, title)
local cfg = M.config.window
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
if cfg.type == "sidebar" then
local width = math.max(math.floor(vim.o.columns * cfg.sidebar.width), cfg.sidebar.min_width)
local cmd = cfg.sidebar.side == "left" and "topleft vsplit" or "botright vsplit"
vim.cmd(cmd)
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_win_set_width(win, width)
vim.api.nvim_win_set_option(win, "wrap", false)
vim.api.nvim_win_set_option(win, "cursorline", true)
return win
elseif cfg.type == "bottom" then
local height = math.max(math.floor(vim.o.lines * cfg.bottom.height), cfg.bottom.min_height)
vim.cmd("botright split")
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_win_set_height(win, height)
vim.api.nvim_win_set_option(win, "wrap", false)
vim.api.nvim_win_set_option(win, "cursorline", true)
return win
else
-- Float window for backward compatibility
local width = math.max(math.floor(vim.o.columns * 0.8), cfg.float.width)
local height = math.floor(vim.o.lines * 0.7)
local row = math.floor((vim.o.lines - height) / 2)
local col = math.floor((vim.o.columns - width) / 3)
return vim.api.nvim_open_win(buf, true, {
relative = "editor",
width = width,
height = height,
row = row,
col = col,
border = cfg.float.border,
title = title or cfg.float.title,
title_pos = "center",
})
end
end
-- Setup function
function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
end
-- Functions
function M.start_model_selector()
model_selector.start_model_selector(M.config)
end
function M.start_chat()
chat.start_chat(M.config)
end
function M.start_fragments()
fragments.start_fragments_manager(M.config)
end
function M.start_ask()
ask.start_ask(M.config)
end
function M.start_logs()
logs.start_logs(M.config)
end
function M.toggle_tabcomplete()
tabcomplete.toggle(M.config)
if not M.config.tabcomplete then
M.config.tabcomplete = { enabled = false, debug = true }
end
M.config.tabcomplete.enabled = tabcomplete.is_enabled()
end
-- Commands
vim.api.nvim_create_user_command("LLMAsk", M.start_ask, { desc = "Open LLM ask window" })
vim.api.nvim_create_user_command("LLMChat", M.start_chat, { desc = "Open LLM chat window" })
vim.api.nvim_create_user_command("LLMLogs", M.start_logs, { desc = "Open LLM log window" })
vim.api.nvim_create_user_command("LLMSelectModel", M.start_model_selector, { desc = "Open LLM model selector window" })
vim.api.nvim_create_user_command("LLMTabComplete", M.toggle_tabcomplete, { desc = "Toggle LLM tab completion" })
-- Keybindings
vim.keymap.set("n", "<leader>aa", "<cmd>LLMAsk<cr>", { desc = "Open LLM Ask" })
vim.keymap.set("n", "<leader>ac", "<cmd>LLMChat<cr>", { desc = "Open LLM Chat" })
vim.keymap.set("n", "<leader>al", "<cmd>LLMLogs<cr>", { desc = "Open LLM Log" })
vim.keymap.set("n", "<leader>am", "<cmd>LLMSelectModel<cr>", { desc = "Select LLM Model" })
vim.keymap.set("n", "<leader>at", "<cmd>LLMTabComplete<cr>", { desc = "Toggle LLM Tab Complete" })
return M