From 46eb5f3fd3dba0a3bb3d026fb2b7462f4a0656b7 Mon Sep 17 00:00:00 2001 From: Liam Dyer Date: Wed, 18 Dec 2024 11:51:32 -0500 Subject: [PATCH] refactor: misc cleanup --- lua/blink/cmp/lib/window/docs.lua | 50 ++++--------------------------- lua/blink/cmp/sources/luasnip.lua | 2 +- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/lua/blink/cmp/lib/window/docs.lua b/lua/blink/cmp/lib/window/docs.lua index 230e3a8d..44001130 100644 --- a/lua/blink/cmp/lib/window/docs.lua +++ b/lua/blink/cmp/lib/window/docs.lua @@ -15,10 +15,6 @@ function docs.render_detail_and_documentation(bufnr, detail, documentation, max_ if documentation ~= nil then local doc = type(documentation) == 'string' and documentation or documentation.value doc_lines = docs.split_lines(doc) - -- if type(documentation) ~= 'string' and documentation.kind == 'markdown' then - -- -- if the rendering seems bugged, it's likely due to this function - -- doc_lines = docs.combine_markdown_lines(doc_lines) - -- end end detail_lines, doc_lines = docs.extract_detail_from_doc(detail_lines, doc_lines) @@ -27,7 +23,7 @@ function docs.render_detail_and_documentation(bufnr, detail, documentation, max_ -- add a blank line for the --- separator local doc_already_has_separator = #doc_lines > 1 and (doc_lines[1] == '---' or doc_lines[1] == '***') - if #detail_lines > 0 and #doc_lines > 0 then table.insert(combined_lines, '') end + if #detail_lines > 0 and #doc_lines > 0 then table.insert(combined_lines, '') end -- skip original separator in doc_lines, so we can highlight it later vim.list_extend(combined_lines, doc_lines, doc_already_has_separator and 2 or 1) @@ -37,7 +33,9 @@ function docs.render_detail_and_documentation(bufnr, detail, documentation, max_ -- Highlight with treesitter vim.api.nvim_buf_clear_namespace(bufnr, highlight_ns, 0, -1) - if #detail_lines > 0 and use_treesitter_highlighting then docs.highlight_with_treesitter(bufnr, vim.bo.filetype, 0, #detail_lines) end + if #detail_lines > 0 and use_treesitter_highlighting then + docs.highlight_with_treesitter(bufnr, vim.bo.filetype, 0, #detail_lines) + end -- Only add the separator if there are documentation lines (otherwise only display the detail) if #detail_lines > 0 and #doc_lines > 0 then @@ -119,40 +117,6 @@ function docs.highlight_with_treesitter(bufnr, filetype, start_line, end_line) end) end ---- Combines adjacent paragraph lines together ---- @param lines string[] ---- @return string[] ---- TODO: Likely buggy -function docs.combine_markdown_lines(lines) - local combined_lines = {} - - local special_starting_chars = { '#', '>', '-', '|', '*', '•' } - local in_code_block = false - local prev_is_special = false - for _, line in ipairs(lines) do - if line:match('^%s*```') then in_code_block = not in_code_block end - -- skip separators - if line:match('^[%s\\-]+$') then goto continue end - - local is_special = line:match('^%s*[' .. table.concat(special_starting_chars) .. ']') or line:match('^%s*%d\\.$') - local is_empty = line:match('^%s*$') - local has_linebreak = line:match('%s%s$') - - if #combined_lines == 0 or in_code_block or is_special or prev_is_special or is_empty or has_linebreak then - table.insert(combined_lines, line) - elseif line:match('^%s*$') then - if combined_lines[#combined_lines] ~= '' then table.insert(combined_lines, '') end - else - combined_lines[#combined_lines] = combined_lines[#combined_lines] .. '' .. line - end - - prev_is_special = is_special - ::continue:: - end - - return combined_lines -end - --- Gets the start and end row of the code block for the given row --- Or returns nil if there's no code block --- @param lines string[] @@ -202,12 +166,10 @@ function docs.extract_detail_from_doc(detail_lines, doc_lines) local doc_str_detail_row = doc_str:find(detail_str, 1, true) -- didn't find the detail in the doc, so return as is - if doc_str_detail_row == nil or #detail_str == 0 or #doc_str == 0 then - return detail_lines, doc_lines - end + if doc_str_detail_row == nil or #detail_str == 0 or #doc_str == 0 then return detail_lines, doc_lines end -- get the line of the match - -- hack: surely there's a better way to do this but it's late + -- hack: surely there's a better way to do this but it's late -- and I can't be bothered local offset = 1 local detail_line = 1 diff --git a/lua/blink/cmp/sources/luasnip.lua b/lua/blink/cmp/sources/luasnip.lua index 564de19c..099a5451 100644 --- a/lua/blink/cmp/sources/luasnip.lua +++ b/lua/blink/cmp/sources/luasnip.lua @@ -121,7 +121,7 @@ function source:execute(_, item) local luasnip = require('luasnip') local snip = luasnip.get_id_snippet(item.data.snip_id) - -- if trigger is a pattern, expand "pattern" instead of actual snippet. + -- if trigger is a pattern, expand "pattern" instead of actual snippet if snip.regTrig then snip = snip:get_pattern_expand_helper() end -- get (0, 0) indexed cursor position