summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2022-07-02 17:58:32 -0500
committerBobby Bingham <koorogi@koorogi.info>2022-07-09 17:55:30 -0500
commit53df8a59580f1f866ea377e75fe14880d8db8fbb (patch)
treef77bb57b0fbe06c4d338284dd6a72da4cdf8bf06
parent1dcf6c6067b8da61b18982f2bae8d5f10bacd7d3 (diff)
nvim: eslint and prettier for typescript
-rw-r--r--nvim/.config/nvim/lua/lsp_config.lua45
-rw-r--r--nvim/.config/nvim/lua/plugins.lua4
2 files changed, 39 insertions, 10 deletions
diff --git a/nvim/.config/nvim/lua/lsp_config.lua b/nvim/.config/nvim/lua/lsp_config.lua
index 63a51d8..4bb64bf 100644
--- a/nvim/.config/nvim/lua/lsp_config.lua
+++ b/nvim/.config/nvim/lua/lsp_config.lua
@@ -1,11 +1,5 @@
--- Mappings.
--- See `:help vim.diagnostic.*` for documentation on any of the below functions
-
-local map = function(mode, lhs, rhs, opts)
- vim.api.nvim_set_keymap(mode, lhs, rhs, opts or {
- noremap = true, silent = true
- })
-end
+local lspconfig = require('lspconfig')
+local null_ls = require("null-ls")
local buf_map = function(bufnr, mode, lhs, rhs, opts)
vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts or {
@@ -50,17 +44,48 @@ local on_attach = function(client, bufnr)
buf_map(bufnr, 'n', '<space>rn', ':LspRename<cr>')
buf_map(bufnr, 'n', '<space>ca', ':LspCodeAction<cr>')
buf_map(bufnr, 'n', '<space>f', ':LspFormatting<cr>')
+
+ if client.resolved_capabilities.document_formatting then
+ vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()")
+ end
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'tsserver', 'zls' }
for _, lsp in pairs(servers) do
- require('lspconfig')[lsp].setup {
+ lspconfig[lsp].setup({
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
- }
+ })
end
+
+-- overrides for typescript
+lspconfig.tsserver.setup {
+ on_attach = function(client, bufnr)
+ -- disable tsserver's formatting; we'll use prettier instead
+ client.resolved_capabilities.document_formatting = false
+ client.resolved_capabilities.document_range_formatting = false
+
+ local ts_utils = require("nvim-lsp-ts-utils")
+ ts_utils.setup({})
+ ts_utils.setup_client(client)
+ buf_map(bufnr, "n", "gs", ":TSLspOrganize<cr>")
+ --buf_map(bufnr, "n", "gi", ":TSLspRenameFile<cr>")
+ buf_map(bufnr, "n", "go", ":TSLspImportAll<cr>")
+
+ on_attach(client, bufnr)
+ end
+}
+
+null_ls.setup({
+ sources = {
+ null_ls.builtins.diagnostics.eslint, -- eslint or eslint_d
+ null_ls.builtins.code_actions.eslint, -- eslint or eslint_d
+ null_ls.builtins.formatting.prettierd -- prettier, eslint, eslint_d, or prettierd
+ },
+ on_attach = on_attach,
+})
diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua
index b54d4ee..ae53f90 100644
--- a/nvim/.config/nvim/lua/plugins.lua
+++ b/nvim/.config/nvim/lua/plugins.lua
@@ -36,6 +36,10 @@ return require('packer').startup(function()
use {
'neovim/nvim-lspconfig',
+ requires = {
+ "jose-elias-alvarez/null-ls.nvim",
+ "jose-elias-alvarez/nvim-lsp-ts-utils",
+ },
config = function() require('lsp_config') end
}