98 lines
3.2 KiB
Lua
98 lines
3.2 KiB
Lua
-- ~/.config/nvim/lua/sam/plugins/lsp.lua (emmet-ls for HTML Tag Completion + No Warning)
|
|
|
|
return {
|
|
"neovim/nvim-lspconfig",
|
|
dependencies = {
|
|
"williamboman/mason.nvim",
|
|
"williamboman/mason-lspconfig.nvim",
|
|
"hrsh7th/nvim-cmp",
|
|
},
|
|
config = function()
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
local on_attach = function(client, bufnr)
|
|
-- LSP keymaps
|
|
local nmap = function(keys, func, desc)
|
|
vim.keymap.set("n", keys, func, { buffer = bufnr, desc = "LSP: " .. desc })
|
|
end
|
|
nmap("gD", vim.lsp.buf.declaration, "Go to Declaration")
|
|
nmap("gd", vim.lsp.buf.definition, "Go to Definition")
|
|
nmap("K", vim.lsp.buf.hover, "Hover Documentation")
|
|
nmap("<leader>rn", vim.lsp.buf.rename, "Rename Symbol")
|
|
nmap("<leader>ca", vim.lsp.buf.code_action, "Code Action")
|
|
end
|
|
|
|
require("mason").setup()
|
|
|
|
-- ADDING THE NEW LSP SERVERS HERE (emmet_ls replaces html for better tags)
|
|
local servers = {
|
|
"intelephense", -- PHP
|
|
"pyright", -- Python
|
|
"ts_ls", -- TS/JS
|
|
"clangd", -- C++
|
|
"lua_ls", -- Lua
|
|
"emmet_ls", -- HTML/CSS (for tag completion/snippets)
|
|
"jsonls", -- JSON
|
|
"yamlls", -- YAML
|
|
"marksman", -- Markdown
|
|
"bashls",
|
|
}
|
|
local mason_lspconfig = require("mason-lspconfig")
|
|
mason_lspconfig.setup({
|
|
ensure_installed = servers,
|
|
handlers = {
|
|
-- Global handler using new vim.lsp.config API (no global lspconfig require)
|
|
function(server_name)
|
|
vim.lsp.config(server_name, {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
root_dir = function(fname)
|
|
if type(fname) ~= "string" then
|
|
return vim.fn.getcwd()
|
|
end
|
|
local util = require("lspconfig.util")
|
|
return util.root_pattern(".git", "composer.json", "package.json")(fname)
|
|
or util.path.dirname(fname)
|
|
end,
|
|
})
|
|
end,
|
|
},
|
|
})
|
|
|
|
-- emmet-ls Specific Setup (for HTML/CSS tag completion + snippets)
|
|
vim.lsp.config("emmet_ls", {
|
|
on_attach = on_attach,
|
|
capabilities = vim.tbl_deep_extend("force", capabilities, {
|
|
textDocument = {
|
|
completion = {
|
|
completionItem = {
|
|
snippetSupport = true, -- Enables <div> → <div></div> + Emmet expansions
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
filetypes = { "html", "css", "javascriptreact", "typescriptreact" }, -- Broad for web files
|
|
root_dir = function(fname)
|
|
if type(fname) ~= "string" then
|
|
return vim.fn.getcwd()
|
|
end
|
|
local util = require("lspconfig.util")
|
|
return util.root_pattern(".git", "package.json")(fname)
|
|
or util.path.dirname(fname)
|
|
end,
|
|
init_options = {
|
|
html = {
|
|
options = {
|
|
["bem.enabled"] = true, -- Optional: BEM naming support
|
|
},
|
|
completions = true,
|
|
format = true,
|
|
extractColors = true,
|
|
includeLanguages = {
|
|
javascript = "javascriptreact",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
end,
|
|
}
|