From 3cbb6ce825174fd7ac9057d631163caa1264591b Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Wed, 19 Oct 2022 23:56:02 -0700 Subject: [PATCH] add eslint_d/prettierd --- lua/commands.lua | 3 +++ lua/configs/lspconfig.lua | 7 +++---- lua/configs/null-ls.lua | 33 +++++++++++---------------------- lua/configs/prettier.lua | 14 ++++++++++++++ lua/plugins.lua | 12 ++++-------- 5 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 lua/configs/prettier.lua diff --git a/lua/commands.lua b/lua/commands.lua index 1f552a4..d45f03a 100644 --- a/lua/commands.lua +++ b/lua/commands.lua @@ -4,3 +4,6 @@ vim.api.nvim_create_user_command('Black', 'call Black()', {}) -- Insert IPDB statement vim.api.nvim_create_user_command('IPDB', 'norm oimport ipdb; ipdb.set_trace() # fmt:skip', {}) +-- Format the document +vim.api.nvim_create_user_command('Format', 'lua vim.lsp.buf.format()', {}) + diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua index b3f5e5d..ea26f18 100644 --- a/lua/configs/lspconfig.lua +++ b/lua/configs/lspconfig.lua @@ -86,12 +86,12 @@ function M.config() lsp_highlight_document(client) end - local sumneko_root_path = '/home/peters/builds/lua-language-server' - local sumneko_binary = sumneko_root_path.."/bin/lua-language-server" + -- local sumneko_root_path = '/home/peters/builds/lua-language-server' + -- local sumneko_binary = sumneko_root_path.."/bin/lua-language-server" -- lua-language-server -- pacman -S lua-language-server lspconfig.sumneko_lua.setup { - cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" }, + -- cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" }, on_attach = on_attach, settings = { Lua = { @@ -148,7 +148,6 @@ function M.config() lspconfig.tsserver.setup { on_attach = on_attach, } - end return M diff --git a/lua/configs/null-ls.lua b/lua/configs/null-ls.lua index 60f2cce..38bb17c 100644 --- a/lua/configs/null-ls.lua +++ b/lua/configs/null-ls.lua @@ -6,31 +6,20 @@ function M.config() return end - -- Check supported formatters - -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting - local formatting = null_ls.builtins.formatting - - -- Check supported linters - -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics - local diagnostics = null_ls.builtins.diagnostics - null_ls.setup { - debug = false, sources = { - -- Set a formatter - --formatting.prettierd, - --TODO: formatting.black, + -- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md - -- Set a linter - --diagnostics.eslint_d, - --TODO: pylint - }, - -- Format before save - on_attach = function(client) - if client.resolved_capabilities.document_formatting then - vim.cmd "autocmd BufWritePre lua vim.lsp.buf.formatting_sync()" - end - end, + -- sudo pacman -S prettierd + null_ls.builtins.formatting.prettierd, + + -- sudo pacman -S eslint_d + null_ls.builtins.diagnostics.eslint_d.with({ + diagnostic_config = { -- see also :help vim.diagnostic.config() + virtual_text = false, + } + }), + } } end diff --git a/lua/configs/prettier.lua b/lua/configs/prettier.lua new file mode 100644 index 0000000..a2f41c9 --- /dev/null +++ b/lua/configs/prettier.lua @@ -0,0 +1,14 @@ +local M = {} + +function M.config() + local status_ok, prettier = pcall(require, "prettier") + if not status_ok then + return + end + + prettier.setup({ + bin = 'prettierd' + }) +end + +return M diff --git a/lua/plugins.lua b/lua/plugins.lua index cdbbcd8..98e6f1b 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -94,7 +94,7 @@ packer.startup { use { 'JoosepAlviste/nvim-ts-context-commentstring', after = 'nvim-treesitter' } -- Show context - use { 'nvim-treesitter/nvim-treesitter-context', config = function() require'configs.treesitter-context'.config() end } + --use { 'nvim-treesitter/nvim-treesitter-context', config = function() require'configs.treesitter-context'.config() end } -- -- LSP @@ -113,13 +113,6 @@ packer.startup { config = function() require'configs.lspconfig'.config() end } - -- Formatting + Linting - use { - 'jose-elias-alvarez/null-ls.nvim', - event = 'BufRead', - config = function() require'configs.null-ls'.config() end - } - -- TODO: LSP Enhancer use { 'tami5/lspsaga.nvim', @@ -129,6 +122,9 @@ packer.startup { -- TODO: Symbols Outline -- use { 'simrat39'/symbols-outline.nvim', cmd = 'SymbolsOutline', setup = function ... } + -- null-ls LSP injector + use { 'jose-elias-alvarez/null-ls.nvim', config = function() require'configs.null-ls'.config() end } + -- -- Autocompletion --