feat (repo-map) configuration option for repo map ignore patterns ()

This commit is contained in:
Christopher Brewin 2024-11-12 02:56:20 +10:00 committed by GitHub
parent deb96e6b00
commit deb3b03826
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

@ -209,6 +209,10 @@ M.defaults = {
hints = { hints = {
enabled = true, enabled = true,
}, },
--- @class AvanteRepoMapConfig
repo_map = {
ignore_patterns = { "%.git", "%.worktree", "__pycache__", "node_modules" }, -- ignore files matching these
},
} }
---@type avante.Config ---@type avante.Config

@ -1,6 +1,7 @@
local Popup = require("nui.popup") local Popup = require("nui.popup")
local Utils = require("avante.utils") local Utils = require("avante.utils")
local event = require("nui.utils.autocmd").event local event = require("nui.utils.autocmd").event
local Config = require("avante.config")
local fn = vim.fn local fn = vim.fn
local filetype_map = { local filetype_map = {
@ -47,7 +48,9 @@ end
function RepoMap._build_repo_map(project_root, file_ext) function RepoMap._build_repo_map(project_root, file_ext)
local output = {} local output = {}
local gitignore_path = project_root .. "/.gitignore" local gitignore_path = project_root .. "/.gitignore"
local ignore_patterns, negate_patterns = Utils.parse_gitignore(gitignore_path) local gitignore_patterns, negate_patterns = Utils.parse_gitignore(gitignore_path)
local ignore_patterns = vim.list_extend(gitignore_patterns, Config.repo_map.ignore_patterns)
local filepaths = Utils.scan_directory(project_root, ignore_patterns, negate_patterns) local filepaths = Utils.scan_directory(project_root, ignore_patterns, negate_patterns)
vim.iter(filepaths):each(function(filepath) vim.iter(filepaths):each(function(filepath)
if not Utils.is_same_file_ext(file_ext, filepath) then return end if not Utils.is_same_file_ext(file_ext, filepath) then return end

@ -583,7 +583,7 @@ local function pattern_to_lua(pattern)
end end
function M.parse_gitignore(gitignore_path) function M.parse_gitignore(gitignore_path)
local ignore_patterns = { "%.git", "%.worktree", "__pycache__", "node_modules", "vendor" } local ignore_patterns = {}
local negate_patterns = {} local negate_patterns = {}
local file = io.open(gitignore_path, "r") local file = io.open(gitignore_path, "r")
if not file then return ignore_patterns, negate_patterns end if not file then return ignore_patterns, negate_patterns end