Add mdx lsp support

This commit is contained in:
2026-04-27 11:57:14 -07:00
parent 051ea08678
commit 5a3a28badc
6 changed files with 115 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
return {
cmd = { "lemminx" },
filetypes = { "xml", "xsd", "xsl", "xslt", "svg" },
root_markers = { "sfdx-project.json", ".git" },
}
+7
View File
@@ -0,0 +1,7 @@
-- LWC LSP: install with `npm i -g @salesforce/lwc-language-server`.
-- Attaches only inside SFDX projects via root marker.
return {
cmd = { "lwc-language-server", "--stdio" },
filetypes = { "javascript", "html" },
root_markers = { "sfdx-project.json" },
}
+24
View File
@@ -0,0 +1,24 @@
local function tsdk()
local local_ts = vim.fs.find("node_modules/typescript/lib", {
upward = true,
path = vim.fn.expand("%:p:h"),
type = "directory",
})[1]
if local_ts then return local_ts end
return vim.fn.stdpath("data")
.. "/mason/packages/typescript-language-server/node_modules/typescript/lib"
end
return {
cmd = { "mdx-language-server", "--stdio" },
filetypes = { "mdx", "markdown.mdx" },
root_markers = { "package.json", "tsconfig.json", ".git" },
init_options = {
typescript = { tsdk = tsdk() },
},
capabilities = {
workspace = {
didChangeWatchedFiles = { dynamicRegistration = false },
},
},
}
+61 -2
View File
@@ -1,5 +1,49 @@
local lint = require("lint")
-- PMD for Apex. JVM startup ~3s per run, so we trigger on save only.
-- Uses project-local pmd-ruleset.xml if present, else bundled Apex categories.
lint.linters.pmd_apex = {
cmd = "pmd",
stdin = false,
append_fname = true,
args = function()
local ruleset = vim.fs.find("pmd-ruleset.xml", {
upward = true,
path = vim.fn.expand("%:p:h"),
})[1] or
"category/apex/bestpractices.xml,category/apex/errorprone.xml," ..
"category/apex/security.xml,category/apex/performance.xml," ..
"category/apex/design.xml"
return { "check", "-R", ruleset, "-f", "json", "--no-progress", "-d" }
end,
stream = "stdout",
ignore_exitcode = true,
parser = function(output)
if not output or output == "" then return {} end
local ok, decoded = pcall(vim.json.decode, output)
if not ok or not decoded.files then return {} end
local diags = {}
for _, file in ipairs(decoded.files) do
for _, v in ipairs(file.violations or {}) do
local sev = vim.diagnostic.severity.WARN
if (v.priority or 3) <= 2 then sev = vim.diagnostic.severity.ERROR
elseif (v.priority or 3) >= 4 then sev = vim.diagnostic.severity.INFO end
table.insert(diags, {
lnum = (v.beginline or 1) - 1,
end_lnum = (v.endline or v.beginline or 1) - 1,
col = (v.begincolumn or 1) - 1,
end_col = v.endcolumn or v.begincolumn or 1,
severity = sev,
source = "pmd",
code = v.rule,
message = v.description,
})
end
end
return diags
end,
}
lint.linters_by_ft = {
javascript = { "eslint_d" },
typescript = { "eslint_d" },
@@ -9,10 +53,25 @@ lint.linters_by_ft = {
sh = { "shellcheck" },
bash = { "shellcheck" },
markdown = { "markdownlint-cli2" },
-- apex handled via separate save-only autocmd below (pmd is slow)
}
vim.api.nvim_create_autocmd({ "BufWritePost", "InsertLeave" }, {
callback = function() lint.try_lint() end,
callback = function()
if vim.bo.filetype == "apex" then return end
lint.try_lint()
end,
})
vim.keymap.set("n", "<leader>l", function() lint.try_lint() end, { desc = "Lint buffer" })
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.cls", "*.trigger", "*.apex" },
callback = function() lint.try_lint("pmd_apex") end,
})
vim.keymap.set("n", "<leader>l", function()
if vim.bo.filetype == "apex" then
lint.try_lint("pmd_apex")
else
lint.try_lint()
end
end, { desc = "Lint buffer" })
+16
View File
@@ -1,8 +1,21 @@
vim.filetype.add({
extension = {
mdx = "markdown.mdx",
cls = "apex",
trigger = "apex",
apex = "apex",
-- Visualforce
page = "html",
component = "html",
-- Aura
cmp = "html",
app = "html",
evt = "xml",
-- SOQL
soql = "soql",
},
pattern = {
[".*%-meta%.xml"] = "xml",
},
})
@@ -26,6 +39,9 @@ vim.lsp.enable({
"bashls",
"apex_ls",
"htmx",
"lemminx",
"lwc_ls",
"mdx_analyzer",
})
vim.diagnostic.config({
+2
View File
@@ -25,6 +25,8 @@ require("mason-tool-installer").setup({
"taplo",
"bash-language-server",
"htmx-lsp",
"lemminx",
"mdx-analyzer",
-- Apex LSP not in mason registry — install JAR manually, set APEX_JAR env
-- Formatters