From 14e724ec0b8adab98d1ff09f305d887d616e4c3e Mon Sep 17 00:00:00 2001 From: IronLu233 Date: Fri, 13 Jan 2023 23:17:42 +0800 Subject: [PATCH 1/3] fix(command_resolver): fix resolve executable on Windows system --- lua/null-ls/helpers/command_resolver.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/null-ls/helpers/command_resolver.lua b/lua/null-ls/helpers/command_resolver.lua index 66af8dfad..386a9478f 100644 --- a/lua/null-ls/helpers/command_resolver.lua +++ b/lua/null-ls/helpers/command_resolver.lua @@ -1,6 +1,6 @@ local cache = require("null-ls.helpers.cache") local u = require("null-ls.utils") - +local is_windows = vim.loop.os_uname().version:match("Windows") local M = {} --- search for a local executable and its parent directory from start_path to end_path @@ -46,7 +46,12 @@ end M.from_node_modules = function() local node_modules_resolver = M.generic(u.path.join("node_modules", ".bin")) return function(params) - return node_modules_resolver(params) or params.command + if is_windows then + params.command = params.command .. ".cmd" + end + + local resolved_executable = node_modules_resolver(params) + return resolved_executable or params.command end end From e4413dbf828f88bf6c968a2136e5f96f4375f438 Mon Sep 17 00:00:00 2001 From: IronLu233 Date: Sat, 14 Jan 2023 10:25:09 +0800 Subject: [PATCH 2/3] fix(command_resolver): deep copy the params, preventing potential risk. --- lua/null-ls/helpers/command_resolver.lua | 8 +++++--- lua/null-ls/utils/init.lua | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/null-ls/helpers/command_resolver.lua b/lua/null-ls/helpers/command_resolver.lua index 386a9478f..0a8430467 100644 --- a/lua/null-ls/helpers/command_resolver.lua +++ b/lua/null-ls/helpers/command_resolver.lua @@ -1,6 +1,5 @@ local cache = require("null-ls.helpers.cache") local u = require("null-ls.utils") -local is_windows = vim.loop.os_uname().version:match("Windows") local M = {} --- search for a local executable and its parent directory from start_path to end_path @@ -46,8 +45,11 @@ end M.from_node_modules = function() local node_modules_resolver = M.generic(u.path.join("node_modules", ".bin")) return function(params) - if is_windows then - params.command = params.command .. ".cmd" + if u.path.is_windows then + local windows_params = vim.deepcopy(params) + windows_params.command = windows_params.command .. ".cmd" + local resolved_executable = node_modules_resolver(windows_params) + return resolved_executable or windows_params.command end local resolved_executable = node_modules_resolver(params) diff --git a/lua/null-ls/utils/init.lua b/lua/null-ls/utils/init.lua index 404a9e4b1..bc7684c48 100644 --- a/lua/null-ls/utils/init.lua +++ b/lua/null-ls/utils/init.lua @@ -238,6 +238,7 @@ end ---@class PathUtils ---@field exists fun(filename: string): boolean ---@field join function(paths: ...): string +---@field is_windows boolean M.path = { exists = function(filename) local stat = vim.loop.fs_stat(filename) @@ -246,6 +247,8 @@ M.path = { join = function(...) return table.concat(vim.tbl_flatten({ ... }), path_separator):gsub(path_separator .. "+", path_separator) end, + + is_windows = is_windows, } --- creates a callback that returns the first root matching a specified pattern From 1e1af9f2b50fe525ecbad7a5c77d224a61a0d16f Mon Sep 17 00:00:00 2001 From: Jose Alvarez Date: Mon, 16 Jan 2023 13:28:29 -0500 Subject: [PATCH 3/3] refactor(command_resolver): avoid (probably) unnecessary deep copy --- lua/null-ls/helpers/command_resolver.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/null-ls/helpers/command_resolver.lua b/lua/null-ls/helpers/command_resolver.lua index 0a8430467..e1d1ab23f 100644 --- a/lua/null-ls/helpers/command_resolver.lua +++ b/lua/null-ls/helpers/command_resolver.lua @@ -46,10 +46,7 @@ M.from_node_modules = function() local node_modules_resolver = M.generic(u.path.join("node_modules", ".bin")) return function(params) if u.path.is_windows then - local windows_params = vim.deepcopy(params) - windows_params.command = windows_params.command .. ".cmd" - local resolved_executable = node_modules_resolver(windows_params) - return resolved_executable or windows_params.command + params.command = params.command .. ".cmd" end local resolved_executable = node_modules_resolver(params)