From cfafc3baef0d167c81353e70371a3e2f6c830664 Mon Sep 17 00:00:00 2001 From: bekaboo <18127878294@qq.com> Date: Thu, 30 Nov 2023 12:46:34 +0800 Subject: [PATCH 1/3] feat: allow multiple hlgroups inside one column --- lua/oil/init.lua | 2 +- lua/oil/util.lua | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 72e87fc8..899fa384 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -7,7 +7,7 @@ local M = {} ---@field parsed_name nil|string ---@alias oil.EntryType "file"|"directory"|"socket"|"link"|"fifo" ----@alias oil.TextChunk string|string[] +---@alias oil.TextChunk string|string[]|{ [1]: string, [2]: { [1]: string, [2]: integer, [3]: integer }[] } ---@alias oil.CrossAdapterAction "copy"|"move" ---@class (exact) oil.Adapter diff --git a/lua/oil/util.lua b/lua/oil/util.lua index 027b5db8..6649f435 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -302,7 +302,21 @@ M.render_table = function(lines, col_width) table.insert(pieces, text) local col_end = col + text:len() + 1 if hl then - table.insert(highlights, { hl, #str_lines, col, col_end }) + if type(hl) == "table" then + -- hl has the form { [1]: hl_name, [2]: col_start, [3]: col_end }[] + -- Notice that col_start and col_end are relative position inside + -- that col, so we need to add the offset to them + for _, sub_hl in ipairs(hl) do + table.insert(highlights, { + sub_hl[1], + #str_lines, + col + sub_hl[2], + col + sub_hl[3], + }) + end + else + table.insert(highlights, { hl, #str_lines, col, col_end }) + end end col = col_end end From f4eaf1850bb147598d1712fbb3c0cbefc968a0f6 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:31:58 -0800 Subject: [PATCH 2/3] types: refactor formatting of highlight types --- lua/oil/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 899fa384..747f9e31 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -7,7 +7,10 @@ local M = {} ---@field parsed_name nil|string ---@alias oil.EntryType "file"|"directory"|"socket"|"link"|"fifo" ----@alias oil.TextChunk string|string[]|{ [1]: string, [2]: { [1]: string, [2]: integer, [3]: integer }[] } +---@alias oil.HlRange { [1]: string, [2]: integer, [3]: integer } A tuple of highlight group name, col_start, col_end +---@alias oil.HlTuple { [1]: string, [2]: string } A tuple of text, highlight group +---@alias oil.HlRangeTuple { [1]: string, [2]: oil.HlRange[] } A tuple of text, internal highlights +---@alias oil.TextChunk string|oil.HlTuple|oil.HlRangeTuple ---@alias oil.CrossAdapterAction "copy"|"move" ---@class (exact) oil.Adapter From 1d80329192a00c364400cfbe30872effc4acc54a Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:32:46 -0800 Subject: [PATCH 3/3] types: LuaLS can't infer type information from unpack --- lua/oil/util.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/oil/util.lua b/lua/oil/util.lua index 6649f435..dc12d7f5 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -294,7 +294,8 @@ M.render_table = function(lines, col_width) for i, chunk in ipairs(cols) do local text, hl if type(chunk) == "table" then - text, hl = unpack(chunk) + text = chunk[1] + hl = chunk[2] else text = chunk end