diff options
author | Gregory Anders <greg@gpanders.com> | 2021-09-17 19:57:14 -0600 |
---|---|---|
committer | Gregory Anders <greg@gpanders.com> | 2021-09-17 21:07:24 -0600 |
commit | 15d501ff7aa37fd507e57069b90ddab8a8eb55c5 (patch) | |
tree | aa4b3dfe4c896414ad3761bd06053ff5862f3f1a /runtime/lua/vim/diagnostic.lua | |
parent | 938ed458e2818b7840e9c4eaf298c5a7af8d79ea (diff) | |
download | rneovim-15d501ff7aa37fd507e57069b90ddab8a8eb55c5.tar.gz rneovim-15d501ff7aa37fd507e57069b90ddab8a8eb55c5.tar.bz2 rneovim-15d501ff7aa37fd507e57069b90ddab8a8eb55c5.zip |
refactor(diagnostic): group local functions together
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 18a2023b50..1e7f95a353 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -426,6 +426,70 @@ local function set_list(loclist, opts) end end +---@private +local function next_diagnostic(position, search_forward, bufnr, opts, namespace) + position[1] = position[1] - 1 + bufnr = bufnr or vim.api.nvim_get_current_buf() + local wrap = vim.F.if_nil(opts.wrap, true) + local line_count = vim.api.nvim_buf_line_count(bufnr) + opts.namespace = namespace + for i = 0, line_count do + local offset = i * (search_forward and 1 or -1) + local lnum = position[1] + offset + if lnum < 0 or lnum >= line_count then + if not wrap then + return + end + lnum = (lnum + line_count) % line_count + end + opts.lnum = lnum + local line_diagnostics = M.get(bufnr, opts) + if line_diagnostics and not vim.tbl_isempty(line_diagnostics) then + local sort_diagnostics, is_next + if search_forward then + sort_diagnostics = function(a, b) return a.col < b.col end + is_next = function(diagnostic) return diagnostic.col > position[2] end + else + sort_diagnostics = function(a, b) return a.col > b.col end + is_next = function(diagnostic) return diagnostic.col < position[2] end + end + table.sort(line_diagnostics, sort_diagnostics) + if i == 0 then + for _, v in pairs(line_diagnostics) do + if is_next(v) then + return v + end + end + else + return line_diagnostics[1] + end + end + end +end + +---@private +local function diagnostic_move_pos(opts, pos) + opts = opts or {} + + local enable_popup = vim.F.if_nil(opts.enable_popup, true) + local win_id = opts.win_id or vim.api.nvim_get_current_win() + + if not pos then + vim.api.nvim_echo({{"No more valid diagnostics to move to", "WarningMsg"}}, true, {}) + return + end + + vim.api.nvim_win_set_cursor(win_id, {pos[1] + 1, pos[2]}) + + if enable_popup then + -- This is a bit weird... I'm surprised that we need to wait til the next tick to do this. + vim.schedule(function() + M.show_position_diagnostics(opts.popup_opts, vim.api.nvim_win_get_buf(win_id)) + end) + end +end + + -- }}} -- Public API {{{ @@ -596,70 +660,6 @@ function M.get(bufnr, opts) return diagnostics end --- Diagnostic Movements {{{ - -local next_diagnostic = function(position, search_forward, bufnr, opts, namespace) - position[1] = position[1] - 1 - bufnr = bufnr or vim.api.nvim_get_current_buf() - local wrap = vim.F.if_nil(opts.wrap, true) - local line_count = vim.api.nvim_buf_line_count(bufnr) - opts.namespace = namespace - for i = 0, line_count do - local offset = i * (search_forward and 1 or -1) - local lnum = position[1] + offset - if lnum < 0 or lnum >= line_count then - if not wrap then - return - end - lnum = (lnum + line_count) % line_count - end - opts.lnum = lnum - local line_diagnostics = M.get(bufnr, opts) - if line_diagnostics and not vim.tbl_isempty(line_diagnostics) then - local sort_diagnostics, is_next - if search_forward then - sort_diagnostics = function(a, b) return a.col < b.col end - is_next = function(diagnostic) return diagnostic.col > position[2] end - else - sort_diagnostics = function(a, b) return a.col > b.col end - is_next = function(diagnostic) return diagnostic.col < position[2] end - end - table.sort(line_diagnostics, sort_diagnostics) - if i == 0 then - for _, v in pairs(line_diagnostics) do - if is_next(v) then - return v - end - end - else - return line_diagnostics[1] - end - end - end -end - ----@private -local function diagnostic_move_pos(opts, pos) - opts = opts or {} - - local enable_popup = vim.F.if_nil(opts.enable_popup, true) - local win_id = opts.win_id or vim.api.nvim_get_current_win() - - if not pos then - vim.api.nvim_echo({{"No more valid diagnostics to move to", "WarningMsg"}}, true, {}) - return - end - - vim.api.nvim_win_set_cursor(win_id, {pos[1] + 1, pos[2]}) - - if enable_popup then - -- This is a bit weird... I'm surprised that we need to wait til the next tick to do this. - vim.schedule(function() - M.show_position_diagnostics(opts.popup_opts, vim.api.nvim_win_get_buf(win_id)) - end) - end -end - --- Get the previous diagnostic closest to the cursor position. --- ---@param opts table See |vim.diagnostic.goto_next()| |