Compare commits

..

3 Commits

2 changed files with 17 additions and 10 deletions

View File

@ -5,6 +5,12 @@ local on_attach = function(client, bufnr)
vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr }) vim.keymap.set("n", key, command, { noremap = true, silent = true, buffer = bufnr })
end end
local function format_buffer()
vim.lsp.buf.format({ timeout_ms = 3000, async = false, filter = function(formatter)
return formatter.name ~= "tsserver" and formatter.name ~= "volar"
end })
end
local telescope = require("telescope.builtin") local telescope = require("telescope.builtin")
nnoremap("gD", vim.lsp.buf.declaration) nnoremap("gD", vim.lsp.buf.declaration)
@ -15,25 +21,18 @@ local on_attach = function(client, bufnr)
nnoremap("K", vim.lsp.buf.hover) nnoremap("K", vim.lsp.buf.hover)
nnoremap("<leader>rn", vim.lsp.buf.rename) nnoremap("<leader>rn", vim.lsp.buf.rename)
nnoremap("<leader>ca", vim.lsp.buf.code_action) nnoremap("<leader>ca", vim.lsp.buf.code_action)
nnoremap("<leader>f", vim.lsp.buf.format) nnoremap("<leader>f", format_buffer)
nnoremap("<leader>d", telescope.diagnostics) nnoremap("<leader>d", telescope.diagnostics)
nnoremap("<leader>D", require("lsp_lines").toggle) nnoremap("<leader>D", require("lsp_lines").toggle)
nnoremap("<C-p>", vim.diagnostic.goto_prev) nnoremap("<C-p>", vim.diagnostic.goto_prev)
nnoremap("<C-n>", vim.diagnostic.goto_next) nnoremap("<C-n>", vim.diagnostic.goto_next)
-- disable tsserver formatting
if client.name == "tsserver" then
client.server_capabilities.document_formatting = false
end
if client.supports_method("textDocument/formatting") then if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", { vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup, group = augroup,
buffer = bufnr, buffer = bufnr,
callback = function() callback = format_buffer,
vim.lsp.buf.format({ timeout_ms = 3000, async = false })
end,
}) })
end end
@ -155,3 +154,11 @@ lspconfig["html"].setup({
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
}) })
-- setup volar
lspconfig["volar"].setup({
cmd = { "./node_modules/.bin/vue-language-server", "--stdio" },
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' },
on_attach = on_attach,
capabilities = capabilities,
})

View File

@ -4,7 +4,7 @@ require('nvim-treesitter.configs').setup({
additional_vim_regex_highlighting = false additional_vim_regex_highlighting = false
}, },
indent = { indent = {
enable = true, enable = false,
}, },
rainbow = { rainbow = {
enable = true, enable = true,