From 51cbef51f64d7fe003e7445ef34df9aa6527111c Mon Sep 17 00:00:00 2001 From: Burton Smith <31320098+break-stuff@users.noreply.github.com> Date: Sun, 7 Dec 2025 14:20:48 -0500 Subject: feat(wc_language_server): web components language server #4228 --- lsp/wc_language_server.lua | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lsp/wc_language_server.lua diff --git a/lsp/wc_language_server.lua b/lsp/wc_language_server.lua new file mode 100644 index 00000000..9005400b --- /dev/null +++ b/lsp/wc_language_server.lua @@ -0,0 +1,85 @@ +---@brief +--- +--- https://github.com/wc-toolkit/wc-language-server +--- +--- Web Components Language Server provides intelligent editor support for Web Components and custom elements. +--- It offers advanced HTML diagnostics, completion, and validation for custom elements, including support for +--- attribute types, deprecation, and duplicate attribute detection. +--- +--- The language server uses the [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest) +--- to generate component integration and validation information +--- +--- `wc-language-server` can be installed by following the instructions at the [GitHub repository](https://github.com/wc-toolkit/wc-language-server/blob/main/packages/neovim/README.md). +--- +--- The default `cmd` assumes that the `wc-language-server` binary can be found in `$PATH`. +--- +--- Alternatively, you can install it via [mason.nvim](https://github.com/williamboman/mason.nvim): +--- ```vim +--- :MasonInstall wc-language-server +--- ``` +--- +--- ## Configuration +--- +--- The language server reads settings from `wc.config.js` (or `.ts/.mjs/.cjs`) at the project root. +--- Use it to customize manifest sources, file scoping, and diagnostic behavior. +--- +--- Example `wc.config.js`: +--- ```js +--- export default { +--- // Fetch manifest from a custom path or URL +--- manifestSrc: './dist/custom-elements.json', +--- +--- // Narrow which files opt into the language server +--- include: ['src/**/*.ts', 'src/**/*.html'], +--- +--- // Skip specific globs +--- exclude: ['**/*.stories.ts'], +--- +--- // Per-library overrides +--- libraries: { +--- '@your/pkg': { +--- manifestSrc: 'https://cdn.example.com/custom-elements.json', +--- tagFormatter: (tag) => tag.replace(/^x-/, 'my-'), +--- }, +--- }, +--- +--- // Customize diagnostic severity levels +--- diagnosticSeverity: { +--- duplicateAttribute: 'warning', +--- unknownElement: 'info', +--- }, +--- }; +--- ``` +--- +--- See the [configuration documentation](https://github.com/wc-toolkit/wc-language-server#configuration) for more details. +--- + +---@type vim.lsp.Config +return { + init_options = { hostInfo = 'neovim' }, + cmd = { 'wc-language-server', '--stdio' }, + filetypes = { + 'html', + 'javascriptreact', + 'typescriptreact', + 'astro', + 'svelte', + 'vue', + 'markdown', + 'mdx', + 'javascript', + 'typescript', + 'css', + 'scss', + 'less', + }, + root_markers = { + 'wc.config.js', + 'wc.config.ts', + 'wc.config.mjs', + 'wc.config.cjs', + 'custom-elements.json', + 'package.json', + '.git', + }, +} -- cgit v1.2.3-70-g09d2