From 68475bba8489ea9e9cd9d6f158c99f9806f6cb74 Mon Sep 17 00:00:00 2001 From: Lukas Reineke Date: Fri, 26 Nov 2021 23:43:26 +0900 Subject: [PATCH] Version 1.3.1 * Un-indent context in documentation window --- doc/cmp-rg.txt | 5 ++++- lua/cmp-rg/init.lua | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/cmp-rg.txt b/doc/cmp-rg.txt index acf594a..d79eb73 100644 --- a/doc/cmp-rg.txt +++ b/doc/cmp-rg.txt @@ -2,7 +2,7 @@ Author: Lukas Reineke -Version: 1.3.0 +Version: 1.3.1 ============================================================================== CONTENTS *cmp-rg* @@ -105,6 +105,9 @@ debug *cmp-rg-debug* ============================================================================== 3. CHANGELOG *cmp-rg-changelog* +1.3.1 + * Un-indent context in documentation window + 1.3.0 * Add context documentation window * Add |cmp-rg-context_before| diff --git a/lua/cmp-rg/init.lua b/lua/cmp-rg/init.lua index 428318b..0371772 100644 --- a/lua/cmp-rg/init.lua +++ b/lua/cmp-rg/init.lua @@ -31,10 +31,22 @@ source.complete = function(self, request, callback) local documentation = result.data.lines.text:gsub("\n", "") table.insert(context, documentation) if documentation_to_add > 0 then - table.insert(items[#items].documentation, documentation) + local d = items[#items].documentation + table.insert(d, documentation) documentation_to_add = documentation_to_add - 1 + if documentation_to_add == 0 then - table.insert(items[#items].documentation, "```") + local min_indent = 1e309 + for i = 4, #d, 1 do + if d[i] ~= "" then + local _, indent = string.find(d[i], "^%s+") + min_indent = math.min(min_indent, indent or 0) + end + end + for i = 4, #d, 1 do + d[i] = d[i]:sub(min_indent) + end + table.insert(d, "```") end end elseif result.type == "match" then