You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

78 lines
2.5 KiB

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", "<cmd>Telescope lsp_references<CR>", "Show LSP references")
map("n", "gD", vim.lsp.buf.declaration, "Go to declaration")
map("n", "gd", "<cmd>Telescope lsp_definitions<CR>", "Show LSP definitions")
map("n", "gi", "<cmd>Telescope lsp_implementations<CR>", "Show LSP implementations")
map("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", "Show LSP type definitions")
-- Actions
map({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, "See available code actions")
map("n", "<leader>rn", vim.lsp.buf.rename, "Smart rename")
-- Diagnostics
map("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", "Show buffer diagnostics")
map("n", "<leader>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