nvimtools / none-ls.nvim

null-ls.nvim reloaded / Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
The Unlicense
2.43k stars 72 forks source link

Unable to run prettier #59

Closed ctranstrum closed 8 months ago

ctranstrum commented 8 months ago

FAQ

Issues

Neovim Version

NVIM v0.9.4

Dev Version?

Operating System

MacOS Sonoma 14.2.1

Minimal Config

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
    local path_sep = on_windows and "\\" or "/"
    local result = table.concat({ ... }, path_sep)
    return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local null_ls_config = function()
    local null_ls = require("null-ls")
    local fix = null_ls.builtins.formatting
    local js = { 'javascript', 'typescript', 'vue' }
    -- add only what you need to reproduce your issue
    null_ls.setup({
        sources = {
          fix.trim_newlines,
          fix.trim_whitespace,
          -- Javascript prettier
          fix.prettierd.with {
            filetypes = js,
            condition = function(u)
              return u.root_has_file('node_modules/.bin/prettier') and not u.root_has_file('.disable-prettier')
            end,
          },

        },
        debug = true,
    })
end

local function load_plugins()
    -- only add other plugins if they are necessary to reproduce the issue
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            {
                "nvimtools/none-ls.nvim",
                requires = { "nvim-lua/plenary.nvim" },
                config = null_ls_config,
            },
        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end

Steps to Reproduce

open a js file and run the formatter with :lua vim.lsp.buf.format {async=true}

Reproducibility Check

Expected Behavior

File is formatted with prettier

Actual Behavior

error message: [null-ls] failed to run generator: ...ker/start/none-ls.nvim/lua/null-ls/utils/cosmiconfig.lua:25: attempt to call field 'unpack' (a nil value)

Debug Log

[WARN Thu Jan 11 12:41:40 2024] /tmp/nvim/site/pack/packer/start/none-ls.nvim/lua/null-ls/generators.lua:94: failed to run generator: ...ker/start/none-ls.nvim/lua/null-ls/utils/cosmiconfig.lua:25: attempt to call field 'unpack' (a nil value)

Help

No

Implementation Help

No response

Requirements

mochaaP commented 8 months ago

Oops. Fixed in 7e146f3a188853843bb4ca1bff24c912bb9b7177.