Skip to content

Commit 768fc89

Browse files
authored
feat(editing-support): add amp.nvim (#1675)
1 parent 6675261 commit 768fc89

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# amp.nvim
2+
3+
This plugin allows the [Amp CLI](https://ampcode.com/manual#cli) to see the file you currently have open in your Neovim instance, along with your cursor position and your text selection.
4+
5+
**Repository**: <https://github.com/sourcegraph/amp.nvim>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
return {
2+
"sourcegraph/amp.nvim",
3+
branch = "main",
4+
lazy = false,
5+
opts = { auto_start = true, log_level = "info" },
6+
dependencies = {
7+
{
8+
"AstroNvim/astrocore",
9+
opts = {
10+
commands = {
11+
AmpSend = {
12+
function(event)
13+
local message = event.args
14+
if message == "" then
15+
print "Please provide a message to send"
16+
return
17+
end
18+
require("amp.message").send_message(message)
19+
end,
20+
nargs = "*",
21+
desc = "Send a message to Amp",
22+
},
23+
AmpSendBuffer = {
24+
function()
25+
local buf = vim.api.nvim_get_current_buf()
26+
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
27+
local content = table.concat(lines, "\n")
28+
require("amp.message").send_message(content)
29+
end,
30+
desc = "Send current buffer contents to Amp",
31+
},
32+
AmpPromptSelection = {
33+
function(event)
34+
local lines = vim.api.nvim_buf_get_lines(0, event.line1 - 1, event.line2, false)
35+
local text = table.concat(lines, "\n")
36+
require("amp.message").send_to_prompt(text)
37+
end,
38+
range = true,
39+
desc = "Add selected text to Amp prompt",
40+
},
41+
AmpPromptRef = {
42+
function(event)
43+
local bufname = vim.api.nvim_buf_get_name(0)
44+
if bufname == "" then
45+
print "Current buffer has no filename"
46+
return
47+
end
48+
local relative_path = vim.fn.fnamemodify(bufname, ":.")
49+
local ref = "@" .. relative_path
50+
if event.line1 ~= event.line2 then
51+
ref = ref .. "#L" .. event.line1 .. "-" .. event.line2
52+
elseif event.line1 > 1 then
53+
ref = ref .. "#L" .. event.line1
54+
end
55+
require("amp.message").send_to_prompt(ref)
56+
end,
57+
range = true,
58+
desc = "Add file reference (with selection) to Amp prompt",
59+
},
60+
},
61+
},
62+
},
63+
},
64+
}

0 commit comments

Comments
 (0)