Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

fix(command_resolver): fix resolve executable on Windows system #1341

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lua/null-ls/helpers/command_resolver.lua
Original file line number Diff line number Diff line change
@@ -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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we actually add this to our path utils and read the value from there? I'd rather avoid duplicating the check.

local M = {}

--- search for a local executable and its parent directory from start_path to end_path
Expand Down Expand Up @@ -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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two potential issues with this:

  1. I'm not sure if mutating this directly on the params table will have any unexpected effects, but it seems risky.
  2. If we're looking for eslint and don't find a local executable, then we'll be looking for eslint.cmd in $PATH (I'm actually not sure what this will do, but I suspect it won't work).

I think it would be less risky to declare local command_to_find = params.command and use that, then fall back to params.command.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike Linux, Windows determine a file is executable or not, is rely on file's extension. when file's extension changes, the file will not be executable.

image

I rename prettier.cmd to prettier.cmd3, and it can not be executed.

end

local resolved_executable = node_modules_resolver(params)
return resolved_executable or params.command
end
end

Expand Down