mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-01 20:47:42 +00:00
chore(lint): fixed stylua and linted nvim configs
This commit is contained in:
@@ -25,22 +25,17 @@ M.version = '0.1.0' -- x-release-please-version
|
||||
---@return string? Return the result of the command
|
||||
local function run_command(cmd)
|
||||
local result = vim.fn.system(cmd)
|
||||
return vim.v.shell_error == 0 and result:gsub("%s+$", "") or nil
|
||||
return vim.v.shell_error == 0 and result:gsub('%s+$', '') or nil
|
||||
end
|
||||
|
||||
|
||||
-- Helper function to show a notification
|
||||
---@param msg string Show a message
|
||||
---@param level number|"info"|"warn"|"error"|"trace" Notification level
|
||||
local function n(msg, level)
|
||||
if msg == nil then
|
||||
msg = M.name .. ": No message provided"
|
||||
end
|
||||
if level == nil then
|
||||
level = "trace"
|
||||
end
|
||||
if msg == nil then msg = M.name .. ': No message provided' end
|
||||
if level == nil then level = 'trace' end
|
||||
|
||||
vim.notify(M.name .. ": " .. msg, level)
|
||||
vim.notify(M.name .. ': ' .. msg, level)
|
||||
end
|
||||
|
||||
---@class NvmDefaultOptions
|
||||
@@ -52,59 +47,63 @@ end
|
||||
---@type NvmDefaultOptions
|
||||
M.defaults = {
|
||||
add_to_path = vim.g.nvm_default_add_to_path or true,
|
||||
nvm_path = vim.fn.expand(os.getenv("NVM_DIR") or "~/.nvm"),
|
||||
notify_level = vim.g.nvm_default_notify_level or "info",
|
||||
nvm_path = vim.fn.expand(os.getenv 'NVM_DIR' or '~/.nvm'),
|
||||
notify_level = vim.g.nvm_default_notify_level or 'info',
|
||||
}
|
||||
|
||||
-- Fetch the NVM default version or fallback to node version
|
||||
---@param opts? NvmDefaultOptions Plugin options
|
||||
function M.setup(opts)
|
||||
local options = vim.tbl_deep_extend("force", M.defaults, opts or {})
|
||||
local options = vim.tbl_deep_extend('force', M.defaults, opts or {})
|
||||
|
||||
local nvm_path = options.nvm_path
|
||||
local node_version =
|
||||
run_command(string.format(". %s/nvm.sh && nvm version default", nvm_path)) or
|
||||
run_command(string.format(". %s/nvm.sh && nvm version node", nvm_path))
|
||||
local node_version = run_command(
|
||||
string.format('. %s/nvm.sh && nvm version default', nvm_path)
|
||||
) or run_command(string.format('. %s/nvm.sh && nvm version node', nvm_path))
|
||||
|
||||
if node_version and node_version:match("^v") then
|
||||
if node_version and node_version:match '^v' then
|
||||
-- Set vim.g.node_host_prog and vim.g.copilot_node_command
|
||||
local current_nvm_version_path = string.format("%s/versions/node/%s", nvm_path, node_version)
|
||||
local current_nvm_node_bin_path = string.format("%s/bin", current_nvm_version_path)
|
||||
local current_nvm_node_bin = string.format("%s/node", current_nvm_node_bin_path)
|
||||
local neovim_node_host_bin_path = string.format("%s/neovim-node-host", current_nvm_node_bin_path)
|
||||
local current_nvm_version_path =
|
||||
string.format('%s/versions/node/%s', nvm_path, node_version)
|
||||
local current_nvm_node_bin_path =
|
||||
string.format('%s/bin', current_nvm_version_path)
|
||||
local current_nvm_node_bin =
|
||||
string.format('%s/node', current_nvm_node_bin_path)
|
||||
local neovim_node_host_bin_path =
|
||||
string.format('%s/neovim-node-host', current_nvm_node_bin_path)
|
||||
|
||||
-- Collect missing files and directories errors for error output
|
||||
local missing = {}
|
||||
|
||||
-- If node_dir isn't there, stop and show error
|
||||
if not vim.fn.isdirectory(current_nvm_version_path) then
|
||||
table.insert(missing, "Node.js directory: " .. current_nvm_version_path)
|
||||
table.insert(missing, 'Node.js directory: ' .. current_nvm_version_path)
|
||||
end
|
||||
|
||||
-- If node_bin isn't there, stop and show error
|
||||
if not vim.fn.filereadable(current_nvm_node_bin) then
|
||||
table.insert(missing, "Node.js binary: " .. current_nvm_node_bin)
|
||||
table.insert(missing, 'Node.js binary: ' .. current_nvm_node_bin)
|
||||
end
|
||||
|
||||
if not vim.fn.filereadable(neovim_node_host_bin_path) then
|
||||
table.insert(missing, "Neovim host binary: " .. neovim_node_host_bin_path)
|
||||
table.insert(missing, 'Neovim host binary: ' .. neovim_node_host_bin_path)
|
||||
end
|
||||
|
||||
if #missing > 0 then
|
||||
n("Missing required files:\n- " .. table.concat(missing, "\n- "), "error")
|
||||
n('Missing required files:\n- ' .. table.concat(missing, '\n- '), 'error')
|
||||
return
|
||||
end
|
||||
|
||||
-- Add to PATH if requested. Can be turned off by setting if it messes with
|
||||
-- other tools.
|
||||
if options.add_to_path then
|
||||
vim.env.PATH = current_nvm_node_bin_path .. ":" .. vim.env.PATH
|
||||
vim.env.PATH = current_nvm_node_bin_path .. ':' .. vim.env.PATH
|
||||
end
|
||||
|
||||
vim.g.node_host_prog = neovim_node_host_bin_path
|
||||
vim.g.copilot_node_command = current_nvm_node_bin
|
||||
else
|
||||
n("Unable to determine the Node.js version from nvm.", "error")
|
||||
n('Unable to determine the Node.js version from nvm.', 'error')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user