move lsp config into a folder
This commit is contained in:
parent
d15112bc7d
commit
2b88ac6e5d
2 changed files with 144 additions and 141 deletions
|
|
@ -1,141 +0,0 @@
|
||||||
return {
|
|
||||||
'VonHeikemen/lsp-zero.nvim',
|
|
||||||
branch = 'v2.x',
|
|
||||||
dependencies = {
|
|
||||||
-- LSP Support
|
|
||||||
{ 'neovim/nvim-lspconfig' }, -- Required
|
|
||||||
{
|
|
||||||
-- Optional
|
|
||||||
'williamboman/mason.nvim',
|
|
||||||
build = function()
|
|
||||||
pcall(vim.cmd, 'MasonUpdate')
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional
|
|
||||||
|
|
||||||
-- Autocompletion
|
|
||||||
{ 'hrsh7th/nvim-cmp' }, -- Required
|
|
||||||
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required
|
|
||||||
{ 'L3MON4D3/LuaSnip' }, -- Required
|
|
||||||
|
|
||||||
-- Neovim Plugin Development Completions
|
|
||||||
{
|
|
||||||
'folke/neodev.nvim',
|
|
||||||
opts = {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
-- required to setup neodev before lspconfig
|
|
||||||
require('neodev').setup({})
|
|
||||||
|
|
||||||
local lspzero = require("lsp-zero")
|
|
||||||
|
|
||||||
lspzero.preset({})
|
|
||||||
|
|
||||||
lspzero.on_attach(function(client, bufnr)
|
|
||||||
lspzero.default_keymaps({
|
|
||||||
buffer = bufnr,
|
|
||||||
omit = {
|
|
||||||
'gr'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
function nmap(key, action, desc)
|
|
||||||
vim.keymap.set(
|
|
||||||
"n",
|
|
||||||
key,
|
|
||||||
action,
|
|
||||||
{
|
|
||||||
desc = "LSP: " .. desc,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
nmap("[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Goto Prev Diagnostic");
|
|
||||||
nmap("]d", "<cmd>lua vim.diagnostic.goto_next()<CR>", "Goto Next Diagnostic")
|
|
||||||
|
|
||||||
local current_dir = vim.fn.expand("%:p:h")
|
|
||||||
|
|
||||||
-- vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<cr>', { buffer = true })
|
|
||||||
|
|
||||||
-- format with space + f
|
|
||||||
-- vim.keymap.set("n", "<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>",
|
|
||||||
-- { desc = "[F]ormat [B]uffer" })
|
|
||||||
nmap("<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>", "[F]ormat [B]uffer")
|
|
||||||
end)
|
|
||||||
|
|
||||||
lspzero.ensure_installed({
|
|
||||||
"tsserver",
|
|
||||||
"eslint",
|
|
||||||
"tailwindcss",
|
|
||||||
})
|
|
||||||
|
|
||||||
lspzero.format_on_save({
|
|
||||||
format_ops = {
|
|
||||||
async = true,
|
|
||||||
timeout_ms = 10000,
|
|
||||||
},
|
|
||||||
servers = {
|
|
||||||
["lua_ls"] = { "lua" },
|
|
||||||
["null-ls"] = {
|
|
||||||
"javascript",
|
|
||||||
"typescript",
|
|
||||||
"javascriptreact",
|
|
||||||
"typescriptreact",
|
|
||||||
"html",
|
|
||||||
"css",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
local status, lspconfig = pcall(require, "lspconfig")
|
|
||||||
|
|
||||||
if status then
|
|
||||||
lspconfig.tsserver.setup({})
|
|
||||||
lspconfig.tailwindcss.setup({
|
|
||||||
filetypes = {
|
|
||||||
'templ',
|
|
||||||
'html',
|
|
||||||
'javascript',
|
|
||||||
'typescript',
|
|
||||||
'javascriptreact',
|
|
||||||
'typescriptreact',
|
|
||||||
},
|
|
||||||
init_options = {
|
|
||||||
userLanguages = {
|
|
||||||
templ = "html"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
lspconfig.zls.setup({})
|
|
||||||
lspconfig.rust_analyzer.setup({})
|
|
||||||
lspconfig.gopls.setup({})
|
|
||||||
lspconfig.html.setup({})
|
|
||||||
vim.filetype.add({
|
|
||||||
extension = {
|
|
||||||
templ = "templ"
|
|
||||||
},
|
|
||||||
})
|
|
||||||
lspconfig.templ.setup({
|
|
||||||
filetypes = {
|
|
||||||
"templ",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
lspzero.setup()
|
|
||||||
|
|
||||||
local cmp
|
|
||||||
status, cmp = pcall(require, "cmp")
|
|
||||||
|
|
||||||
if not status then return end
|
|
||||||
|
|
||||||
cmp.setup({
|
|
||||||
mapping = {
|
|
||||||
-- press 'enter' to confirm completion/suggestion
|
|
||||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
|
||||||
['<C-e>'] = cmp.mapping.abort(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end
|
|
||||||
}
|
|
||||||
144
nvim/lua/juancwu/plugins/lsp/init.lua
Normal file
144
nvim/lua/juancwu/plugins/lsp/init.lua
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
return {
|
||||||
|
-- lspconfig
|
||||||
|
{
|
||||||
|
'VonHeikemen/lsp-zero.nvim',
|
||||||
|
branch = 'v2.x',
|
||||||
|
dependencies = {
|
||||||
|
-- LSP Support
|
||||||
|
{ 'neovim/nvim-lspconfig' }, -- Required
|
||||||
|
{
|
||||||
|
-- Optional
|
||||||
|
'williamboman/mason.nvim',
|
||||||
|
build = function()
|
||||||
|
pcall(vim.cmd, 'MasonUpdate')
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional
|
||||||
|
|
||||||
|
-- Autocompletion
|
||||||
|
{ 'hrsh7th/nvim-cmp' }, -- Required
|
||||||
|
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required
|
||||||
|
{ 'L3MON4D3/LuaSnip' }, -- Required
|
||||||
|
|
||||||
|
-- Neovim Plugin Development Completions
|
||||||
|
{
|
||||||
|
'folke/neodev.nvim',
|
||||||
|
opts = {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
-- required to setup neodev before lspconfig
|
||||||
|
require('neodev').setup({})
|
||||||
|
|
||||||
|
local lspzero = require("lsp-zero")
|
||||||
|
|
||||||
|
lspzero.preset({})
|
||||||
|
|
||||||
|
lspzero.on_attach(function(client, bufnr)
|
||||||
|
lspzero.default_keymaps({
|
||||||
|
buffer = bufnr,
|
||||||
|
omit = {
|
||||||
|
'gr'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function nmap(key, action, desc)
|
||||||
|
vim.keymap.set(
|
||||||
|
"n",
|
||||||
|
key,
|
||||||
|
action,
|
||||||
|
{
|
||||||
|
desc = "LSP: " .. desc,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
nmap("[d", "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Goto Prev Diagnostic");
|
||||||
|
nmap("]d", "<cmd>lua vim.diagnostic.goto_next()<CR>", "Goto Next Diagnostic")
|
||||||
|
|
||||||
|
local current_dir = vim.fn.expand("%:p:h")
|
||||||
|
|
||||||
|
-- vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<cr>', { buffer = true })
|
||||||
|
|
||||||
|
-- format with space + f
|
||||||
|
-- vim.keymap.set("n", "<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>",
|
||||||
|
-- { desc = "[F]ormat [B]uffer" })
|
||||||
|
nmap("<leader>fb", "<cmd>lua vim.lsp.buf.format()<CR>", "[F]ormat [B]uffer")
|
||||||
|
end)
|
||||||
|
|
||||||
|
lspzero.ensure_installed({
|
||||||
|
"tsserver",
|
||||||
|
"eslint",
|
||||||
|
"tailwindcss",
|
||||||
|
})
|
||||||
|
|
||||||
|
lspzero.format_on_save({
|
||||||
|
format_ops = {
|
||||||
|
async = true,
|
||||||
|
timeout_ms = 10000,
|
||||||
|
},
|
||||||
|
servers = {
|
||||||
|
["lua_ls"] = { "lua" },
|
||||||
|
["null-ls"] = {
|
||||||
|
"javascript",
|
||||||
|
"typescript",
|
||||||
|
"javascriptreact",
|
||||||
|
"typescriptreact",
|
||||||
|
"html",
|
||||||
|
"css",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
local status, lspconfig = pcall(require, "lspconfig")
|
||||||
|
|
||||||
|
if status then
|
||||||
|
lspconfig.tsserver.setup({})
|
||||||
|
lspconfig.tailwindcss.setup({
|
||||||
|
filetypes = {
|
||||||
|
'templ',
|
||||||
|
'html',
|
||||||
|
'javascript',
|
||||||
|
'typescript',
|
||||||
|
'javascriptreact',
|
||||||
|
'typescriptreact',
|
||||||
|
},
|
||||||
|
init_options = {
|
||||||
|
userLanguages = {
|
||||||
|
templ = "html"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
lspconfig.zls.setup({})
|
||||||
|
lspconfig.rust_analyzer.setup({})
|
||||||
|
lspconfig.gopls.setup({})
|
||||||
|
lspconfig.html.setup({})
|
||||||
|
vim.filetype.add({
|
||||||
|
extension = {
|
||||||
|
templ = "templ"
|
||||||
|
},
|
||||||
|
})
|
||||||
|
lspconfig.templ.setup({
|
||||||
|
filetypes = {
|
||||||
|
"templ",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
lspzero.setup()
|
||||||
|
|
||||||
|
local cmp
|
||||||
|
status, cmp = pcall(require, "cmp")
|
||||||
|
|
||||||
|
if not status then return end
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
mapping = {
|
||||||
|
-- press 'enter' to confirm completion/suggestion
|
||||||
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||||
|
['<C-e>'] = cmp.mapping.abort(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue