Skip to content

Use wildignore when completing files #74

Description

@gi1242

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions