diff --git a/vim/.config/nvim/lsp/astro.lua b/vim/.config/nvim/lsp/astro.lua index d53f1ca..45a9e8b 100644 --- a/vim/.config/nvim/lsp/astro.lua +++ b/vim/.config/nvim/lsp/astro.lua @@ -1,7 +1,7 @@ return { cmd = { 'astro-ls', '--stdio' }, filetypes = { 'astro' }, - root_markers = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' }, + root_markers = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git', '.jj' }, init_options = { typescript = { tsdk = "./node_modules/typescript/lib" diff --git a/vim/.config/nvim/lsp/basedpyright.lua b/vim/.config/nvim/lsp/basedpyright.lua index 5f54c3d..86fb411 100644 --- a/vim/.config/nvim/lsp/basedpyright.lua +++ b/vim/.config/nvim/lsp/basedpyright.lua @@ -32,6 +32,7 @@ return { 'Pipfile', 'pyrightconfig.json', '.git', + '.jj' }, settings = { basedpyright = { diff --git a/vim/.config/nvim/lsp/clangd.lua b/vim/.config/nvim/lsp/clangd.lua index 2fd489a..a3add02 100644 --- a/vim/.config/nvim/lsp/clangd.lua +++ b/vim/.config/nvim/lsp/clangd.lua @@ -17,7 +17,9 @@ return { '.clang-format', 'compile_commands.json', 'compile_flags.txt', - 'configure.ac' -- AutoTools + 'configure.ac', -- AutoTools + '.git', + '.jj' }, single_file_support = true, capabilities = { diff --git a/vim/.config/nvim/lsp/codebook.lua b/vim/.config/nvim/lsp/codebook.lua index 5bd3696..226046e 100644 --- a/vim/.config/nvim/lsp/codebook.lua +++ b/vim/.config/nvim/lsp/codebook.lua @@ -36,5 +36,5 @@ return { 'typst', 'zig', }, - root_markers = { '.git', 'codebook.toml', '.codebook.toml' }, + root_markers = { '.git', '.jj', 'codebook.toml', '.codebook.toml' }, } diff --git a/vim/.config/nvim/lsp/cspell-ls.lua b/vim/.config/nvim/lsp/cspell-ls.lua index b01c7a3..b3c60db 100644 --- a/vim/.config/nvim/lsp/cspell-ls.lua +++ b/vim/.config/nvim/lsp/cspell-ls.lua @@ -7,6 +7,7 @@ return { filetypes = { "go", "rust", "js", "ts", "html", "css", "json", "yaml", "markdown", "gitcommit", "typst", "lua", "htmlua", "c", "cpp", "arduino" }, root_markers = { '.git', + '.jj', 'cspell.json', '.cspell.json', 'cspell.json', diff --git a/vim/.config/nvim/lsp/css.lua b/vim/.config/nvim/lsp/css.lua new file mode 100644 index 0000000..9314747 --- /dev/null +++ b/vim/.config/nvim/lsp/css.lua @@ -0,0 +1,34 @@ +---@brief +--- +--- https://github.com/hrsh7th/vscode-langservers-extracted +--- +--- `css-languageserver` can be installed via `npm`: +--- +--- ```sh +--- npm i -g vscode-langservers-extracted +--- ``` +--- +--- Neovim does not currently include built-in snippets. `vscode-css-language-server` only provides completions when snippet support is enabled. To enable completion, install a snippet plugin and add the following override to your language client capabilities during setup. +--- +--- ```lua +--- --Enable (broadcasting) snippet capability for completion +--- local capabilities = vim.lsp.protocol.make_client_capabilities() +--- capabilities.textDocument.completion.completionItem.snippetSupport = true +--- +--- vim.lsp.config('cssls', { +--- capabilities = capabilities, +--- }) +--- ``` + +---@type vim.lsp.Config +return { + cmd = { 'vscode-css-language-server', '--stdio' }, + filetypes = { 'css', 'scss', 'less' }, + init_options = { provideFormatter = true }, -- needed to enable formatting capabilities + root_markers = { 'package.json', '.git', '.jj' }, + settings = { + css = { validate = true }, + scss = { validate = true }, + less = { validate = true }, + }, +} diff --git a/vim/.config/nvim/lsp/eslint.lua b/vim/.config/nvim/lsp/eslint.lua new file mode 100644 index 0000000..07d4ed7 --- /dev/null +++ b/vim/.config/nvim/lsp/eslint.lua @@ -0,0 +1,221 @@ +--- @brief +--- +--- https://github.com/hrsh7th/vscode-langservers-extracted +--- +--- `vscode-eslint-language-server` is a linting engine for JavaScript / Typescript. +--- It can be installed via `npm`: +--- +--- ```sh +--- npm i -g vscode-langservers-extracted +--- ``` +--- +--- The default `on_attach` config provides the `LspEslintFixAll` command that can be used to format a document on save: +--- ```lua +--- local base_on_attach = vim.lsp.config.eslint.on_attach +--- vim.lsp.config("eslint", { +--- on_attach = function(client, bufnr) +--- if not base_on_attach then return end +--- +--- base_on_attach(client, bufnr) +--- vim.api.nvim_create_autocmd("BufWritePre", { +--- buffer = bufnr, +--- command = "LspEslintFixAll", +--- }) +--- end, +--- }) +--- ``` +--- +--- See [vscode-eslint](https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L216-L229) for configuration options. +--- +--- Messages handled in lspconfig: `eslint/openDoc`, `eslint/confirmESLintExecution`, `eslint/probeFailed`, `eslint/noLibrary` +--- +--- Additional messages you can handle: `eslint/noConfig` +--- +--- ### Monorepo support +--- +--- `vscode-eslint-language-server` supports monorepos by default. It will automatically find the config file corresponding to the package you are working on. You can use different configs in different packages. +--- This works without the need of spawning multiple instances of `vscode-eslint-language-server`. +--- You can use a different version of ESLint in each package, but it is recommended to use the same version of ESLint in all packages. The location of the ESLint binary will be determined automatically. +--- +--- /!\ When using flat config files, you need to use them across all your packages in your monorepo, as it's a global setting for the server. +--- +--- ### Flat config in ESLint versions prior to 10.0 +--- +--- If you're using a ESLint version that supports both flat config and eslintrc (>= 8.21, < 10.0) and want to change +--- the [default behavior](https://eslint.org/blog/2023/10/flat-config-rollout-plans/), you'll need to set +--- `experimental.useFlatConfig` accordingly: +--- ```lua +--- vim.lsp.config("eslint", { +--- settings = { +--- experimental = { +--- -- If you want to use flat config on >= 8.21, < 9.0 +--- useFlatConfig = true, +--- -- Or if you want to use eslintrc on 9.* +--- -- useFlatConfig = false, +--- } +--- } +--- }) +--- ``` + +-- local util = require 'lspconfig.util' +local lsp = vim.lsp + +local eslint_config_files = { + '.eslintrc', + '.eslintrc.js', + '.eslintrc.cjs', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + 'eslint.config.js', + 'eslint.config.mjs', + 'eslint.config.cjs', + 'eslint.config.ts', + 'eslint.config.mts', + 'eslint.config.cts', +} + +---@type vim.lsp.Config +return { + cmd = { 'vscode-eslint-language-server', '--stdio' }, + filetypes = { + 'javascript', + 'javascriptreact', + 'typescript', + 'typescriptreact', + 'vue', + 'svelte', + 'astro', + 'htmlangular', + }, + workspace_required = true, + -- on_attach = function(client, bufnr) + -- vim.api.nvim_buf_create_user_command(bufnr, 'LspEslintFixAll', function() + -- client:request_sync('workspace/executeCommand', { + -- command = 'eslint.applyAllFixes', + -- arguments = { + -- { + -- uri = vim.uri_from_bufnr(bufnr), + -- version = lsp.util.buf_versions[bufnr], + -- }, + -- }, + -- }, nil, bufnr) + -- end, {}) + -- end, + root_dir = function(bufnr, on_dir) + -- The project root is where the LSP can be started from + -- As stated in the documentation above, this LSP supports monorepos and simple projects. + -- We select then from the project root, which is identified by the presence of a package + -- manager lock file. + local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock' } + -- Give the root markers equal priority by wrapping them in a table + root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git', '.jj' } } + or vim.list_extend(root_markers, { '.git' }) + + -- exclude deno + if vim.fs.root(bufnr, { 'deno.json', 'deno.jsonc', 'deno.lock' }) then + return + end + + -- We fallback to the current working directory if no project root is found + local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd() + + -- We know that the buffer is using ESLint if it has a config file + -- in its directory tree. + -- + -- Eslint used to support package.json files as config files, but it doesn't anymore. + -- We keep this for backward compatibility. + -- local filename = vim.api.nvim_buf_get_name(bufnr) + -- local eslint_config_files_with_package_json = + -- util.insert_package_json(eslint_config_files, 'eslintConfig', filename) + -- local is_buffer_using_eslint = vim.fs.find(eslint_config_files_with_package_json, { + -- path = filename, + -- type = 'file', + -- limit = 1, + -- upward = true, + -- stop = vim.fs.dirname(project_root), + -- })[1] + -- if not is_buffer_using_eslint then + -- return + -- end + + on_dir(project_root) + end, + -- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation. + settings = { + validate = 'on', + ---@diagnostic disable-next-line: assign-type-mismatch + packageManager = nil, + useESLintClass = false, + experimental = {}, + codeActionOnSave = { + enable = false, + mode = 'all', + }, + format = true, + quiet = false, + onIgnoredFiles = 'off', + rulesCustomizations = {}, + run = 'onType', + problems = { + shortenToSingleLine = false, + }, + -- nodePath configures the directory in which the eslint server should start its node_modules resolution. + -- This path is relative to the workspace folder (root dir) of the server instance. + nodePath = '', + -- use the workspace folder location or the file location (if no workspace folder is open) as the working directory + workingDirectory = { mode = 'auto' }, + codeAction = { + disableRuleComment = { + enable = true, + location = 'separateLine', + }, + showDocumentation = { + enable = true, + }, + }, + }, + before_init = function(_, config) + -- The "workspaceFolder" is a VSCode concept. It limits how far the + -- server will traverse the file system when locating the ESLint config + -- file (e.g., .eslintrc). + local root_dir = config.root_dir + + if root_dir then + config.settings = config.settings or {} + config.settings.workspaceFolder = { + uri = root_dir, + name = vim.fn.fnamemodify(root_dir, ':t'), + } + + -- Support Yarn2 (PnP) projects + local pnp_cjs = root_dir .. '/.pnp.cjs' + local pnp_js = root_dir .. '/.pnp.js' + if type(config.cmd) == 'table' and (vim.uv.fs_stat(pnp_cjs) or vim.uv.fs_stat(pnp_js)) then + config.cmd = vim.list_extend({ 'yarn', 'exec' }, config.cmd --[[@as table]]) + end + end + end, + handlers = { + ['eslint/openDoc'] = function(_, result) + if result then + vim.ui.open(result.url) + end + return {} + end, + ['eslint/confirmESLintExecution'] = function(_, result) + if not result then + return + end + return 4 -- approved + end, + ['eslint/probeFailed'] = function() + vim.notify('[lspconfig] ESLint probe failed.', vim.log.levels.WARN) + return {} + end, + ['eslint/noLibrary'] = function() + vim.notify('[lspconfig] Unable to find ESLint library.', vim.log.levels.WARN) + return {} + end, + }, +} diff --git a/vim/.config/nvim/lsp/fish-lsp.lua b/vim/.config/nvim/lsp/fish-lsp.lua new file mode 100644 index 0000000..d0e6500 --- /dev/null +++ b/vim/.config/nvim/lsp/fish-lsp.lua @@ -0,0 +1,17 @@ +---@brief +--- +--- https://github.com/ndonfris/fish-lsp +--- +--- A Language Server Protocol (LSP) tailored for the fish shell. +--- This project aims to enhance the coding experience for fish, +--- by introducing a suite of intelligent features like auto-completion, +--- scope aware symbol analysis, per-token hover generation, and many others. +--- +--- [homepage](https://www.fish-lsp.dev/) + +---@type vim.lsp.Config +return { + cmd = { 'fish-lsp', 'start' }, + filetypes = { 'fish' }, + root_markers = { 'config.fish', '.git', '.jj' }, +} diff --git a/vim/.config/nvim/lsp/gdscript.lua b/vim/.config/nvim/lsp/gdscript.lua index 42f3ae2..aaba5a3 100644 --- a/vim/.config/nvim/lsp/gdscript.lua +++ b/vim/.config/nvim/lsp/gdscript.lua @@ -5,5 +5,5 @@ local cmd = vim.lsp.rpc.connect('127.0.0.1', tonumber(port)) return { cmd = cmd, filetypes = { 'gd', 'gdscript', 'gdscript3' }, - root_markers = { 'project.godot', '.git' }, + root_markers = { 'project.godot', '.git', '.jj' }, } diff --git a/vim/.config/nvim/lsp/gopls.lua b/vim/.config/nvim/lsp/gopls.lua index 0b4c59f..1cec249 100644 --- a/vim/.config/nvim/lsp/gopls.lua +++ b/vim/.config/nvim/lsp/gopls.lua @@ -82,7 +82,7 @@ local function get_root_dir(fname) return clients[#clients].config.root_dir end end - return vim.fs.root(fname, 'go.work') or vim.fs.root(fname, 'go.mod') or vim.fs.root(fname, '.git') + return vim.fs.root(fname, 'go.work') or vim.fs.root(fname, 'go.mod') or vim.fs.root(fname, '.git') or vim.fs.root(fname, '.jj') end return { diff --git a/vim/.config/nvim/lsp/html.lua b/vim/.config/nvim/lsp/html.lua new file mode 100644 index 0000000..e9ac9c4 --- /dev/null +++ b/vim/.config/nvim/lsp/html.lua @@ -0,0 +1,36 @@ +---@brief +--- +--- https://github.com/hrsh7th/vscode-langservers-extracted +--- +--- `vscode-html-language-server` can be installed via `npm`: +--- ```sh +--- npm i -g vscode-langservers-extracted +--- ``` +--- +--- Neovim does not currently include built-in snippets. `vscode-html-language-server` only provides completions when snippet support is enabled. +--- To enable completion, install a snippet plugin and add the following override to your language client capabilities during setup. +--- +--- The code-formatting feature of the lsp can be controlled with the `provideFormatter` option. +--- +--- ```lua +--- --Enable (broadcasting) snippet capability for completion +--- local capabilities = vim.lsp.protocol.make_client_capabilities() +--- capabilities.textDocument.completion.completionItem.snippetSupport = true +--- +--- vim.lsp.config('html', { +--- capabilities = capabilities, +--- }) +--- ``` + +---@type vim.lsp.Config +return { + cmd = { 'vscode-html-language-server', '--stdio' }, + filetypes = { 'html' }, + root_markers = { 'package.json', '.git', '.jj' }, + settings = {}, + init_options = { + provideFormatter = true, + embeddedLanguages = { css = true, javascript = true }, + configurationSection = { 'html', 'css', 'javascript' }, + }, +} diff --git a/vim/.config/nvim/lsp/json.lua b/vim/.config/nvim/lsp/json.lua new file mode 100644 index 0000000..3ef906c --- /dev/null +++ b/vim/.config/nvim/lsp/json.lua @@ -0,0 +1,32 @@ +---@brief +--- +--- https://github.com/hrsh7th/vscode-langservers-extracted +--- +--- vscode-json-language-server, a language server for JSON and JSON schema +--- +--- `vscode-json-language-server` can be installed via `npm`: +--- ```sh +--- npm i -g vscode-langservers-extracted +--- ``` +--- +--- `vscode-json-language-server` only provides completions when snippet support is enabled. If you use Neovim older than v0.10 you need to enable completion, install a snippet plugin and add the following override to your language client capabilities during setup. +--- +--- ```lua +--- --Enable (broadcasting) snippet capability for completion +--- local capabilities = vim.lsp.protocol.make_client_capabilities() +--- capabilities.textDocument.completion.completionItem.snippetSupport = true +--- +--- vim.lsp.config('jsonls', { +--- capabilities = capabilities, +--- }) +--- ``` + +---@type vim.lsp.Config +return { + cmd = { 'vscode-json-language-server', '--stdio' }, + filetypes = { 'json', 'jsonc' }, + init_options = { + provideFormatter = true, + }, + root_markers = { '.git', '.jj' }, +} diff --git a/vim/.config/nvim/lsp/pyright.lua b/vim/.config/nvim/lsp/pyright.lua index edc802e..b501b85 100644 --- a/vim/.config/nvim/lsp/pyright.lua +++ b/vim/.config/nvim/lsp/pyright.lua @@ -32,6 +32,7 @@ return { 'Pipfile', 'pyrightconfig.json', '.git', + '.jj' }, settings = { python = { diff --git a/vim/.config/nvim/lsp/superhtml.lua b/vim/.config/nvim/lsp/superhtml.lua index 7e68b25..fcbe24b 100644 --- a/vim/.config/nvim/lsp/superhtml.lua +++ b/vim/.config/nvim/lsp/superhtml.lua @@ -18,5 +18,5 @@ return { cmd = { 'superhtml', 'lsp' }, filetypes = { 'superhtml', 'html', "htmldjango" }, - root_markers = { '.git' }, + root_markers = { '.git', '.jj' }, } diff --git a/vim/.config/nvim/lsp/tinymist.lua b/vim/.config/nvim/lsp/tinymist.lua index 5b6a449..eddcd7e 100644 --- a/vim/.config/nvim/lsp/tinymist.lua +++ b/vim/.config/nvim/lsp/tinymist.lua @@ -49,7 +49,7 @@ end return { cmd = { 'tinymist' }, filetypes = { 'typst' }, - root_markers = { '.git' }, + root_markers = { '.git', '.jj' }, on_attach = function(client, bufnr) for _, command in ipairs { 'tinymist.exportSvg', diff --git a/vim/.config/nvim/lsp/ty.lua b/vim/.config/nvim/lsp/ty.lua index 254ef7e..411fbd1 100644 --- a/vim/.config/nvim/lsp/ty.lua +++ b/vim/.config/nvim/lsp/ty.lua @@ -1,5 +1,5 @@ return { cmd = { 'uvx', 'ty', 'server' }, filetypes = { 'python' }, - root_markers = { 'ty.toml', 'pyproject.toml', '.git' }, + root_markers = { 'ty.toml', 'pyproject.toml', '.git', '.jj' }, } diff --git a/vim/.config/nvim/lsp/zigscient.lua b/vim/.config/nvim/lsp/zigscient.lua index cdce2f3..bdb256f 100644 --- a/vim/.config/nvim/lsp/zigscient.lua +++ b/vim/.config/nvim/lsp/zigscient.lua @@ -7,6 +7,6 @@ return { cmd = { 'zigscient' }, filetypes = { 'zig', 'zir' }, - root_markers = { 'zls.json', 'build.zig', '.git' }, + root_markers = { 'zls.json', 'build.zig', '.git', '.jj' }, workspace_required = false, } diff --git a/vim/.config/nvim/lsp/zls.lua b/vim/.config/nvim/lsp/zls.lua index 6a8dc08..6716521 100644 --- a/vim/.config/nvim/lsp/zls.lua +++ b/vim/.config/nvim/lsp/zls.lua @@ -7,6 +7,6 @@ return { cmd = { 'zls' }, filetypes = { 'zig', 'zir' }, - root_markers = { 'zls.json', 'build.zig', '.git' }, + root_markers = { 'zls.json', 'build.zig', '.git', '.jj' }, workspace_required = false, } diff --git a/vim/.config/nvim/lua/native-lsp.lua b/vim/.config/nvim/lua/native-lsp.lua index 38fdacd..ec5d865 100644 --- a/vim/.config/nvim/lua/native-lsp.lua +++ b/vim/.config/nvim/lua/native-lsp.lua @@ -79,6 +79,13 @@ vim.lsp.enable("csharp-ls") vim.lsp.enable("asm-lsp") vim.lsp.enable("codebook") +vim.lsp.enable("json") +vim.lsp.enable("eslint") +vim.lsp.enable("css") +vim.lsp.enable("html") +vim.lsp.enable("fish-lsp") + + -- https://lsp-zero.netlify.app/blog/lsp-client-features.html