Refactored lsp and null ls configs
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# My curent Neovim config
|
# My curent Neovim config
|
||||||
|
|
||||||
Inspired by [ThePrimeagen](https://github.com/ThePrimeagen/init.lua)
|
Inspired by [ThePrimeagen](https://github.com/ThePrimeagen/init.lua) and [Josean](https://github.com/josean-dev/dev-environment-files)
|
||||||
|
|
||||||
Make sure to run `:PackerSync` so it grabs all plugins.
|
Make sure to run `:PackerSync` so it grabs all plugins.
|
||||||
You can also run `nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'`
|
You can also run `nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'`
|
||||||
|
|||||||
13
after/plugin/autopairs.lua
Normal file
13
after/plugin/autopairs.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
local autopairs_setup, autopairs = pcall(require, "nvim-autopairs")
|
||||||
|
if not autopairs_setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
autopairs.setup {
|
||||||
|
check_ts = true,
|
||||||
|
ts_config = {
|
||||||
|
lua = { "string" },
|
||||||
|
javascript = { "template_string" },
|
||||||
|
java = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -15,22 +15,6 @@ lsp.on_attach(function(client, bufnr)
|
|||||||
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local cmp = require('cmp')
|
|
||||||
local cmp_select = {behavior = cmp.SelectBehavior.Select}
|
|
||||||
local cmp_mappings = lsp.defaults.cmp_mappings({
|
|
||||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
|
||||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
|
||||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp_mappings['<Tab>'] = nil
|
|
||||||
cmp_mappings['<S-Tab>'] = nil
|
|
||||||
|
|
||||||
lsp.setup_nvim_cmp({
|
|
||||||
mapping = cmp_mappings
|
|
||||||
})
|
|
||||||
|
|
||||||
lsp.ensure_installed({
|
lsp.ensure_installed({
|
||||||
'lua_ls',
|
'lua_ls',
|
||||||
'tsserver',
|
'tsserver',
|
||||||
@@ -40,3 +24,18 @@ lspconfig.lua_ls.setup(lsp.nvim_lua_ls())
|
|||||||
lspconfig.tsserver.setup({})
|
lspconfig.tsserver.setup({})
|
||||||
|
|
||||||
lsp.setup()
|
lsp.setup()
|
||||||
|
local cmp = require('cmp')
|
||||||
|
local cmp_select = {behavior = cmp.SelectBehavior.Select}
|
||||||
|
local cmp_mappings = lsp.defaults.cmp_mappings({
|
||||||
|
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
||||||
|
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
||||||
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||||
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
|
})
|
||||||
|
|
||||||
|
lsp.setup_nvim_cmp({
|
||||||
|
mapping = cmp_mappings
|
||||||
|
})
|
||||||
|
cmp_mappings['<Tab>'] = nil
|
||||||
|
cmp_mappings['<S-Tab>'] = nil
|
||||||
|
|
||||||
58
after/plugin/lsp/lspconfig.lua
Normal file
58
after/plugin/lsp/lspconfig.lua
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
local lspconfig_status, lspconfig = pcall(require, "lspconfig")
|
||||||
|
if not lspconfig_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||||
|
if not cmp_nvim_lsp_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
local opts = { noremap = true, silent = true, buffer = bufnr }
|
||||||
|
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
|
||||||
|
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
|
||||||
|
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
|
||||||
|
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
|
||||||
|
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
|
||||||
|
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
|
||||||
|
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
|
||||||
|
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
|
||||||
|
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
|
||||||
|
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||||
|
|
||||||
|
local signs = { Error = " ", Warn = " ", Hint = "ﴞ ", Info = " " }
|
||||||
|
for type, icon in pairs(signs) do
|
||||||
|
local hl = "DiagnosticSign" .. type
|
||||||
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
||||||
|
end
|
||||||
|
|
||||||
|
lspconfig["lua_ls"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
diagnostics = {
|
||||||
|
globals = { "vim" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
lspconfig["html"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
|
||||||
|
lspconfig["tsserver"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
|
||||||
|
lspconfig["cssls"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
35
after/plugin/lsp/mason.lua
Normal file
35
after/plugin/lsp/mason.lua
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
local mason_status, mason = pcall(require, "mason")
|
||||||
|
if not mason_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local mason_lspconfig_status, mason_lspconfig = pcall(require, "mason-lspconfig")
|
||||||
|
if not mason_lspconfig_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local mason_null_ls_status, mason_null_ls = pcall(require, "mason-null-ls")
|
||||||
|
if not mason_null_ls_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
mason.setup()
|
||||||
|
|
||||||
|
mason_lspconfig.setup({
|
||||||
|
ensure_installed = {
|
||||||
|
"tsserver",
|
||||||
|
"html",
|
||||||
|
"cssls",
|
||||||
|
"lua_ls"
|
||||||
|
},
|
||||||
|
automatic_installation = true,
|
||||||
|
})
|
||||||
|
|
||||||
|
mason_null_ls.setup({
|
||||||
|
ensure_installed = {
|
||||||
|
"stylua",
|
||||||
|
"clang_format",
|
||||||
|
"eslint_d"
|
||||||
|
},
|
||||||
|
automatic_installation = true,
|
||||||
|
})
|
||||||
18
after/plugin/lsp/null-ls.lua
Normal file
18
after/plugin/lsp/null-ls.lua
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
local setup, null_ls = pcall(require, "null-ls")
|
||||||
|
if not setup then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local formatting = null_ls.builtins.formatting
|
||||||
|
local diagnostics = null_ls.builtins.diagnostics
|
||||||
|
|
||||||
|
null_ls.setup({
|
||||||
|
sources = {
|
||||||
|
formatting.stylua,
|
||||||
|
diagnostics.eslint_d.with({
|
||||||
|
condition = function(utils)
|
||||||
|
return utils.root_has_file(".eslintrc.js")
|
||||||
|
end,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
47
after/plugin/nvim-cmp.lua
Normal file
47
after/plugin/nvim-cmp.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
local cmp_status, cmp = pcall(require, "cmp")
|
||||||
|
if not cmp_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local luasnip_status, luasnip = pcall(require, "luasnip")
|
||||||
|
if not luasnip_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local lspkind_status, lspkind = pcall(require, "lspkind")
|
||||||
|
if not lspkind_status then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
require("luasnip/loaders/from_vscode").lazy_load()
|
||||||
|
|
||||||
|
vim.opt.completeopt = "menu,menuone,noselect"
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
["<C-p>"] = cmp.mapping.select_prev_item(), -- previous suggestion
|
||||||
|
["<C-n>"] = cmp.mapping.select_next_item(), -- next suggestion
|
||||||
|
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
|
||||||
|
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
||||||
|
['<Tab>'] = nil,
|
||||||
|
['<S-Tab>'] = nil
|
||||||
|
}),
|
||||||
|
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = "nvim_lsp" }, -- lsp
|
||||||
|
{ name = "luasnip" }, -- snippets
|
||||||
|
{ name = "buffer" }, -- text within current buffer
|
||||||
|
{ name = "path" }, -- file system paths
|
||||||
|
}),
|
||||||
|
formatting = {
|
||||||
|
format = lspkind.cmp_format({
|
||||||
|
maxwidth = 50,
|
||||||
|
ellipsis_char = "...",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user