neovim

Personal neovim configuration files
git clone git://gtms.dev/neovim.git
Log | Files | Refs

commit bfaa6d9116c0c11c772d1a9226e223b3080eb968
parent a72ac5c05f4692dff5f37f43d2a7414cb8f0eab6
Author: Tomas Nemec <nemi@skaut.cz>
Date:   Sun, 28 Nov 2021 00:29:33 +0100

gupdate

Diffstat:
Minit.lua | 5+++++
Dlua/tms/lsp/efm.lua | 37-------------------------------------
Mlua/tms/lsp/init.lua | 34+++++++++++++++++++++-------------
Mlua/tms/lsp/servers.lua | 108++++++++++++++++++++++++++++---------------------------------------------------
Mlua/tms/p/luasnip.lua | 2+-
Alua/tms/p/nullls.lua | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlua/tms/plugins.lua | 6+-----
Dplugin/debug.lua | 4----
8 files changed, 118 insertions(+), 130 deletions(-)

diff --git a/init.lua b/init.lua @@ -4,6 +4,11 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.api.nvim_command('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path) end +function _G.dump(...) + local objects = vim.tbl_map(vim.inspect, {...}) + print(unpack(objects)) +end + -- Meta setup vim.cmd [[runtime plugin/astronauta.vim]] require('impatient') diff --git a/lua/tms/lsp/efm.lua b/lua/tms/lsp/efm.lua @@ -1,37 +0,0 @@ -local M = {} - -M.settings = { - languages = { - lua = {{formatCommand = 'lua-format -i', formatStdin = true}}, - clang = {{formatCommand = 'clang-format --style=file', formatStdin = true}}, - css = {{formatCommand = 'prettier --config ~/.config/prettier/config.yaml --parser css', formatStdin = true}}, - scss = {{formatCommand = 'prettier --config ~/.config/prettier/config.yaml --parser scss', formatStdin = true}}, - html = {{formatCommand = 'prettier --config ~/.config/prettier/config.yaml --parser html', formatStdin = true}}, - json = {{formatCommand = 'prettier --config ~/.config/prettier/config.yaml --parser json', formatStdin = true}}, - yaml = {{formatCommand = 'prettier --config ~/.config/prettier/config.yaml --parser yaml', formatStdin = true}}, - -- javascript = { - -- { - -- formatCommand = 'prettier --config ~/.config/prettier/config.yaml --parser typescript', - -- formatStdin = true, - -- }, - -- }, - }, -} - --- List all filetypes efm handles -M.filetypes = function() - local fts = {} - for ft, _ in pairs(M.settings.languages) do table.insert(fts, ft) end - return fts -end - --- Check if filetype is handled by efm -M.handle_filetype = function(filetype) - if type(filetype) == 'string' then - for _, ft in ipairs(M.filetypes()) do if ft == filetype then return true end end - elseif type(filetype) == 'table' then - for _, ft in ipairs(M.filetypes()) do for _, fft in ipairs(filetype) do if ft == fft then return true end end end - end -end - -return M diff --git a/lua/tms/lsp/init.lua b/lua/tms/lsp/init.lua @@ -1,4 +1,3 @@ -local efm = require('tms.lsp.efm') local servers = require('tms.lsp.servers') local M = {} @@ -31,9 +30,6 @@ local keybind = function(bufnr) end local custom_attach = function(client, bufnr) - if client.name ~= 'efm' and efm.handle_filetype(client.config.filetypes) then - client.resolved_capabilities.document_formatting = false - end local lsp = vim.lsp lsp.handlers['textDocument/hover'] = lsp.with(lsp.handlers.hover, {border = 'single'}) lsp.handlers['textDocument/signatureHelp'] = lsp.with(lsp.handlers.signature_help, {border = 'single'}) @@ -41,7 +37,10 @@ local custom_attach = function(client, bufnr) keybind(bufnr) end +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + M.setup = function() + -- LSP Installer local lsp_installer = require('nvim-lsp-installer') lsp_installer.on_server_ready(function(server) local function finish(o) @@ -50,23 +49,32 @@ M.setup = function() end local opts = {} + opts = servers.setup(server.name, opts) opts.on_attach = custom_attach - opts = servers.modify_opts(server.name, opts) - opts.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + opts.capabilities = capabilities if server.name == 'sumneko_lua' then opts = vim.tbl_deep_extend('force', server:get_default_options(), opts) - local luadev = require('lua-dev').setup({lspconfig = opts}) - finish(luadev) - else - finish(opts) + opts = require('lua-dev').setup({lspconfig = opts}) end + finish(opts) end) + -- Manual install local lspc = require('lspconfig') - lspc.dartls.setup(servers.dartls(custom_attach)) - lspc.gdscript.setup(servers.gdscript(custom_attach)) - lspc.sumneko_lua.setup(servers.lua(custom_attach)) + local manual_servers = { + 'null-ls', + 'gdscript', + 'dartls', + -- 'sumneko_lua' + } + for _, name in ipairs(manual_servers) do + local opts = {} + opts.on_attach = custom_attach + opts.capabilities = capabilities + opts = servers.setup(name, opts) + lspc[name].setup(opts) + end end return M diff --git a/lua/tms/lsp/servers.lua b/lua/tms/lsp/servers.lua @@ -1,90 +1,58 @@ +-- Custom configuration for servers local lspc = require('lspconfig') -local efm = require('tms.lsp.efm') local M = {} -M.modify_opts = function(name, opts) - if name == 'intelephense' then - opts.init_options = { - clearCache = true, - licenceKey = os.getenv('XDG_CONFIG_HOME') .. '/intelephense/licenceKey.txt', - globalStoragePath = os.getenv('XDG_CONFIG_HOME') .. '/intelephense', - } - elseif name == 'gopls' then - opts.root_dir = lspc.util.root_pattern('go.mod', '.git', vim.fn.getcwd()) - elseif name == 'efm' then - opts.init_options = {documentFormatting = true} - opts.settings = efm.settings - opts.filetypes = efm.filetypes() - opts.root_dir = lspc.util.root_pattern('.git', vim.fn.getcwd()) - elseif name == 'emmet_ls' then - opts.root_dir = lspc.util.root_pattern('.git', vim.fn.getcwd()) - end +M.setup = function(name, opts) + local fn = M[name] + if fn then opts = fn(opts) end return opts end --- Custom configuration for servers +-- Servers -M.dartls = function(attach_fn) - return { - on_attach = attach_fn, - cmd = require'tms.ft.dart.bin'.lspcmd(), - init_options = {closingLabels = true, outline = true}, - -- filetypes = {'dart', 'html'}, - settings = {dart = {lineLength = 120, showTodos = true, completeFunctionCalls = true}}, - handlers = {['dart/textDocument/publishClosingLabels'] = require('tms.ft.dart.closing_labels').get_callback {}}, - root_dir = lspc.util.root_pattern('pubspec.yaml', '.git', vim.fn.getcwd()), - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), - } +M.emmet_ls = function(opts) + opts.root_dir = lspc.util.root_pattern('.git', vim.fn.getcwd()) + return opts end -M.gdscript = function(attach_fn) - return { - on_attach = attach_fn, - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), - } +M.efm = function(opts) + local efm = require('tms.lsp.efm') + opts.init_options = {documentFormatting = true} + opts.settings = efm.settings + opts.filetypes = efm.filetypes() + opts.root_dir = lspc.util.root_pattern('.git', vim.fn.getcwd()) + return opts end -M.efm = function(attach_fn) - return { - on_attach = attach_fn, - init_options = {documentFormatting = true}, - settings = efm.settings, - root_dir = lspc.util.root_pattern('.git', vim.fn.getcwd()), - filetypes = efm.filetypes(), - } +M.gopls = function(opts) + opts.root_dir = lspc.util.root_pattern('go.mod', '.git', vim.fn.getcwd()) + return opts end -M.lua = function(attach_fn) - return require('lua-dev').setup({ - lspconfig = { - on_attach = attach_fn, - cmd = { - '/home/tms/.cache/nvim/lspconfig/sumneko_lua/lua-language-server/bin/Linux/lua-language-server', - '-E', - '/home/tms/.cache/nvim/lspconfig/sumneko_lua/lua-language-server/main.lua', - }, - settings = { - Lua = { - runtime = {version = 'LuaJIT', path = vim.split(package.path, ';')}, - diagnostics = {globals = {'vim', 'vimp', 'Color', 'c', 'Group', 'g', 's', 'use', 'mutt'}}, - }, - }, - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), - }, - }) +M.dartls = function(opts) + opts.cmd = require('tms.ft.dart.bin').lspcmd() + opts.init_options = {closingLabels = true, outline = true} + -- filetypes = {'dart', 'html'} + opts.settings = {dart = {lineLength = 120, showTodos = true, completeFunctionCalls = true}} + opts.handlers = {['dart/textDocument/publishClosingLabels'] = require('tms.ft.dart.closing_labels').get_callback {}} + opts.root_dir = lspc.util.root_pattern('pubspec.yaml', '.git', vim.fn.getcwd()) + return opts end -M.php = function(attach_fn) - return { - on_attach = attach_fn, - init_options = { - clearCache = true, - licenceKey = os.getenv('XDG_CONFIG_HOME') .. '/intelephense/licenceKey.txt', - globalStoragePath = os.getenv('XDG_CONFIG_HOME') .. '/intelephense', - }, - capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()), +M.gdscript = function(opts) return opts end + +M['null-ls'] = function(opts) return opts end + +M.sumneko_lua = function(opts) return opts end + +M.intelephense = function(opts) + opts.init_options = { + clearCache = true, + licenceKey = os.getenv('XDG_CONFIG_HOME') .. '/intelephense/licenceKey.txt', + globalStoragePath = os.getenv('XDG_CONFIG_HOME') .. '/intelephense', } + return opts end return M diff --git a/lua/tms/p/luasnip.lua b/lua/tms/p/luasnip.lua @@ -59,7 +59,7 @@ local snippets = function(luasnip) }, html = {s('ni', fmt('*ngIf="{1}"', {i(1)}))}, lua = { - s('fn', fmt('function() {1} end', {i(1)})), + s('f', fmt('function() {1} end', {i(1)})), s('r', fmt('require(\'{1}\')', {i(1)})), s('l', fmt('local {1} = {2}', {i(1), i(2)})), }, diff --git a/lua/tms/p/nullls.lua b/lua/tms/p/nullls.lua @@ -0,0 +1,52 @@ +local M = {} + +local zsh_diag = function() + local null_ls = require('null-ls') + local h = require('null-ls.helpers') + return { + name = 'zsh check', + method = null_ls.methods.DIAGNOSTICS, + filetypes = {'zsh'}, + update_on_insert = true, + generator = null_ls.generator({ + command = 'zsh', + args = {'-n', '$FILENAME'}, + format = 'line', + check_exit_code = function(code) return code <= 1 end, + from_stderr = true, + to_stdin = true, + on_output = h.diagnostics.from_patterns({{pattern = [[%w+:(%d+): (.*)]], groups = {'row', 'message'}}}), + }), + } +end + +M.setup = function() + local null_ls = require('null-ls') + local h = require('null-ls.helpers') + local builtins = null_ls.builtins + null_ls.config({ + sources = { + -- formatting + builtins.formatting.prettier.with { + filetypes = {'html', 'json', 'yaml', 'markdown', 'css', 'scss'}, + args = h.range_formatting_args_factory({ + '--config', + vim.fn.expand('$CONFIG/prettier/config.yaml'), + '--stdin-filepath', + '$FILENAME', + }), + }, + builtins.formatting.lua_format, + builtins.formatting.clang_format, + builtins.formatting.shfmt.with { + filetypes = {'sh', 'zsh'}, + args = {'-i', vim.opt.shiftwidth:get(), '-filename', '$FILENAME'}, + }, + -- diagnostic + builtins.diagnostics.shellcheck, + zsh_diag(), + }, + }) +end + +return M diff --git a/lua/tms/plugins.lua b/lua/tms/plugins.lua @@ -336,11 +336,7 @@ return packer.startup({ use {'folke/lua-dev.nvim'} use { 'jose-elias-alvarez/null-ls.nvim', - config = function() - local null_ls = require('null-ls') - null_ls.config({}) - require('lspconfig')['null-ls'].setup({}) - end, + config = function() require('tms.p.nullls').setup() end, requires = {'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig'}, } use {'stevearc/aerial.nvim', config = function() require('tms.p.aerial').setup() end} diff --git a/plugin/debug.lua b/plugin/debug.lua @@ -1,4 +0,0 @@ -function _G.dump(...) - local objects = vim.tbl_map(vim.inspect, {...}) - print(unpack(objects)) -end