Skip to content
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

Use wildignore when completing files #74

Open
gi1242 opened this issue Dec 13, 2023 · 0 comments
Open

Use wildignore when completing files #74

gi1242 opened this issue Dec 13, 2023 · 0 comments

Comments

@gi1242
Copy link

gi1242 commented Dec 13, 2023

Here's a patch to use wildignore when completing files. (This way log files / other outputs wont clutter the completion menu).

diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua
index 4e63d27..62f1e5e 100644
--- a/lua/cmp_path/init.lua
+++ b/lua/cmp_path/init.lua
@@ -121,11 +121,26 @@ source._candidates = function(_, dirname, include_hidden, option, callback)
 
   local items = {}
 
+  -- 2023-12-12 gi1242: Partially convert glob patters to lua patterns
+  local wildignore = {}
+  for k, v in pairs( vim.opt.wildignore:get() ) do
+    wildignore[k] = v:gsub( '\\.', '\\.' ):gsub( '*', '.*' )
+  end
+  vim.print(wildignore)
+
+
   local function create_item(name, fs_type)
     if not (include_hidden or string.sub(name, 1, 1) ~= '.') then
       return
     end
 
+    -- 2023-12-12 gi1242: Ignore paths matching wildignore
+    for k, v in pairs( wildignore ) do
+      if name:find(v) then
+	return
+      end
+    end
+
     local path = dirname .. '/' .. name
     local stat = vim.loop.fs_stat(path)
     local lstat = nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant