neovim

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

commit d5dfb3ac6a48cfcce7fb631b9660d725af05abe5
parent b56a1774eb7d7ba6abd1bc2935af37ffb1075932
Author: Tomas Nemec <nemi@skaut.cz>
Date:   Tue,  2 Aug 2022 23:06:45 +0200

update

Diffstat:
Aafter/plugin/format.lua | 19+++++++++++++++++++
Aafter/plugin/lsp.lua | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dafter/plugin/mason.lua | 3---
Mafter/plugin/nulls.lua | 9++++++---
Mafter/plugin/zen.lua | 13++++++++++---
Mafter/plugin/zk.lua | 11++++++++++-
Minit.lua | 1-
Mlua/tms/ft/dart/bin.lua | 2++
Mlua/tms/lsp/init.lua | 82+++++++++++--------------------------------------------------------------------
Mlua/tms/plugins.lua | 3++-
Mplugin/globals.lua | 2+-
11 files changed, 133 insertions(+), 84 deletions(-)

diff --git a/after/plugin/format.lua b/after/plugin/format.lua @@ -0,0 +1,19 @@ +local group = vim.api.nvim_create_augroup('user-format', {}) + +vim.api.nvim_create_autocmd('LspAttach', { + group = group, + callback = function(args) + local buf = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + + vim.api.nvim_buf_set_option(buf, 'formatexpr', 'v:lua.vim.lsp.formatexpr()') + + vim.keymap.set('n', 'Q', function() + local params = vim.lsp.util.make_formatting_params({}) + client.request('textDocument/formatting', params, nil, buf) + end, { buffer = buf, desc = 'LSP Format' }) + + local rhs = ':<c-u>lua vim.lsp.buf.range_formatting()<cr>' + vim.keymap.set('v', 'Q', rhs, { buffer = buf, desc = 'LSP Range Format' }) + end, +}) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua @@ -0,0 +1,72 @@ +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('user-lsp', {}), + callback = function(args) + local buf = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + local cap = client.server_capabilities + + local opt = function(desc) + return { buffer = buf, desc = desc } + end + + if cap.hoverProvider then + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opt 'LSP Hover') + end + + if cap.definitionProvider then + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opt 'LSP Definition') + vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opt('LSP definition in vsplit')) + end + + if cap.typeDefinitionProvider then + vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, opt('LSP Type Definition')) + end + if cap.implementationProvider then + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opt('LSP Implementation')) + end + if cap.signatureHelpProvider then + vim.keymap.set('n', '<c-p>', vim.lsp.buf.signature_help, opt('LSP Signature Help')) + vim.keymap.set('i', '<c-p>', vim.lsp.buf.signature_help, opt('LSP Signature Help')) + end + if cap.referencesProvider then + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opt('LSP References')) + end + if cap.codeActionProvider then + vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, opt('LSP Code Actions')) + vim.keymap.set('v', 'ga', vim.lsp.buf.range_code_action, opt('LSP Code Actions')) + end + if cap.renameProvider then + vim.keymap.set('n', 'gn', vim.lsp.buf.rename, opt('LSP Rename')) + end + + local has_aerial, aerial = pcall(require, 'aerial') + if has_aerial then + aerial.on_attach(client, buf) + end + end, +}) + +vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = 'single' }) +vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = 'single' }) + +-- lsp.handlers['$/progress'] = progress.handler +-- local severity = { 'error', 'warn', 'info' } +-- lsp.handlers['window/showMessage'] = +-- function(_, method, params, _) vim.notify(method.message, severity[params.type]) end + +if not pcall(require, 'mason') then + return +end + +require('mason').setup() +local mlsp = require('mason-lspconfig') +mlsp.setup() +mlsp.setup_handlers { + function(name) + local has_lspc, lsp_config = pcall(require, 'lspconfig') + if has_lspc then + local opts = require('tms.lsp').make_opts(name) + lsp_config[name].setup(opts) + end + end, +} diff --git a/after/plugin/mason.lua b/after/plugin/mason.lua @@ -1,3 +0,0 @@ -if not pcall(require, 'mason') then return end - -require('mason').setup() diff --git a/after/plugin/nulls.lua b/after/plugin/nulls.lua @@ -1,4 +1,6 @@ -if not pcall(require, 'null-ls') then return end +if not pcall(require, 'null-ls') then + return +end local null_ls = require('null-ls') local h = require('null-ls.helpers') @@ -13,7 +15,9 @@ local zsh_diag = { command = 'zsh', args = { '-n', '$FILENAME' }, format = 'line', - check_exit_code = function(code) return code <= 1 end, + 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' } } }), @@ -21,7 +25,6 @@ local zsh_diag = { } null_ls.setup({ - on_attach = function(client, bufnr) require('tms.lsp').on_attach(client, bufnr) end, sources = { -- formatting builtins.formatting.prettier.with { diff --git a/after/plugin/zen.lua b/after/plugin/zen.lua @@ -1,4 +1,11 @@ -if not pcall(require,'zen-mode')then return end +if not pcall(require, 'true-zen') then + return +end -require('zen-mode').setup {} -vim.keymap.set('n', '<leader>Z', '<cmd>ZenMode<cr>') +local zen = require('true-zen') +zen.setup { modes = { ataraxis = { backdrop = 0.05 }, narrow = { folds_style = 'invisible' } } } +vim.keymap.set('n', '<leader>nr', ':TZNarrow<CR>', { desc = 'Zen Line Narrow' }) +vim.keymap.set('v', '<leader>nr', ':\'<,\'>TZNarrow<CR>', { desc = 'Zen Range Narrow' }) +vim.keymap.set('n', '<leader>nf', zen.focus, { desc = 'Zen Focus' }) +vim.keymap.set('n', '<leader>nd', zen.minimalist, { desc = 'Zen Distract Free' }) +vim.keymap.set('n', '<leader>na', zen.ataraxis, { desc = 'Zen Atraxis' }) diff --git a/after/plugin/zk.lua b/after/plugin/zk.lua @@ -1,4 +1,6 @@ -if not pcall(require, 'zk') then return end +if not pcall(require, 'zk') then + return +end vim.keymap.set('n', '<leader>zc', '<cmd>ZkNew<cr>') vim.keymap.set('x', '<leader>zc', '<cmd>ZkNewFromTitleSelection<cr>') @@ -20,3 +22,10 @@ vim.keymap.set('n', '<space>zo', '<cmd>ZkNotes {orphan = true}<cr>') -- require('zk').new(nil, {insertLinkAtLocation = location, title = title}) -- end) -- end + +-- Manual +local l = require('tms.lsp') +local has_zk, zk = pcall(require, 'zk') +if has_zk then + zk.setup({ lsp = { config = l.make_opts('zk') } }) +end diff --git a/init.lua b/init.lua @@ -2,4 +2,3 @@ vim.g.mapleader = ',' require('tms.first_load') require('impatient') require('colorbuddy').colorscheme('tms') -require('tms.lsp').setup() diff --git a/lua/tms/ft/dart/bin.lua b/lua/tms/ft/dart/bin.lua @@ -3,6 +3,8 @@ local fn = vim.fn local M = {} function M.lsp_cmd() + -- local dart_bin = '/home/tms/.dswitch/old/dart' + -- local dart_bin_root = '/home/tms/.dswitch/old' local dart_bin = fn.resolve(fn.exepath('dart')) local dart_bin_root = fn.fnamemodify(dart_bin, ':h') local snapshot = dart_bin_root .. '/snapshots/analysis_server.dart.snapshot' diff --git a/lua/tms/lsp/init.lua b/lua/tms/lsp/init.lua @@ -1,80 +1,20 @@ -local lsp = vim.lsp -local servers = require('tms.lsp.servers') --- local progress = require('tms.lsp.progress') +local M = {} -local format_setup = function(client, bufnr) - vim.keymap.set('n', 'Q', function() - local params = vim.lsp.util.make_formatting_params({}) - client.request('textDocument/formatting', params, nil, bufnr) - end, { buffer = bufnr, desc = 'LSP Format' }) - vim.keymap - .set('v', 'Q', ':<c-u>lua vim.lsp.buf.range_formatting()<cr>', { buffer = bufnr, desc = 'LSP Range Format' }) -end - -local on_attach = function(client, bufnr) - vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc') - vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr()') - - local opts = function(desc) return { silent = true, buffer = bufnr, desc = desc } end - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts('LSP Definition')) - vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opts('LSP definition in vsplit')) - vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, opts('LSP Type Definition')) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts('LSP Implementation')) - vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts('LSP Hover')) - vim.keymap.set('n', '<c-p>', vim.lsp.buf.signature_help, opts('LSP Signature Help')) - vim.keymap.set('i', '<c-p>', vim.lsp.buf.signature_help, opts('LSP Signature Help')) - vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts('LSP References')) - vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, opts('LSP Code Actions')) - vim.keymap.set('v', 'ga', vim.lsp.buf.range_code_action, opts('LSP Code Actions')) - vim.keymap.set('n', 'gn', vim.lsp.buf.rename, opts('LSP Rename')) - - if not servers.no_format[client.name] then format_setup(client, bufnr) end - - local has_aerial, aerial = pcall(require, 'aerial') - if has_aerial then aerial.on_attach(client, bufnr) end -end - -local capabilities = function() - local ok, cnl = pcall(require, 'cmp_nvim_lsp') - if ok then - return cnl.update_capabilities(vim.lsp.protocol.make_client_capabilities()) +M.capabilities = function() + local cap = vim.lsp.protocol.make_client_capabilities() + local has_cmp, cmp = pcall(require, 'cmp_nvim_lsp') + if has_cmp then + return cmp.update_capabilities(cap) else - return vim.lsp.protocol.make_client_capabilities() + return cap end end -local make_opts = function(name) +M.make_opts = function(name) local opts = {} - opts.on_attach = on_attach - opts.capabilities = capabilities() - opts = servers.setup(name, opts) + opts.capabilities = M.capabilities() + opts = require('tms.lsp.servers').setup(name, opts) return opts end -local setup = function() - lsp.handlers['textDocument/hover'] = lsp.with(lsp.handlers.hover, { border = 'single' }) - lsp.handlers['textDocument/signatureHelp'] = lsp.with(lsp.handlers.signature_help, { border = 'single' }) - -- lsp.handlers['$/progress'] = progress.handler - -- local severity = { 'error', 'warn', 'info' } - -- lsp.handlers['window/showMessage'] = - -- function(_, method, params, _) vim.notify(method.message, severity[params.type]) end - - -- LSP Installer - local has_lspi, lsp_installer = pcall(require, 'nvim-lsp-installer') - if has_lspi then lsp_installer.setup({}) end - - -- LSP Config - local has_lspc, lsp_config = pcall(require, 'lspconfig') - if has_lspc then - for _, name in ipairs(servers.installed) do - local opts = make_opts(name) - lsp_config[name].setup(opts) - end - end - - -- Manual - local has_zk, zk = pcall(require, 'zk') - if has_zk then zk.setup({ lsp = { config = make_opts('zk') } }) end -end - -return { on_attach = on_attach, setup = setup } +return M diff --git a/lua/tms/plugins.lua b/lua/tms/plugins.lua @@ -55,7 +55,7 @@ return packer.startup({ -- distraction use 'junegunn/limelight.vim' - use 'folke/zen-mode.nvim' + use 'Pocco81/true-zen.nvim' -- how to vim use 'ThePrimeagen/vim-be-good' @@ -109,6 +109,7 @@ return packer.startup({ -- lsp use 'neovim/nvim-lspconfig' use 'williamboman/mason.nvim' + use 'williamboman/mason-lspconfig.nvim' use 'b0o/schemastore.nvim' use 'folke/lua-dev.nvim' use { 'jose-elias-alvarez/null-ls.nvim', requires = { 'nvim-lua/plenary.nvim' } } diff --git a/plugin/globals.lua b/plugin/globals.lua @@ -7,5 +7,5 @@ end R = function(p) package.loaded[p] = nil - require(p) + return require(p) end