Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support netrw file selection#62

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
makotodejima wants to merge1 commit intocoder:main
base:main
Choose a base branch
Loading
frommakotodejima:feat/netrw-support
Open
Show file tree
Hide file tree
Changes fromall 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
4 changes: 2 additions & 2 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,7 @@ When Anthropic released Claude Code, they only supported VS Code and JetBrains.
"<leader>as",
"<cmd>ClaudeCodeTreeAdd<cr>",
desc = "Add file",
ft = { "NvimTree", "neo-tree", "oil" },
ft = { "NvimTree", "neo-tree", "oil", "netrw" },
},
-- Diff management
{ "<leader>aa", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
Expand DownExpand Up@@ -80,7 +80,7 @@ That's it! The plugin will auto-configure everything else.
1. **Launch Claude**: Run `:ClaudeCode` to open Claude in a split terminal
2. **Send context**:
- Select text in visual mode and use `<leader>as` to send it to Claude
- In `nvim-tree`/`neo-tree`/`oil.nvim`, press `<leader>as` on a file to add it to Claude's context
- In `nvim-tree`/`neo-tree`/`oil.nvim`/`netrw`, press `<leader>as` on a file to add it to Claude's context
3. **Let Claude work**: Claude can now:
- See your current file and selections in real-time
- Open files in your editor
Expand Down
2 changes: 1 addition & 1 deletiondev-config.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ return {
"<leader>as",
"<cmd>ClaudeCodeTreeAdd<cr>",
desc = "Add file from tree",
ft = { "NvimTree", "neo-tree", "oil" },
ft = { "NvimTree", "neo-tree", "oil", "netrw" },
},

-- Development helpers
Expand Down
1 change: 1 addition & 0 deletionslua/claudecode/diff.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,7 @@ local function find_main_editor_window()
or filetype == "ClaudeCode"
or filetype == "NvimTree"
or filetype == "oil"
or filetype == "netrw"
or filetype == "aerial"
or filetype == "tagbar"
)
Expand Down
1 change: 1 addition & 0 deletionslua/claudecode/init.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -611,6 +611,7 @@ function M._create_commands()
local is_tree_buffer = current_ft == "NvimTree"
or current_ft == "neo-tree"
or current_ft == "oil"
or current_ft == "netrw"
or string.match(current_bufname, "neo%-tree")
or string.match(current_bufname, "NvimTree")

Expand Down
52 changes: 52 additions & 0 deletionslua/claudecode/integrations.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,8 @@ function M.get_selected_files_from_tree()
return M._get_neotree_selection()
elseif current_ft == "oil" then
return M._get_oil_selection()
elseif current_ft == "netrw" then
return M._get_netrw_selection()
else
return nil, "Not in a supported tree buffer (current filetype: " .. current_ft .. ")"
end
Expand DownExpand Up@@ -261,4 +263,54 @@ function M._get_oil_selection()
return {}, "No file found under cursor"
end

--- Get selected files from netrw
--- Supports both marked files and single file under cursor
--- Reference: :help netrw-mf, :help markfilelist
--- @return table files List of file paths
--- @return string|nil error Error message if operation failed
function M._get_netrw_selection()
-- 1. Check for marked files
local mf_ok, mf_result = pcall(function()
if vim.fn.exists("*netrw#Expose") == 1 then
return vim.fn.call("netrw#Expose", { "netrwmarkfilelist" })
end
return nil
end)

local marked_files = {}

if mf_ok and mf_result and type(mf_result) == "table" and #mf_result > 0 then
for _, file_path in ipairs(mf_result) do
if vim.fn.filereadable(file_path) == 1 or vim.fn.isdirectory(file_path) == 1 then
table.insert(marked_files, file_path)
end
end
end

if #marked_files > 0 then
return marked_files, nil
end

-- 2. No marked files. Check for a file or dir under cursor
local path_ok, path_result = pcall(function()
if vim.fn.exists("*netrw#Call") == 1 then
local word = vim.fn.call("netrw#Call", { "NetrwGetWord" })
if word ~= "" then
return vim.fn.call("netrw#Call", { "NetrwFile", word })
end
end
return nil
end)

if not path_ok or not path_result or path_result == "" then
return {}, "Failed to get path from netrw"
end

if vim.fn.filereadable(path_result) == 1 or vim.fn.isdirectory(path_result) == 1 then
return { path_result }, nil
end

return {}, "Invalid file or directory path: " .. path_result
end

return M
1 change: 1 addition & 0 deletionslua/claudecode/tools/open_file.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,6 +76,7 @@ local function find_main_editor_window()
or filetype == "ClaudeCode"
or filetype == "NvimTree"
or filetype == "oil"
or filetype == "netrw"
or filetype == "aerial"
or filetype == "tagbar"
)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp