summaryrefslogtreecommitdiff
path: root/.config/nvim/lsp
diff options
context:
space:
mode:
authormoxie <moxie.git@posteo.net>2025-09-30 12:27:44 +0300
committermoxie <moxie.git@posteo.net>2025-09-30 12:27:44 +0300
commit1e27d1c7b25e4d28a25c0fa2c4e6e33a66b9072e (patch)
tree7169509b4d5dfce3ed25fe333cc506a40f5c90f2 /.config/nvim/lsp
parent51797f743fe74d1723ca62085f92e8c5e953038b (diff)
add nvim configs
Diffstat (limited to '.config/nvim/lsp')
-rw-r--r--.config/nvim/lsp/bashls.lua7
-rw-r--r--.config/nvim/lsp/clangd.lua13
-rw-r--r--.config/nvim/lsp/cssls.lua20
-rw-r--r--.config/nvim/lsp/gopls.lua9
-rw-r--r--.config/nvim/lsp/jsonls.lua8
-rw-r--r--.config/nvim/lsp/lua_ls.lua12
-rw-r--r--.config/nvim/lsp/pyright.lua34
-rw-r--r--.config/nvim/lsp/rubocop.lua5
-rw-r--r--.config/nvim/lsp/ruby-lsp.lua9
-rw-r--r--.config/nvim/lsp/ruff.lua11
-rw-r--r--.config/nvim/lsp/rust_analyzer.lua19
-rw-r--r--.config/nvim/lsp/ts_ls.lua83
-rw-r--r--.config/nvim/lsp/ty.lua13
13 files changed, 243 insertions, 0 deletions
diff --git a/.config/nvim/lsp/bashls.lua b/.config/nvim/lsp/bashls.lua
new file mode 100644
index 0000000..88cc2b1
--- /dev/null
+++ b/.config/nvim/lsp/bashls.lua
@@ -0,0 +1,7 @@
+return {
+ cmd = { "bash-language-server", "start" },
+ filetypes = { "bash", "sh" },
+ root_markers = { ".git", },
+ single_file_support = true,
+ settings = {},
+}
diff --git a/.config/nvim/lsp/clangd.lua b/.config/nvim/lsp/clangd.lua
new file mode 100644
index 0000000..ad2b669
--- /dev/null
+++ b/.config/nvim/lsp/clangd.lua
@@ -0,0 +1,13 @@
+return {
+ cmd = { "clangd" },
+ root_markers = { ".clangd", "compile_commands.json" },
+ init_options = { clangdFilestatus = true },
+ filetypes = { "c", "cpp" },
+ capabilities = {
+ textDocument = {
+ semanticTokens = {
+ multilineTokenSupport = true,
+ }
+ }
+ }
+}
diff --git a/.config/nvim/lsp/cssls.lua b/.config/nvim/lsp/cssls.lua
new file mode 100644
index 0000000..01e73c4
--- /dev/null
+++ b/.config/nvim/lsp/cssls.lua
@@ -0,0 +1,20 @@
+return {
+ init_options = { provideFormatter = true }, -- needed to enable formatting capabilities
+ cmd = { 'vscode-css-language-server', '--stdio' },
+ filetypes = { 'css', 'scss', 'less' },
+ root_markers = { 'package.json', '.git' },
+ settings = {
+ css = { validate = true },
+ scss = { validate = true },
+ less = { validate = true },
+ },
+ capabilities = {
+ textDocument = {
+ completion = {
+ completionItem = {
+ snippetSupport = true,
+ }
+ }
+ }
+ }
+}
diff --git a/.config/nvim/lsp/gopls.lua b/.config/nvim/lsp/gopls.lua
new file mode 100644
index 0000000..a72ff1f
--- /dev/null
+++ b/.config/nvim/lsp/gopls.lua
@@ -0,0 +1,9 @@
+return {
+ cmd = { "gopls" },
+ filetypes = { "go", "gomod", "gowork", "gotmpl" },
+ root_markers = {
+ "go.work",
+ "go.mod",
+ ".git",
+ },
+}
diff --git a/.config/nvim/lsp/jsonls.lua b/.config/nvim/lsp/jsonls.lua
new file mode 100644
index 0000000..98da93b
--- /dev/null
+++ b/.config/nvim/lsp/jsonls.lua
@@ -0,0 +1,8 @@
+return {
+ settings = {
+ json = {
+ schemas = require("schemastore").json.schemas(),
+ validate = { enable = true },
+ },
+ },
+}
diff --git a/.config/nvim/lsp/lua_ls.lua b/.config/nvim/lsp/lua_ls.lua
new file mode 100644
index 0000000..936557c
--- /dev/null
+++ b/.config/nvim/lsp/lua_ls.lua
@@ -0,0 +1,12 @@
+return {
+ cmd = { "lua-language-server" },
+ filetypes = { "lua" },
+ root_markers = { ".luarc.json", ".luarc.jsonc" },
+ settings = {
+ Lua = {
+ runtime = {
+ version = "LuaJIT",
+ },
+ },
+ },
+}
diff --git a/.config/nvim/lsp/pyright.lua b/.config/nvim/lsp/pyright.lua
new file mode 100644
index 0000000..d5a139a
--- /dev/null
+++ b/.config/nvim/lsp/pyright.lua
@@ -0,0 +1,34 @@
+return {
+ cmd = { "pyright-langserver", "--stdio" },
+ filetypes = { "python" },
+ root_markers = {
+ "pyproject.toml",
+ "setup.py",
+ "setup.cfg",
+ "requirements.txt",
+ "Pipfile",
+ "pyrightconfig.json",
+ ".git",
+ },
+ capabilities = {
+ offsetEncoding = { "utf-8" },
+ },
+ single_file_support = true,
+ settings = {
+ pyright = {
+ -- use ruff import organizer
+ disableOrganizeImports = true,
+ },
+ python = {
+ analysis = {
+ -- ignore all files for analysis and use ruff for linting
+ ignore = { '*' },
+ -- diagnosticSeverityOverrides = "none",
+ autoSearchPaths = true,
+ useLibraryCodeForTypes = true,
+ diagnosticMode = "openFilesOnly",
+ -- typeCheckingMode = "off",
+ },
+ },
+ },
+}
diff --git a/.config/nvim/lsp/rubocop.lua b/.config/nvim/lsp/rubocop.lua
new file mode 100644
index 0000000..b04c9a4
--- /dev/null
+++ b/.config/nvim/lsp/rubocop.lua
@@ -0,0 +1,5 @@
+return {
+ cmd = { 'rubocop', '--lsp' },
+ filetypes = { 'ruby' },
+ root_markers = { 'Gemfile', '.git' },
+}
diff --git a/.config/nvim/lsp/ruby-lsp.lua b/.config/nvim/lsp/ruby-lsp.lua
new file mode 100644
index 0000000..9403914
--- /dev/null
+++ b/.config/nvim/lsp/ruby-lsp.lua
@@ -0,0 +1,9 @@
+return {
+ cmd = { 'ruby-lsp' },
+ filetypes = { 'ruby', 'eruby' },
+ root_markers = { 'Gemfile', '.git' },
+ init_options = {
+ formatter = 'auto',
+ },
+ single_file_support = true,
+}
diff --git a/.config/nvim/lsp/ruff.lua b/.config/nvim/lsp/ruff.lua
new file mode 100644
index 0000000..d00352c
--- /dev/null
+++ b/.config/nvim/lsp/ruff.lua
@@ -0,0 +1,11 @@
+return {
+ cmd = { "ruff", "server" },
+ filetypes = { "python" },
+ root_markers = {
+ "pyproject.toml",
+ "ruff.toml",
+ ".ruff.toml",
+ },
+ single_file_support = true,
+ settings = {},
+}
diff --git a/.config/nvim/lsp/rust_analyzer.lua b/.config/nvim/lsp/rust_analyzer.lua
new file mode 100644
index 0000000..df5c1de
--- /dev/null
+++ b/.config/nvim/lsp/rust_analyzer.lua
@@ -0,0 +1,19 @@
+return {
+ cmd = { "rust-analyzer" },
+ filetypes = { "rust" },
+ root_markers = { "Cargo.toml", ".git" },
+ single_file_support = true,
+ capabilities = {
+ experimental = {
+ serverStatusNotification = true,
+ },
+ },
+ before_init = function(init_params, config)
+ -- See https://github.com/rust-lang/rust-analyzer/blob/eb5da56d839ae0a9e9f50774fa3eb78eb0964550/docs/dev/lsp-extensions.md?plain=1#L26
+ if config.settings and config.settings['rust-analyzer'] then
+ init_params.initializationOptions = config.settings['rust-analyzer']
+ end
+ end,
+}
+
+-- cmd = { "socat", "-", "UNIX-CONNECT:/tmp/rust-analyzer.sock" },
diff --git a/.config/nvim/lsp/ts_ls.lua b/.config/nvim/lsp/ts_ls.lua
new file mode 100644
index 0000000..e9ef670
--- /dev/null
+++ b/.config/nvim/lsp/ts_ls.lua
@@ -0,0 +1,83 @@
+return {
+ init_options = { hostInfo = 'neovim' },
+ cmd = { 'typescript-language-server', '--stdio' },
+ filetypes = {
+ 'javascript',
+ 'javascriptreact',
+ 'javascript.jsx',
+ 'typescript',
+ 'typescriptreact',
+ 'typescript.tsx',
+ },
+ 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', 'deno.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' } }
+ or vim.list_extend(root_markers, { '.git' })
+ -- 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()
+
+ on_dir(project_root)
+ end,
+ handlers = {
+ -- handle rename request for certain code actions like extracting functions / types
+ ['_typescript.rename'] = function(_, result, ctx)
+ local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
+ vim.lsp.util.show_document({
+ uri = result.textDocument.uri,
+ range = {
+ start = result.position,
+ ['end'] = result.position,
+ },
+ }, client.offset_encoding)
+ vim.lsp.buf.rename()
+ return vim.NIL
+ end,
+ },
+ commands = {
+ ['editor.action.showReferences'] = function(command, ctx)
+ local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
+ local file_uri, position, references = unpack(command.arguments)
+
+ local quickfix_items = vim.lsp.util.locations_to_items(references, client.offset_encoding)
+ vim.fn.setqflist({}, ' ', {
+ title = command.title,
+ items = quickfix_items,
+ context = {
+ command = command,
+ bufnr = ctx.bufnr,
+ },
+ })
+
+ vim.lsp.util.show_document({
+ uri = file_uri,
+ range = {
+ start = position,
+ ['end'] = position,
+ },
+ }, client.offset_encoding)
+
+ vim.cmd('botright copen')
+ end,
+ },
+ on_attach = function(client, bufnr)
+ -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in
+ -- `vim.lsp.buf.code_action()` if specified in `context.only`.
+ vim.api.nvim_buf_create_user_command(bufnr, 'LspTypescriptSourceAction', function()
+ local source_actions = vim.tbl_filter(function(action)
+ return vim.startswith(action, 'source.')
+ end, client.server_capabilities.codeActionProvider.codeActionKinds)
+
+ vim.lsp.buf.code_action({
+ context = {
+ diagnostics = {},
+ only = source_actions,
+ },
+ })
+ end, {})
+ end,
+}
diff --git a/.config/nvim/lsp/ty.lua b/.config/nvim/lsp/ty.lua
new file mode 100644
index 0000000..a5503ea
--- /dev/null
+++ b/.config/nvim/lsp/ty.lua
@@ -0,0 +1,13 @@
+return {
+ -- init_options = {
+ -- logLevel = "debug",
+ -- logFile = "/tmp/ty.log",
+ -- },
+ cmd = { "ty", "server" },
+ filetypes = { "python" },
+ root_markers = {
+ "ty.toml",
+ "pyproject.toml",
+ ".git",
+ },
+}