-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.lua
More file actions
96 lines (77 loc) · 2.41 KB
/
Copy pathactions.lua
File metadata and controls
96 lines (77 loc) · 2.41 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
-- lua/neopencode/actions.lua
local session = require("neopencode.session")
local api = require("neopencode.api")
local ui = require("neopencode.ui")
local M = {}
function M.send_file()
if not session.current_session then
M.log_error("No neopencode session selected. Please run :OpencodeSelectSession")
return
end
local file_path = vim.fn.expand("%:p")
if file_path == "" then
M.log_error("No file name.")
return
end
local filename = vim.fn.expand("%")
ui.input({
prompt = "Prompt for " .. filename,
default = "@" .. filename .. " ",
}, function(prompt)
if not prompt or prompt == "" then
return
end
api.send_chat(session.current_session.id, prompt)
end)
end
function M.send_selection(start_line, end_line)
if not session.current_session then
M.log_error("No neopencode session selected. Please run :OpencodeSelectSession")
return
end
local file_path = vim.fn.expand("%")
if file_path == "" then
M.log_error("No file name.")
return
end
local selected_lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
local selected_text = table.concat(selected_lines, "\n")
local prompt_text = "Prompt for " .. file_path .. " L" .. start_line .. ":L" .. end_line
local default_text = "@" .. file_path .. "\n" .. selected_text .. "\n\n"
ui.input({
prompt = prompt_text,
default = default_text,
}, function(prompt)
if not prompt or prompt == "" then
return
end
api.send_chat(session.current_session.id, prompt)
end)
end
function M.log_error(message)
local bufname = "neopencode.ai error"
local bufnr = vim.fn.bufnr(bufname)
-- If buffer doesn't exist, create it
if bufnr == -1 then
vim.cmd("new " .. bufname)
vim.api.nvim_buf_set_option(0, "bufhidden", "wipe")
vim.api.nvim_buf_set_option(0, "buftype", "nofile")
vim.api.nvim_buf_set_option(0, "swapfile", false)
bufnr = vim.api.nvim_get_current_buf()
end
-- Switch to the error buffer window if it's not open
local winid = vim.fn.bufwinid(bufnr)
if winid == -1 then
vim.cmd("sbuffer " .. bufnr)
else
vim.api.nvim_set_current_win(winid)
end
-- Append the error message
local lines = vim.fn.split(message, "\n")
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, lines)
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, { "---" }) -- Separator
end
function M.display_response(response)
-- Do nothing.
end
return M