From b5aab4aadb3e62096d5d3d727958dd0f94cb783a Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 9 Apr 2022 19:38:57 +0200 Subject: [PATCH] refactor: nvim autoformatter / lsp --- configs/nvim/init.lua | 4 +-- configs/nvim/lua/autocommands.lua | 6 ++++ configs/nvim/lua/keymappings.lua | 8 ++++- configs/nvim/lua/lsp-conf.lua | 48 -------------------------- configs/nvim/lua/lspinstaller-conf.lua | 15 ++++---- configs/nvim/lua/plugins.lua | 3 +- configs/zathura/zathurarc | 1 + 7 files changed, 25 insertions(+), 60 deletions(-) create mode 100644 configs/zathura/zathurarc diff --git a/configs/nvim/init.lua b/configs/nvim/init.lua index 357f930..fca7ba2 100644 --- a/configs/nvim/init.lua +++ b/configs/nvim/init.lua @@ -166,7 +166,7 @@ if u.has_plugin("cmp") then cmd("highlight Normal guibg=none") cmd("highlight NonText guibg=none") - require("formatter-conf") + -- Configure nvim-tree g.nvim_tree_special_files = {} @@ -291,7 +291,7 @@ if u.has_plugin("cmp") then -- LSP Config require "lspinstaller-conf" - require "lsp-conf" + -- require "lsp-conf" else vim.cmd [[PackerSync]] end diff --git a/configs/nvim/lua/autocommands.lua b/configs/nvim/lua/autocommands.lua index b461ad3..4951e8e 100644 --- a/configs/nvim/lua/autocommands.lua +++ b/configs/nvim/lua/autocommands.lua @@ -26,3 +26,9 @@ augroup SaveManualFolds au BufWinEnter ?* silent! loadview augroup END ]] + +vim.api.nvim_create_autocmd("BufWritePre",{ + callback = function() + vim.lsp.buf.formatting_sync(); + end +}) diff --git a/configs/nvim/lua/keymappings.lua b/configs/nvim/lua/keymappings.lua index 92038e6..f4bfb08 100644 --- a/configs/nvim/lua/keymappings.lua +++ b/configs/nvim/lua/keymappings.lua @@ -7,7 +7,7 @@ local remap = {noremap = false} g.mapleader = " " -map("n", "", ":Telescope find_files", options) +map("n", "", ":Telescope find_files", options) map("n", "", ":Telescope live_grep", options) map("n", "", "za", options) @@ -30,6 +30,9 @@ map("n", "", "h", options) map("n", "", "j", options) map("n", "", "k", options) map("n", "", "l", options) +-- Browser like next/previous +map("n", "", ":bprevious",options); +map("n", "", ":bnext",options); map("n", "Y", "yy", options) map("n", "k", "{", options) @@ -53,6 +56,9 @@ map("n", "gdh", ":diffget //2", options) -- Find file in NvimTree map("n", "f", ":NvimTreeFindFile", options) +map("n", "",":vsplit",options); +map("n", "",":split",options); + -- I aint no weak boy map("n", "", ":echo 'No Left for you'", options) map("n", "", ":echo 'No Right for you'", options) diff --git a/configs/nvim/lua/lsp-conf.lua b/configs/nvim/lua/lsp-conf.lua index a0301b6..2a0c516 100644 --- a/configs/nvim/lua/lsp-conf.lua +++ b/configs/nvim/lua/lsp-conf.lua @@ -2,11 +2,6 @@ local lsp = require "lspconfig" local lsp_status = require("lsp-status") local ts_utils = require("nvim-lsp-ts-utils") --- function to attach completion when setting up lsp -local function on_attach(client, bufnr) - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") -end - local runtime_path = vim.split(package.path, ";") table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") @@ -60,24 +55,6 @@ lsp.grammar_guard.setup( } ) --- Go Language Server -lsp.gopls.setup { - on_attach = on_attach, - capabilities = lsp_status.capabilities -} - --- Html Setup -lsp.html.setup { - on_attach = on_attach, - capabilities = lsp_status.capabilities, - filetypes = {"html"} -} - --- Svelte Language Server -lsp.svelte.setup { - on_attach = on_attach, - capabilities = lsp_status.capabilities -} -- Typescript Language Server lsp.tsserver.setup( @@ -146,21 +123,8 @@ lsp.tsserver.setup( } ) --- JSON ls setup -lsp.jsonls.setup { - on_attach = on_attach, - capabilities = lsp_status.capabilities -} - --- JSON ls setup -lsp.cssls.setup { - on_attach = on_attach, - capabilities = lsp_status.capabilities -} - -- Setup diagnostics formaters and linters for non LSP provided files lsp.diagnosticls.setup { - on_attach = on_attach, capabilities = lsp_status.capabilities, cmd = {"diagnostic-languageserver", "--stdio"}, filetypes = { @@ -234,15 +198,3 @@ lsp.diagnosticls.setup { } } } - --- Enable diagnostics -vim.lsp.handlers["textDocument/publishDiagnostics"] = - vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, - { - underline = true, - virtual_text = false, - signs = true, - update_in_insert = true - } -) diff --git a/configs/nvim/lua/lspinstaller-conf.lua b/configs/nvim/lua/lspinstaller-conf.lua index a6b0138..379fb76 100644 --- a/configs/nvim/lua/lspinstaller-conf.lua +++ b/configs/nvim/lua/lspinstaller-conf.lua @@ -1,16 +1,15 @@ local lsp_installer = require("nvim-lsp-installer") + require("lsp-format").setup {} + lsp_installer.on_server_ready( function(server) - local opts = {} - - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end + local opts = { + on_attach = require "lsp-format".on_attach + } + -- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart) - -- server:setup(opts) - vim.cmd [[ do User LspAttachBuffers ]] + server:setup(opts) end ) diff --git a/configs/nvim/lua/plugins.lua b/configs/nvim/lua/plugins.lua index 6464c58..75cd818 100644 --- a/configs/nvim/lua/plugins.lua +++ b/configs/nvim/lua/plugins.lua @@ -75,7 +75,8 @@ return require("packer").startup( } -- Autoformat - use "sbdchd/neoformat" + -- use "sbdchd/neoformat" + use "lukas-reineke/lsp-format.nvim" -- use "lukas-reineke/format.nvim" -- General Popup Window diff --git a/configs/zathura/zathurarc b/configs/zathura/zathurarc new file mode 100644 index 0000000..ea10740 --- /dev/null +++ b/configs/zathura/zathurarc @@ -0,0 +1 @@ +set selection-clipboard clipboard