neovim

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

commit 9c1b0c7e5a87f0423ba73907d37028e92b67eb7d
parent f4f409e38beb0ec4c06cd9e7e94fa997d15da71c
Author: Tomas Nemec <owl@gtms.dev>
Date:   Tue,  7 May 2024 12:22:22 +0200

update

Diffstat:
Mafter/plugin/codeium.lua | 2++
Mafter/plugin/lsp.lua | 132++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Mcolors/tms.lua | 23+++++++++++++----------
Mftplugin/dart.lua | 1+
Mlua/tms/lsp/dart.lua | 12+++++-------
Mlua/tms/lsp/init.lua | 2+-
Dlua/tms/lsp/progress.lua | 69---------------------------------------------------------------------
Dlua/tms/lsp/request.lua | 63---------------------------------------------------------------
Mlua/tms/medoro.lua | 2+-
Mplugin/snippet.lua | 6++++++
10 files changed, 120 insertions(+), 192 deletions(-)

diff --git a/after/plugin/codeium.lua b/after/plugin/codeium.lua @@ -1,3 +1,5 @@ +vim.g.codeium_enabled = false +vim.g.codeium_manual = true vim.g.codeium_disable_bindings = true vim.g.codeium_no_map_tab = true diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua @@ -5,69 +5,119 @@ end local lsp_group = vim.api.nvim_create_augroup('user-lsp', {}) local function keymap(client, buf) - local lb = vim.lsp.buf local function opt(desc) return { buffer = buf, desc = desc } end -- client.server_capabilities.semanticTokensProvider = nil - -- if client.supports_method('textDocument/definition') then - -- vim.keymap.set('n', 'gd', lb.definition, opt 'LSP Definition') - -- vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opt('LSP definition in vsplit')) - -- end - -- collision with previous tab `gT` - -- if cap.typeDefinitionProvider then - -- vim.keymap.set('n', 'gT', lb.type_definition, opt('LSP Type Definition')) - -- end + if client.supports_method('textDocument/definition') then + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opt 'LSP Definition') + vim.keymap.set('n', 'crd', vim.lsp.buf.definition, opt 'LSP Definition') + end + + if client.supports_method('textDocument/typeDefinition') then + vim.keymap.set('n', 'crt', vim.lsp.buf.type_definition, opt 'LSP Type Definition') + end + + if client.supports_method('callHierarchy/incomingCalls') then + vim.keymap.set('n', 'cri', vim.lsp.buf.incoming_calls, opt 'LSP Incoming calls') + end + + if client.supports_method('callHierarchy/outgoingCalls') then + vim.keymap.set('n', 'cro', vim.lsp.buf.outgoing_calls, opt 'LSP Outgoing calls') + end + if client.supports_method('textDocument/implementation') then - vim.keymap.set('n', 'cri', lb.implementation, opt('LSP Implementation')) + vim.keymap.set('n', 'crm', vim.lsp.buf.implementation, opt 'LSP Implementation') vim.keymap.set('i', '<c-w><c-m>', function() vim.cmd.split() - lb.implementation() - end, opt('LSP Implementation')) + vim.lsp.buf.implementation() + end, opt('LSP Implementation (Split)')) end + if client.supports_method('textDocument/signatureHelp') then - -- vim.keymap.set('i', '<c-p>', lb.signature_help, opt('LSP Signature Help')) - vim.keymap.set('n', '<c-s>', lb.signature_help, opt('LSP Signature Help')) + vim.keymap.set({ 'n', 'i' }, '<c-s>', vim.lsp.buf.signature_help, opt('LSP Signature Help')) + end + + if client.supports_method('textDocument/references') then + vim.keymap.set('n', 'crf', function() + vim.lsp.buf.references({ includeDeclaration = false }) + end, opt('LSP References')) + + vim.keymap.set('n', '[I', function() + vim.lsp.buf.references({ includeDeclaration = false }, { + on_list = function(opts) + local curr_filename = vim.api.nvim_buf_get_name(opts.context.bufnr) + opts.items = vim.tbl_filter(function(item) + return item.filename == curr_filename + end, opts.items) + + if #opts.items == 0 then + vim.notify('No references in current file') + return + end + + opts.title = 'References (Current File)' + vim.fn.setloclist(0, {}, ' ', opts) + vim.api.nvim_command('botright lopen') + end + }) + end, opt('LSP References (Current File)')) + + vim.keymap.set('n', ']I', function() + vim.lsp.buf.references({ includeDeclaration = false }, { + on_list = function(opts) + local curr_filename = vim.api.nvim_buf_get_name(opts.context.bufnr) + local curr_lnum = opts.context.params.position.line + opts.items = vim.tbl_filter(function(item) + return item.filename == curr_filename and item.lnum > curr_lnum + end, opts.items) + + if #opts.items == 0 then + vim.notify('No references after current line') + return + end + + opts.title = 'References (After Current Line)' + vim.fn.setloclist(0, {}, ' ', opts) + vim.api.nvim_command('botright lopen') + end + }) + end, opt('LSP References (After Current Line)')) + end + + if client.supports_method('textDocument/codeAction') then + vim.keymap.set({ 'n', 'v' }, 'cra', vim.lsp.buf.code_action, opt('LSP Code Actions')) end - -- if client.supports_method('textDocument/references') then - -- vim.keymap.set('n', 'gr', lb.references, opt('LSP References')) - -- end - -- if client.supports_method('textDocument/codeAction') then - -- vim.keymap.set({ 'n', 'v' }, 'ga', lb.code_action, opt('LSP Code Actions')) - -- end + if client.supports_method('textDocument/documentHighlight') then - vim.keymap.set('n', '<leader>k', lb.document_highlight, opt('LSP Highlight')) + vim.keymap.set('n', '<leader>k', vim.lsp.buf.document_highlight, opt('LSP Highlight')) vim.api.nvim_create_autocmd('CursorMoved', { group = lsp_group, buffer = buf, callback = vim.lsp.buf.clear_references }) end + if client.supports_method('textDocument/inlayHint') then - vim.keymap.set('n', 'gH', function() - vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled(0)) + vim.keymap.set('n', 'crh', function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) end, opt('LSP Inlay hints')) end - -- if client.supports_method('textDocument/rename') thenga - -- vim.keymap.set('n', 'cd', lb.rename, opt('LSP Rename (change definition)')) - -- end - if client.supports_method('textDocument/prepareTypeHierarchy') then - vim.keymap.set('n', 'gh', function() - require('tms.lsp.request').type_hierarchy('subtypes') - end, opt('LSP Subtypes')) - vim.keymap.set('n', 'gl', function() - require('tms.lsp.request').type_hierarchy('supertypes') - end, opt('LSP Supertypes')) + + if client.supports_method('textDocument/rename') then + vim.keymap.set('n', 'crn', vim.lsp.buf.rename, opt('LSP Rename')) end - -- if client.supports_method('textDocument/formatting') then - -- vim.keymap.set('n', 'gQ', function() - -- vim.lsp.buf.format() + if client.supports_method('typeHierarchy/supertypes') then + vim.keymap.set('n', 'crp', function() + vim.lsp.buf.typehierarchy('supertypes') + end, opt 'LSP Supertypes (Parents)') + end - -- -- if vim.api.nvim_get_option_value('ft', { buf = buf }) == 'dart' then - -- -- vim.cmd.NgHtmlFormat() - -- -- end - -- end, { buffer = buf, desc = 'LSP Format' }) - -- end + if client.supports_method('typeHierarchy/subtypes') then + vim.keymap.set('n', 'crc', function() + vim.lsp.buf.typehierarchy('subtypes') + end, opt 'LSP Subtypes (Children)') + end end vim.api.nvim_create_autocmd('LspAttach', { diff --git a/colors/tms.lua b/colors/tms.lua @@ -140,15 +140,15 @@ vim.api.nvim_set_hl(0, 'cssClassName', { fg = gui0E, ctermfg = cterm0E }) vim.api.nvim_set_hl(0, 'cssColor', { fg = gui0C, ctermfg = cterm0C }) -- Diff highlighting -vim.api.nvim_set_hl(0, 'DiffAdd', { fg = gui0B, bg = gui01, ctermfg = cterm0B, ctermbg = cterm01 }) -vim.api.nvim_set_hl(0, 'DiffChange', { fg = gui03, bg = gui01, ctermfg = cterm03, ctermbg = cterm01 }) -vim.api.nvim_set_hl(0, 'DiffDelete', { fg = gui08, bg = gui01, ctermfg = cterm08, ctermbg = cterm01 }) -vim.api.nvim_set_hl(0, 'DiffText', { fg = gui0D, bg = gui01, ctermfg = cterm0D, ctermbg = cterm01 }) -vim.api.nvim_set_hl(0, 'DiffAdded', { fg = gui0B, bg = gui00, ctermfg = cterm0B, ctermbg = cterm00 }) -vim.api.nvim_set_hl(0, 'DiffFile', { fg = gui08, bg = gui00, ctermfg = cterm08, ctermbg = cterm00 }) -vim.api.nvim_set_hl(0, 'DiffNewFile', { fg = gui0B, bg = gui00, ctermfg = cterm0B, ctermbg = cterm00 }) -vim.api.nvim_set_hl(0, 'DiffLine', { fg = gui0D, bg = gui00, ctermfg = cterm0D, ctermbg = cterm00 }) -vim.api.nvim_set_hl(0, 'DiffRemoved', { fg = gui08, bg = gui00, ctermfg = cterm08, ctermbg = cterm00 }) +vim.api.nvim_set_hl(0, 'DiffAdd', { fg = gui0B, bg = gui01, ctermfg = cterm0B, ctermbg = cterm01 }) +vim.api.nvim_set_hl(0, 'DiffChange', { fg = gui03, bg = gui01, ctermfg = cterm03, ctermbg = cterm01 }) +vim.api.nvim_set_hl(0, 'DiffDelete', { fg = gui08, bg = gui01, ctermfg = cterm08, ctermbg = cterm01 }) +vim.api.nvim_set_hl(0, 'DiffText', { fg = gui0D, bg = gui01, ctermfg = cterm0D, ctermbg = cterm01 }) +vim.api.nvim_set_hl(0, 'DiffAdded', { fg = gui0B, bg = gui00, ctermfg = cterm0B, ctermbg = cterm00 }) +vim.api.nvim_set_hl(0, 'DiffFile', { fg = gui08, bg = gui00, ctermfg = cterm08, ctermbg = cterm00 }) +vim.api.nvim_set_hl(0, 'DiffNewFile', { fg = gui0B, bg = gui00, ctermfg = cterm0B, ctermbg = cterm00 }) +vim.api.nvim_set_hl(0, 'DiffLine', { fg = gui0D, bg = gui00, ctermfg = cterm0D, ctermbg = cterm00 }) +vim.api.nvim_set_hl(0, 'DiffRemoved', { fg = gui08, bg = gui00, ctermfg = cterm08, ctermbg = cterm00 }) -- Git highlighting vim.api.nvim_set_hl(0, 'gitcommitOverflow', { fg = gui08, ctermfg = cterm08 }) @@ -351,7 +351,7 @@ vim.api.nvim_set_hl(0, 'DiagnosticHint', { fg = gui03, ctermfg = cterm03 }) -- vim.api.nvim_set_hl(0, group, {}) -- end -vim.api.nvim_set_hl(0, '@lsp.type.enum', {}) +-- vim.api.nvim_set_hl(0, '@lsp.type.enum', {}) vim.api.nvim_set_hl(0, '@lsp.type.class', { link = 'Type' }) vim.api.nvim_set_hl(0, '@lsp.type.keyword', { link = 'Keyword' }) vim.api.nvim_set_hl(0, '@lsp.mod.annotation', { italic = true }) @@ -360,3 +360,6 @@ vim.api.nvim_set_hl(0, '@type.qualifier', { link = 'Keyword' }) vim.api.nvim_set_hl(0, '@variable.builtin', { link = 'Type' }) vim.api.nvim_set_hl(0, '@conceal', { link = 'Conceal' }) vim.api.nvim_set_hl(0, '@text.reference', { link = 'Keyword' }) + +vim.api.nvim_set_hl(0, '@lsp.type.string.dart', {}) +vim.api.nvim_set_hl(0, '@variable.builtin.dart', { link = 'Keyword' }) diff --git a/ftplugin/dart.lua b/ftplugin/dart.lua @@ -4,6 +4,7 @@ vim.opt_local.includeexpr = [[v:lua.require('tms.ft.dart.package').package_path( vim.opt_local.isfname:append { ':' } vim.opt_local.iskeyword:append { '$' } vim.opt_local.textwidth = 80 +vim.opt_local.shiftwidth = 2 vim.opt_local.formatoptions:remove('t') vim.opt_local.makeprg = [[dart %]] vim.opt_local.efm = [[%f:%l:%c: %m]] diff --git a/lua/tms/lsp/dart.lua b/lua/tms/lsp/dart.lua @@ -7,7 +7,7 @@ local capabilities = { local function root_dir(path) path = path or vim.fs.dirname(vim.api.nvim_buf_get_name(0)) local matches = vim.fs.find('pubspec.yaml', - { path = path, upward = true, limit = math.huge, stop = vim.uv.os_homedir() }) + { path = path, upward = true, limit = math.huge, stop = vim.uv.os_homedir() }) return vim.fs.dirname(matches[#matches]) end @@ -18,17 +18,15 @@ function M.start() 'dart', 'language-server', '--protocol=lsp', - '--port=10000', - '--instrumentation-log-file=/tmp/dart-plugin-log', + -- '--port=10000', + -- '--instrumentation-log-file=/tmp/dart-plugin-log', }, root_dir = root_dir(), - capabilities = vim.tbl_deep_extend('force', require'tms.lsp'.capabilities(), capabilities), + capabilities = vim.tbl_deep_extend('force', require 'tms.lsp'.capabilities(), capabilities), init_options = { closingLabels = true, outline = true, flutterOutline = true }, settings = { dart = { completeFunctionCalls = true, showTodos = true, lineLength = 120 } }, handlers = { - ['typeHierarchy/subtypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), - ['typeHierarchy/supertypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), - ['dart/textDocument/publishClosingLabels'] = require'dart-tools.lsp.labels'.handler(), + ['dart/textDocument/publishClosingLabels'] = require 'dart-tools.lsp.labels'.handler(), ['dart/textDocument/super'] = vim.lsp.handlers['textDocument/definition'], }, } diff --git a/lua/tms/lsp/init.lua b/lua/tms/lsp/init.lua @@ -3,7 +3,7 @@ local M = {} function M.capabilities() local o = vim.lsp.protocol.make_client_capabilities() if pcall(require, 'cmp_nvim_lsp') then - o = vim.tbl_deep_extend('force', o, require'cmp_nvim_lsp'.default_capabilities()) + o = vim.tbl_deep_extend('force', o, require 'cmp_nvim_lsp'.default_capabilities()) end return o end diff --git a/lua/tms/lsp/progress.lua b/lua/tms/lsp/progress.lua @@ -1,69 +0,0 @@ -local M = {} - -local client_notifs = {} - -local function get_notif_data(client_id, token) - if not client_notifs[client_id] then client_notifs[client_id] = {} end - - if not client_notifs[client_id][token] then client_notifs[client_id][token] = {} end - - return client_notifs[client_id][token] -end - -local spinner_frames = { '⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷' } - -local function update_spinner(client_id, token) - local notif_data = get_notif_data(client_id, token) - - if notif_data.spinner then - local new_spinner = (notif_data.spinner + 1) % #spinner_frames - notif_data.spinner = new_spinner - - notif_data.notification = vim.notify(nil, nil, { - hide_from_history = true, - icon = spinner_frames[new_spinner], - replace = notif_data.notification, - }) - - vim.defer_fn(function() update_spinner(client_id, token) end, 100) - end -end - -local function format_title(title, client_name) return client_name .. (#title > 0 and ': ' .. title or '') end - -local function format_message(message, percentage) return (percentage and percentage .. '%\t' or '') .. (message or '') end - -M.handler = function(_, result, ctx) - local client_id = ctx.client_id - - local val = result.value - - if not val.kind then return end - print(val.kind) - - local notif_data = get_notif_data(client_id, result.token) - - if val.kind == 'begin' then - local message = format_message(val.message, val.percentage) - - notif_data.notification = vim.notify(message, 'info', { - title = format_title(val.title, vim.lsp.get_client_by_id(client_id).name), - icon = spinner_frames[1], - timeout = false, - hide_from_history = false, - }) - - notif_data.spinner = 1 - update_spinner(client_id, result.token) - elseif val.kind == 'report' and notif_data then - notif_data.notification = vim.notify(format_message(val.message, val.percentage), 'info', - { replace = notif_data.notification, hide_from_history = false }) - elseif val.kind == 'end' and notif_data then - notif_data.notification = vim.notify(val.message and format_message(val.message) or 'Complete', 'info', - { icon = '', replace = notif_data.notification, timeout = 3000 }) - - notif_data.spinner = nil - end -end - -return M diff --git a/lua/tms/lsp/request.lua b/lua/tms/lsp/request.lua @@ -1,63 +0,0 @@ -local vim = vim -local validate = vim.validate -local util = require('vim.lsp.util') - -local M = {} - -local function request(method, params, handler) - validate({ method = { method, 's' }, handler = { handler, 'f', true } }) - return vim.lsp.buf_request(0, method, params, handler) -end - -local function pick_type_hierarchy_item(type_hierarchy_items) - if not type_hierarchy_items then - return - end - if #type_hierarchy_items == 1 then - return type_hierarchy_items[1] - end - local items = {} - for i, item in pairs(type_hierarchy_items) do - local entry = item.detail or item.name - table.insert(items, string.format('%d. %s', i, entry)) - end - local choice = vim.fn.inputlist(items) - if choice < 1 or choice > #items then - return - end - return choice -end - -function M.type_hierarchy(method) - vim.validate({ - method = { - method, - function(m) - return (m == 'subtypes') or (m == 'supertypes'), 'Method must be one of ["subtypes", "supertypes"]' - end, - }, - }) - method = 'typeHierarchy/' .. method - local params = util.make_position_params() - request('textDocument/prepareTypeHierarchy', params, function(err, result, ctx) - if err then - vim.notify(err.message, vim.log.levels.WARN) - return - end - - local type_hierarchy_item = pick_type_hierarchy_item(result) - if not type_hierarchy_item then - return - end - - local client = vim.lsp.get_client_by_id(ctx.client_id) - if client then - client.request(method, { item = type_hierarchy_item }, nil, ctx.bufnr) - else - vim.notify(string.format('Client with id=%d disappeared during type hierarchy request', ctx.client_id), - vim.log.levels.WARN) - end - end) -end - -return M diff --git a/lua/tms/medoro.lua b/lua/tms/medoro.lua @@ -2,7 +2,7 @@ local M = {} M.lang = function() -- TODO(tms) 17.12.22: little to specific not? - local cwd = '/home/tms/dev/medoro/dpgw/src/main/resources/org/medoro/dpgw/core/lang/' + local cwd = '/home/tms/dev/medoro/dpgw/server/src/main/resources/org/medoro/dpgw/core/lang/' local files = { 'lang.properties', 'lang_cs.properties' } require('telescope.builtin').live_grep({ cwd = cwd, diff --git a/plugin/snippet.lua b/plugin/snippet.lua @@ -9,3 +9,9 @@ vim.keymap.set({ 'i', 's' }, '<c-h>', function() vim.snippet.jump(-1) end end, { desc = 'Snippet Jump Forward' }) + +vim.keymap.set({ 'i', 's' }, '<c-e>', function() + if vim.snippet.active() then + vim.snippet.exit() + end +end, { desc = 'Snippet Exit' })