-
-
Notifications
You must be signed in to change notification settings - Fork 146
feat(snacks): add snacks.picker action integration #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
37c46e8
de1f887
a89441e
2f1c55e
7f37200
f82831a
a671b07
17070e5
471d1cc
b364992
9a1ed55
527a0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ---@module 'snacks' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ---Snacks picker integration for opencode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ---@class opencode.integrations.picker.snacks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local M = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ---Send selected picker items to opencode prompt. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ---@param picker snacks.Picker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function M.opencode_send(picker) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local entries = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, item in ipairs(picker:selected({ fallback = true })) do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local entry = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if item.text and item.text ~= "" then -- Includes file reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entry = item.text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Append line numbers if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if item.file and item.pos then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local line_ref = ("L%d"):format(item.pos[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if item.end_pos and item.end_pos[1] ~= item.pos[1] then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line_ref = line_ref .. ("-L%d"):format(item.end_pos[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entry = entry .. " " .. line_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if entry ~= "" then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local entries = {} | |
| for _, item in ipairs(picker:selected({ fallback = true })) do | |
| local entry = "" | |
| if item.text and item.text ~= "" then -- Includes file reference | |
| entry = item.text | |
| end | |
| -- Append line numbers if available | |
| if item.file and item.pos then | |
| local line_ref = ("L%d"):format(item.pos[1]) | |
| if item.end_pos and item.end_pos[1] ~= item.pos[1] then | |
| line_ref = line_ref .. ("-L%d"):format(item.end_pos[1]) | |
| end | |
| entry = entry .. " " .. line_ref | |
| end | |
| if entry ~= "" then | |
| local Context = require("opencode.context").Context | |
| local entries = {} | |
| for _, item in ipairs(picker:selected({ fallback = true })) do | |
| local entry | |
| -- Prefer constructing a proper opencode context when file and position are available | |
| if item.file and item.pos then | |
| local start_line = item.pos[1] | |
| local start_col = item.pos[2] | |
| local ctx = Context.format({ | |
| path = item.file, | |
| start_line = start_line, | |
| start_col = start_col, | |
| }) | |
| if item.text and item.text ~= "" then | |
| entry = ctx .. " " .. item.text | |
| else | |
| entry = ctx | |
| end | |
| -- Fallback: no file info, just use the text if present | |
| elseif item.text and item.text ~= "" then | |
| entry = item.text | |
| end | |
| if entry and entry ~= "" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong because item.text is never empty in my experience. Tested on file picker, grep, diagnostics, etc.
Uh oh!
There was an error while loading. Please reload this page.