neovim

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

commit 8413f98cc2f6ad484dbd065db2593a470a3e7e94
parent a788b10d8e45b76ef4a5d44553d478fd40672d3b
Author: Tomas Nemec <owl@gtms.dev>
Date:   Sat, 16 Dec 2023 20:52:51 +0100

update

Diffstat:
Dafter/plugin/diagflow.lua | 13-------------
Mafter/plugin/hardtime.lua | 2+-
Mcolors/tms.lua | 15++++++++++-----
Mlua/plugins.lua | 1-
Aplugin/diagflow.lua | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 141 insertions(+), 20 deletions(-)

diff --git a/after/plugin/diagflow.lua b/after/plugin/diagflow.lua @@ -1,13 +0,0 @@ -if not pcall(require, 'diagflow') then - return -end - -require('diagflow').setup { - padding_top = 2, - scope = 'line', - show_borders = true, - -- todo - -- toggle_event = { 'InsertEnter' }, - -- render_event = { 'DiagnosticChanged', 'CursorMoved' }, - -- update_event = { 'DiagnosticChanged', 'BufReadPost' }, -} diff --git a/after/plugin/hardtime.lua b/after/plugin/hardtime.lua @@ -2,4 +2,4 @@ if not pcall(require, 'hardtime') then return end -require('hardtime').setup { disabled_filetypes = { 'qf', 'netrw', 'dirbuf', 'mason', 'query' } } +-- require('hardtime').setup { disabled_filetypes = { 'qf', 'netrw', 'dirbuf', 'mason', 'query' } } diff --git a/colors/tms.lua b/colors/tms.lua @@ -332,12 +332,17 @@ vim.api.nvim_set_hl(0, 'CodeiumSuggestion', { link = 'Comment' }) vim.api.nvim_set_hl(0, 'LspReferenceText', { underline = true }) vim.api.nvim_set_hl(0, 'LspReferenceRead', { undercurl = true }) --- LSP highlighting -vim.api.nvim_set_hl(0, 'DiagnosticFloatingError', { fg = gui08, ctermfg = cterm08 }) -vim.api.nvim_set_hl(0, 'DiagnosticFloatingWarn', { fg = gui09, ctermfg = cterm09 }) -vim.api.nvim_set_hl(0, 'DiagnosticFloatingInfo', { fg = gui05, ctermfg = cterm05 }) -vim.api.nvim_set_hl(0, 'DiagnosticFloatingHint', { fg = gui03, ctermfg = cterm03 }) +-- Diagnostic +vim.api.nvim_set_hl(0, 'DiagnosticError', { fg = gui08, ctermfg = cterm08 }) +vim.api.nvim_set_hl(0, 'DiagnosticWarn', { fg = gui09, ctermfg = cterm09 }) +vim.api.nvim_set_hl(0, 'DiagnosticInfo', { fg = gui05, ctermfg = cterm05 }) +vim.api.nvim_set_hl(0, 'DiagnosticHint', { fg = gui03, ctermfg = cterm03 }) +-- vim.api.nvim_set_hl(0, 'DiagnosticFloatingError', { link = 'DiagnosticError' }) +-- vim.api.nvim_set_hl(0, 'DiagnosticFloatingWarn', { link = 'DiagnosticWarn' }) +-- vim.api.nvim_set_hl(0, 'DiagnosticFloatingInfo', { link = 'DiagnosticInfo' }) +-- vim.api.nvim_set_hl(0, 'DiagnosticFloatingHint', { link = 'DiagnosticHint' }) +-- LSP highlighting -- Hide all semantic highlights -- for _, group in ipairs(vim.fn.getcompletion('@lsp', 'highlight')) do -- vim.api.nvim_set_hl(0, group, {}) diff --git a/lua/plugins.lua b/lua/plugins.lua @@ -65,7 +65,6 @@ return require('paq') { -- can we get rid of this? 'folke/neodev.nvim', { 'jose-elias-alvarez/null-ls.nvim', requires = { 'nvim-lua/plenary.nvim' } }, - 'dgagn/diagflow.nvim', 'Exafunction/codeium.vim', 'mfussenegger/nvim-dap', 'leoluz/nvim-dap-go', diff --git a/plugin/diagflow.lua b/plugin/diagflow.lua @@ -0,0 +1,130 @@ +-- { +-- bufnr = 1, +-- code = "undefined-global", +-- col = 24, +-- end_col = 30, +-- end_lnum = 63, +-- lnum = 63, +-- message = "Undefined global `config`.", +-- namespace = 33, +-- severity = 2, +-- source = "Lua Diagnostics.", +-- user_data = { +-- lsp = { +-- code = "undefined-global" +-- } +-- } +-- } +local enable = true +local ns = vim.api.nvim_create_namespace 'DiagflowHighlight' +local severity_hl_map = { + [vim.diagnostic.severity.ERROR] = 'DiagnosticError', + [vim.diagnostic.severity.WARN] = 'DiagnosticWarn', + [vim.diagnostic.severity.INFO] = 'DiagnosticInfo', + [vim.diagnostic.severity.HINT] = 'DiagnosticHint', +} + +local function get_padding(bufnr, winnr) + if not pcall(require, 'treesitter-context.context') then + return 0 + end + + local context_lines = #(require('treesitter-context.context').get(bufnr, winnr) or {}) + if context_lines == 0 then + return 0 + end + + return context_lines + 1 -- +1 for the underline +end + +local function clear(bufnr) + bufnr = bufnr or vim.api.nvim_get_current_buf() + vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1) +end + +local function render(diagnostics, bufnr) + clear(bufnr) + + if not enable then + return + end + + bufnr = bufnr or vim.api.nvim_get_current_buf() + + if vim.diagnostic.is_disabled(bufnr) then + return + end + + local winnr + for _, win in ipairs(vim.api.nvim_list_wins()) do + if vim.api.nvim_win_get_buf(win) == bufnr then + winnr = win + break + end + end + + if not winnr then + return + end + + local padding = get_padding(bufnr, winnr) + local line_offset = vim.fn.getwininfo(winnr)[1].topline - 1 + padding + for _, diagnostic in ipairs(diagnostics) do + local hl_group = severity_hl_map[diagnostic.severity] + vim.api.nvim_buf_set_extmark(bufnr, ns, 0 + line_offset, 0, { + virt_text = { { diagnostic.message, hl_group } }, + virt_text_pos = 'right_align', + virt_text_hide = true, + strict = false, + }) + line_offset = line_offset + 1 + end +end + +local function reload() + if not enable then + clear() + return + end + + local cursor_lnum = vim.api.nvim_win_get_cursor(0)[1] - 1 + local diagnostics = vim.diagnostic.get(0, { lnum = cursor_lnum }) + render(diagnostics) +end + +local function toggle(force) + enable = force or not enable + + if enable then + reload() + else + clear() + end +end + +vim.api.nvim_create_autocmd('InsertEnter', { + callback = function() + toggle(false) + end, +}) +vim.api.nvim_create_autocmd('InsertLeave', { + callback = function() + toggle(true) + end, +}) +vim.api.nvim_create_autocmd({ 'DiagnosticChanged', 'CursorMoved', 'CursorMovedI', 'WinScrolled' }, { + callback = function() + reload() + vim.print( + #(require('treesitter-context.context').get(vim.api.nvim_get_current_buf(), vim.api.nvim_get_current_win()) or {})) + end, +}) +vim.api.nvim_create_autocmd({ 'BufLeave' }, { + callback = function() + clear() + end, +}) + +vim.api.nvim_create_user_command('Diagflow', function() + toggle() +end, { desc = 'Diagflow Toggle' })