local M = {} -- Find global node_modules path function M.find_node_modules_path() local paths = { "/usr/lib/node_modules", "/usr/local/lib/node_modules", "/opt/homebrew/lib/node_modules" } for _, path in ipairs(paths) do if vim.loop.fs_stat(path) then return path end end return nil end -- Check if a file exists function M.file_exists(path) return vim.fn.filereadable(path) == 1 end -- Check if a directory exists function M.dir_exists(path) return vim.fn.isdirectory(path) == 1 end -- Get project root directory function M.get_project_root() return vim.loop.cwd() end -- Setup common LSP keymaps (you can move the keymap logic here if desired) function M.setup_lsp_keymaps(bufnr) local keymap = vim.keymap local function map(mode, lhs, rhs, desc) keymap.set(mode, lhs, rhs, { buffer = bufnr, noremap = true, silent = true, desc = desc }) end -- Navigation map("n", "gr", "Telescope lsp_references", "Show LSP references") map("n", "gD", vim.lsp.buf.declaration, "Go to declaration") map("n", "gd", "Telescope lsp_definitions", "Show LSP definitions") map("n", "gi", "Telescope lsp_implementations", "Show LSP implementations") map("n", "gt", "Telescope lsp_type_definitions", "Show LSP type definitions") -- Actions map({ "n", "v" }, "ca", vim.lsp.buf.code_action, "See available code actions") map("n", "rn", vim.lsp.buf.rename, "Smart rename") -- Diagnostics map("n", "D", "Telescope diagnostics bufnr=0", "Show buffer diagnostics") map("n", "d", vim.diagnostic.open_float, "Show line diagnostics") map("n", "[d", function() vim.diagnostic.jump({ count = -1, float = true }) end, "Go to previous diagnostic") map("n", "]d", function() vim.diagnostic.jump({ count = 1, float = true }) end, "Go to next diagnostic") map("n", "[e", function() vim.diagnostic.jump({ count = -1, float = true, severity = vim.diagnostic.severity.ERROR }) end, "Go to previous diagnostic (error only)") map("n", "]e", function() vim.diagnostic.jump({ count = 1, float = true, severity = vim.diagnostic.severity.ERROR }) end, "Go to next diagnostic (error only)") -- Documentation map("n", "K", vim.lsp.buf.hover, "Show documentation for what is under cursor") end return M