mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.76k stars 191 forks source link

feature request: improving how nvim-lint find node executable #576

Closed RiwEZ closed 2 months ago

RiwEZ commented 2 months ago

Problem

The current implementation did it like this (example from linters/biomejs)

-- local binary_name = "biome"
cmd = function()
    local local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
    return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,

The problem is if we did not open an nvim instance on the folder that contains the node_modules folder (e.g. when working with multiple projects), this does not work.

Solution Idea

By using vim.fs.find we can find the node_modules directory relative to the open buffer and now the problem is gone.

-- local binary_name = "biome"
cmd = function()
    local dirname = vim.fs.dirname(vim.api.nvim_buf_get_name(0))
    local node_folders =
        vim.fs.find("node_modules/.bin/" .. binary_name, { upward = true, path = dirname })
    for _, result in ipairs(node_folders) do
        if vim.fn.executable(result) == 1 then
            return result
        end
    end
    -- fallback
    return binary_name
end

I can open a PR to implement this, if it's okay.

mfussenegger commented 2 months ago

See https://github.com/mfussenegger/nvim-lint/issues/482