From b5489face89e98f77633733eaf5f14c27709f0b7 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 22 Feb 2022 09:27:45 +0100 Subject: [PATCH] feat: add lua-format to lsp --- lua/options.lua | 4 +- lua/plugins.lua | 157 ++++++++++++++++++-------------------- lua/plugins/lspconfig.lua | 50 +++++------- 3 files changed, 98 insertions(+), 113 deletions(-) diff --git a/lua/options.lua b/lua/options.lua index 6ec3a60..b865a1d 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -52,6 +52,6 @@ vim.cmd([[ vim.g.coq_settings = { auto_start = "shut-up", keymap = { - jump_to_mark = "", -- prevent remapping - }, + jump_to_mark = "" -- prevent remapping + } } diff --git a/lua/plugins.lua b/lua/plugins.lua index 19af637..8397d52 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,10 +1,13 @@ local fn = vim.fn -- boostrap packer -local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim' +local install_path = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim' local packer_bootstrap if fn.empty(fn.glob(install_path)) > 0 then - packer_bootstrap = fn.system({'git', 'clone','https://github.com/wbthomason/packer.nvim', install_path}) + packer_bootstrap = fn.system({ + 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', + install_path + }) end -- run PackerSync everytime plugins.lua is updated @@ -19,94 +22,91 @@ vim.cmd([[packadd packer.nvim]]) -- initialize plugins return require('packer').startup(function(use) - -- let packer manage itself - use({'wbthomason/packer.nvim', opt = true}) + -- let packer manage itself + use({'wbthomason/packer.nvim', opt = true}) - -- theme + -- theme use("ishan9299/nvim-solarized-lua") -- commenting use("tpope/vim-commentary") - -- session handling - use('tpope/vim-obsession') - use('dhruvasagar/vim-prosession') + -- session handling + use('tpope/vim-obsession') + use('dhruvasagar/vim-prosession') - -- status line - use { - 'nvim-lualine/lualine.nvim', - requires = { 'kyazdani42/nvim-web-devicons', opt = true }, - config = function() - require('lualine').setup() - end - } + -- status line + use { + 'nvim-lualine/lualine.nvim', + requires = {'kyazdani42/nvim-web-devicons', opt = true}, + config = function() require('lualine').setup() end + } - -- tabline - use { - 'kdheepak/tabline.nvim', - config = function() - require'tabline'.setup { - enable = true, - options = { - show_filename_only = true, - } - } - end, - requires = { { 'hoob3rt/lualine.nvim' }, {'kyazdani42/nvim-web-devicons', opt = true} } - } + -- tabline + use { + 'kdheepak/tabline.nvim', + config = function() + require'tabline'.setup { + enable = true, + options = {show_filename_only = true} + } + end, + requires = { + {'hoob3rt/lualine.nvim'}, + {'kyazdani42/nvim-web-devicons', opt = true} + } + } - -- blankline - use({ - "lukas-reineke/indent-blankline.nvim", - config = function () - require("indent_blankline").setup { - char = "┊", - buftype_exclude = {"terminal", "help"} - } - end - }) + -- blankline + use({ + "lukas-reineke/indent-blankline.nvim", + config = function() + require("indent_blankline").setup { + char = "┊", + buftype_exclude = {"terminal", "help"} + } + end + }) - -- git - use('tpope/vim-fugitive') - use ({ - 'lewis6991/gitsigns.nvim', - requires = {'nvim-lua/plenary.nvim'}, - config = function() require('gitsigns').setup() end - }) + -- git + use('tpope/vim-fugitive') + use({ + 'lewis6991/gitsigns.nvim', + requires = {'nvim-lua/plenary.nvim'}, + config = function() require('gitsigns').setup() end + }) - -- autocompletion - use({ - "ms-jpq/coq_nvim", - branch="coq", - requires = { - {'ms-jpq/coq.artifacts', branch = 'artifacts'}, - }, - }) + -- autocompletion + use({ + "ms-jpq/coq_nvim", + branch = "coq", + requires = {{'ms-jpq/coq.artifacts', branch = 'artifacts'}} + }) -- highlight current symbol use({"RRethy/vim-illuminate"}) - -- language server - use({ - "neovim/nvim-lspconfig", - config = function() require("plugins.lspconfig") end, - }) + -- language server + use({ + "neovim/nvim-lspconfig", + config = function() require("plugins.lspconfig") end + }) use('williamboman/nvim-lsp-installer') - -- treesitter - use({ - 'nvim-treesitter/nvim-treesitter', - config = function() require('plugins.treesitter') end, - run = ':TSUpdate' - }) + -- treesitter + use({ + 'nvim-treesitter/nvim-treesitter', + config = function() require('plugins.treesitter') end, + run = ':TSUpdate' + }) - -- Telescope - use({ - 'nvim-telescope/telescope.nvim', - requires = {{'nvim-lua/plenary.nvim'}}, - config = function() require('plugins.telescope') end, - }) + -- Telescope + use({ + 'nvim-telescope/telescope.nvim', + requires = {{'nvim-lua/plenary.nvim'}}, + config = function() require('plugins.telescope') end + }) -- automatic pairs use({"Raimondi/delimitMate"}) @@ -118,22 +118,15 @@ return require('packer').startup(function(use) use({ "akinsho/nvim-toggleterm.lua", config = function() - require("toggleterm").setup({ - size = 32, - open_mapping = [[]], - }) - end, + require("toggleterm").setup({size = 32, open_mapping = [[]]}) + end }) -- buffer closing - use({ - "sar/bbye.nvim" - }) + use({"sar/bbye.nvim"}) -- ansible filetype use({"pearofducks/ansible-vim"}) - if packer_bootstrap then - require('packer').sync() - end + if packer_bootstrap then require('packer').sync() end end) diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index c181288..5329850 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -6,18 +6,8 @@ table.insert(nvim_runtime_path, "lua/?.lua") table.insert(nvim_runtime_path, "lua/?/init.lua") local language_servers = { - "ansiblels", - "bashls", - "dockerls", - "eslint", - "html", - "pyright", - "rust_analyzer", - "sumneko_lua", - "svelte", - "taplo", - "tsserver", - "volar", + "ansiblels", "bashls", "dockerls", "efm", "eslint", "html", "pyright", + "rust_analyzer", "sumneko_lua", "svelte", "taplo", "tsserver", "volar" } for _, server_name in pairs(language_servers) do @@ -30,30 +20,31 @@ for _, server_name in pairs(language_servers) do end local extra_server_opts = { + ["efm"] = function(opts) + opts.filetypes = {"lua"} + opts.init_options = {documentFormatting = true} + opts.settings = { + rootMarkers = {".git/"}, + languages = { + lua = {{formatCommand = "lua-format -i", formatStdin = true}} + } + } + end, ["sumneko_lua"] = function(opts) opts.settings = { Lua = { - runtime = { - version = 'LuaJIT', - path = nvim_runtime_path, - }, - diagnostics = { - globals = {'vim'}, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry ={ - enable = false, - }, - }, + runtime = {version = 'LuaJIT', path = nvim_runtime_path}, + diagnostics = {globals = {'vim'}}, + workspace = {library = vim.api.nvim_get_runtime_file("", true)}, + telemetry = {enable = false} + } } end } local function custom_on_attach(client, buffer_nr) -- onmifunc - vim.api.nvim_buf_set_option(0, "omnifunc", "v:lua.vim.lsp.omnifunc") + vim.api.nvim_buf_set_option(buffer_nr, "omnifunc", "v:lua.vim.lsp.omnifunc") -- Helper function local opts = {noremap = true, silent = true} @@ -80,7 +71,8 @@ local function custom_on_attach(client, buffer_nr) bufnnoremap("", "lua vim.diagnostic.goto_prev()") -- Show line diagnostics - bufnnoremap("d", 'lua vim.diagnostic.open_float(0, {scope = "line"})') + bufnnoremap("d", + 'lua vim.diagnostic.open_float(0, {scope = "line"})') -- Open local diagnostics in local list bufnnoremap("D", "lua vim.diagnostic.setloclist()") @@ -99,7 +91,7 @@ end lsp_installer.on_server_ready(function(server) local opts = coq.lsp_ensure_capabilities({ on_attach = custom_on_attach, - capabilities = vim.lsp.protocol.make_client_capabilities(), + capabilities = vim.lsp.protocol.make_client_capabilities() }) if extra_server_opts[server.name] then