blink.cmp icon indicating copy to clipboard operation
blink.cmp copied to clipboard

Path source: path completion not working on Windows

Open marovira opened this issue 1 year ago • 2 comments

Make sure you have done the following

  • [X] I have updated to the latest version of blink.cmp
  • [X] I have read the README

Bug Description

In Windows, path completion doesn't work when a path starts with a drive letter, e.g. C:/. To reproduce:

  • Open nvim on an empty buffer in Windows.
  • Enter C:/ and see that no path completion sources are shown.

Note: behaviour is the same if C:\ is used instead.

Using nvim-cmp with cmp-async-path works correctly as shown below image

And this is blink: image

Relevant configuration

{
        "saghen/blink.cmp",
        lazy = false,
        dependencies = {
            { "saghen/blink.compat", lazy = true, config = true },
            { "f3fora/cmp-spell" },
            { "hrsh7th/cmp-omni" },
        },
        version = "v0.*",
        opts = {
            keymap = {
                preset = "enter",
                ["<Tab>"] = { "select_next", "fallback" },
                ["<S-Tab>"] = { "select_prev", "fallback" },
            },
            completion = {
                list = {
                    selection = "auto_insert",
                },
                documentation = { auto_show = true },
            },
            signature = { enabled = true },
            sources = {
                completion = {
                    enabled_providers = { "lsp", "path", "buffer" },
                },
            },
        },
    },

neovim version

NVIM v0.10.2

blink.cmp version: branch, tag, or commit

v0.76

marovira avatar Dec 17 '24 05:12 marovira

I'm on Linux so if someone on Windows could take a look at this, it'd be much appreciated

saghen avatar Dec 17 '24 18:12 saghen

diff --git a/lua/blink/cmp/sources/path/lib.lua b/lua/blink/cmp/sources/path/lib.lua
index a54c257..8f5f0da 100644
--- a/lua/blink/cmp/sources/path/lib.lua
+++ b/lua/blink/cmp/sources/path/lib.lua
@@ -40,6 +40,10 @@ function lib.dirname(path_regex, get_cwd, context)
     accept = accept and (not prefix:match('^[%s/]*$') or not lib.is_slash_comment())    
     if accept then return vim.fn.resolve('/' .. dirname) end
   end
+  local driver = prefix:match('(%a:)[/\\]$')
+  if driver then
+    return vim.fn.resolve(driver .. '/' .. dirname)
+  end
   return nil
 end

https://codeberg.org/FelipeLema/cmp-async-path/src/commit/d6d1ffa2075039632a2d71e8fa139818e15ac757/lua/cmp_async_path/init.lua#L196

bstaint avatar Dec 18 '24 08:12 bstaint