From 76dd7822989caf2c1eab2da21803da204b91363d Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Thu, 19 May 2022 08:47:52 -0700 Subject: [PATCH 1/2] Added support for windows path pattern (only forward slash) --- lua/cmp_path/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua index 74f70ed..9f476d0 100644 --- a/lua/cmp_path/init.lua +++ b/lua/cmp_path/init.lua @@ -9,6 +9,9 @@ local constants = { max_lines = 20, } +-- Heuristic to detect if running on windows and _not_ wsl +local is_windows = vim.fn.has("windows") and not vim.fn.has("unix") + ---@class cmp_path.Options ---@field public trailing_slash boolean @@ -89,7 +92,7 @@ source._dirname = function(self, params, opts) return vim.fn.resolve(env_var_value .. '/' .. dirname) end end - if prefix:match('/$') then + if prefix:match('/$') or (is_windows and prefix:match('%a://')) then local accept = true -- Ignore URL components accept = accept and not prefix:match('%a/$') From 1bc2d2eff6c501ed6a7a01ffd401bbf2a0b416f3 Mon Sep 17 00:00:00 2001 From: Harshad Srinivasan Date: Thu, 19 May 2022 11:57:37 -0700 Subject: [PATCH 2/2] Url vs drive letter detection --- lua/cmp_path/init.lua | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua index 9f476d0..52eff43 100644 --- a/lua/cmp_path/init.lua +++ b/lua/cmp_path/init.lua @@ -9,9 +9,7 @@ local constants = { max_lines = 20, } --- Heuristic to detect if running on windows and _not_ wsl -local is_windows = vim.fn.has("windows") and not vim.fn.has("unix") - +local is_windows = (vim.fn.has("windows") == 1) and (vim.fn.has("unix") == 0) ---@class cmp_path.Options ---@field public trailing_slash boolean @@ -63,6 +61,20 @@ source.complete = function(self, params, callback) end) end + +local function is_url(prefix) + + scheme = prefix:match('%a+://$') + + -- Handle special case of drive letters on windows + if (is_windows and scheme and string.len(scheme) == 4) then + return false + end + + return scheme or prefix:match('%a+:/$') + +end + source._dirname = function(self, params, opts) local s = PATH_REGEX:match_str(params.context.cursor_before_line) if not s then @@ -92,12 +104,21 @@ source._dirname = function(self, params, opts) return vim.fn.resolve(env_var_value .. '/' .. dirname) end end - if prefix:match('/$') or (is_windows and prefix:match('%a://')) then + + if is_windows then + start = prefix:match('%a://$') + end + + if not start then + start = prefix:match('/$') + end + + if start then local accept = true -- Ignore URL components accept = accept and not prefix:match('%a/$') -- Ignore URL scheme - accept = accept and not prefix:match('%a+:/$') and not prefix:match('%a+://$') + accept = accept and not is_url(prefix) -- Ignore HTML closing tags accept = accept and not prefix:match('