Split LSP settings into more specific files in lsp directory
This commit is contained in:
parent
ea6cf9bb24
commit
ce7fed242e
|
@ -1,3 +1,5 @@
|
|||
vim.g.mapleader = " "
|
||||
|
||||
-- bootstrap lazy.nvim
|
||||
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
|
||||
if not vim.loop.fs_stat(lazypath) then
|
||||
|
@ -12,14 +14,10 @@ if not vim.loop.fs_stat(lazypath) then
|
|||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
vim.g.mapleader = " "
|
||||
require("lazy").setup("plugins")
|
||||
|
||||
require("lazy").setup "plugins"
|
||||
-- Set vim options
|
||||
require "options"
|
||||
|
||||
-- Define custom keymappings
|
||||
require "keymaps"
|
||||
|
||||
-- Remaining vim commands to be converted to lua
|
||||
require "vimcommands"
|
||||
|
|
23
config/nvim/lua/lsp/attach.lua
Normal file
23
config/nvim/lua/lsp/attach.lua
Normal file
|
@ -0,0 +1,23 @@
|
|||
-- Use an on_attach function to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
local on_attach = function(_, bufnr)
|
||||
-- Mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.definition, bufopts)
|
||||
vim.keymap.set("n", "gd", "<cmd>Trouble lsp_definitions<cr>", bufopts)
|
||||
vim.keymap.set("n", "gR", vim.lsp.buf.references, bufopts)
|
||||
vim.keymap.set("n", "gr", "<cmd>Trouble lsp_references<cr>", bufopts)
|
||||
vim.keymap.set("n", "gI", vim.lsp.buf.implementation, bufopts)
|
||||
vim.keymap.set("n", "gi", "<cmd>Trouble lsp_implementations<cr>", bufopts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
|
||||
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
|
||||
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
|
||||
vim.keymap.set("n", "<leader>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts)
|
||||
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
||||
vim.keymap.set("n", "<leader>i", require "lsp.formatting", bufopts)
|
||||
end
|
||||
return on_attach
|
5
config/nvim/lua/lsp/flags.lua
Normal file
5
config/nvim/lua/lsp/flags.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
local lsp_flags = {
|
||||
-- This is the default in Nvim 0.7+
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
return lsp_flags
|
9
config/nvim/lua/lsp/formatting.lua
Normal file
9
config/nvim/lua/lsp/formatting.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
local lsp_formatting = function(bufnr)
|
||||
vim.lsp.buf.format {
|
||||
filter = function(client) return client.name == "null-ls" end,
|
||||
bufnr = bufnr,
|
||||
timeout_ms = 2000,
|
||||
-- async = true,
|
||||
}
|
||||
end
|
||||
return lsp_formatting
|
|
@ -12,45 +12,10 @@ for type, icon in pairs(signs) do
|
|||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
||||
end
|
||||
|
||||
local lsp_formatting = function(bufnr)
|
||||
vim.lsp.buf.format {
|
||||
filter = function(client) return client.name == "null-ls" end,
|
||||
bufnr = bufnr,
|
||||
timeout_ms = 2000,
|
||||
-- async = true,
|
||||
}
|
||||
end
|
||||
|
||||
-- Use an on_attach function to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
local on_attach = function(_, bufnr)
|
||||
-- Mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local bufopts = { noremap = true, silent = true, buffer = bufnr }
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.definition, bufopts)
|
||||
vim.keymap.set("n", "gd", "<cmd>Trouble lsp_definitions<cr>", bufopts)
|
||||
vim.keymap.set("n", "gR", vim.lsp.buf.references, bufopts)
|
||||
vim.keymap.set("n", "gr", "<cmd>Trouble lsp_references<cr>", bufopts)
|
||||
vim.keymap.set("n", "gI", vim.lsp.buf.implementation, bufopts)
|
||||
vim.keymap.set("n", "gi", "<cmd>Trouble lsp_implementations<cr>", bufopts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
|
||||
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
|
||||
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
|
||||
vim.keymap.set("n", "<leader>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts)
|
||||
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
|
||||
vim.keymap.set("n", "<leader>i", lsp_formatting, bufopts)
|
||||
end
|
||||
|
||||
local lsp_flags = {
|
||||
-- This is the default in Nvim 0.7+
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
|
||||
require("neodev").setup()
|
||||
|
||||
local on_attach = require "lsp.attach"
|
||||
local lsp_flags = require "lsp.flags"
|
||||
local lspconfig = require "lspconfig"
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
|
@ -78,20 +43,8 @@ lspconfig.texlab.setup {
|
|||
capabilities = capabilities,
|
||||
}
|
||||
|
||||
local null_ls = require "null-ls"
|
||||
null_ls.setup {
|
||||
sources = {
|
||||
null_ls.builtins.code_actions.gitsigns,
|
||||
null_ls.builtins.diagnostics.mypy,
|
||||
null_ls.builtins.diagnostics.zsh,
|
||||
null_ls.builtins.formatting.black,
|
||||
null_ls.builtins.formatting.isort,
|
||||
null_ls.builtins.formatting.trim_whitespace,
|
||||
null_ls.builtins.formatting.stylua,
|
||||
null_ls.builtins.formatting.shfmt,
|
||||
null_ls.builtins.formatting.prettier,
|
||||
null_ls.builtins.hover.dictionary,
|
||||
},
|
||||
require("null-ls").setup {
|
||||
sources = require "lsp.null_ls_sources",
|
||||
on_attach = on_attach,
|
||||
flags = lsp_flags,
|
||||
capabilities = capabilities,
|
||||
|
|
13
config/nvim/lua/lsp/null_ls_sources.lua
Normal file
13
config/nvim/lua/lsp/null_ls_sources.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
local null_ls = require "null-ls"
|
||||
return {
|
||||
null_ls.builtins.code_actions.gitsigns,
|
||||
null_ls.builtins.diagnostics.mypy,
|
||||
null_ls.builtins.diagnostics.zsh,
|
||||
null_ls.builtins.formatting.black,
|
||||
null_ls.builtins.formatting.isort,
|
||||
null_ls.builtins.formatting.trim_whitespace,
|
||||
null_ls.builtins.formatting.stylua,
|
||||
null_ls.builtins.formatting.shfmt,
|
||||
null_ls.builtins.formatting.prettier,
|
||||
null_ls.builtins.hover.dictionary,
|
||||
}
|
Loading…
Reference in a new issue