Skip to content

Commit

Permalink
wip: works fine apart from tab spaced lines
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed May 26, 2024
1 parent 5424e07 commit 307ff71
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
8 changes: 8 additions & 0 deletions lua/precognition/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ function M.inlay_hints_enabled(t)
return false
end

function M.flatten(t)
if vim.fn.has("nvim-0.11") then
return vim.iter(t):flatten():totable()
else
return vim.tbl_flatten(t)
end
end

return M
31 changes: 15 additions & 16 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ local config = default
---@type integer?
local extmark -- the active extmark in the current buffer
---@type boolean
local dirty -- whether a redraw is needed
local dirty -- whether a redraw is needed
---@type boolean
local visible = false
---@type string
local gutter_name_prefix = "precognition_gutter_" -- prefix for gutter signs object naame
---@type {SupportedGutterHints: { line: integer, id: integer }} -- cache for gutter signs
local gutter_signs_cache = {} -- cache for gutter signs
local gutter_signs_cache = {} -- cache for gutter signs

---@type integer
local au = vim.api.nvim_create_augroup("precognition", { clear = true })
Expand Down Expand Up @@ -151,24 +151,23 @@ local function build_virt_line(marks, line_num, line_len)
["end"] = { line = line_num - 1, character = line_len - 1 },
},
})
-- sort the hints by start character
table.sort(inlays_hints, function(a, b)
return a.inlay_hint.label[1].location.range.start.character
< b.inlay_hint.label[1].location.range.start.character
end)

local total_added = 0
local i = 0

-- local total_added = 0
-- local i = 0
for _, hint in ipairs(inlays_hints) do
local length = #hint.inlay_hint.label[1].value + 1
local start = hint.inlay_hint.label[1].location.range.start.character + 1
local start = hint.inlay_hint.label[1].location.range.start.character + 2
vim.print(vim.inspect(hint.inlay_hint.label[1]))
-- + 2 as we want to add to the character after the hint
-- Pad characters to the left of the hint to avoid overlapping with the inlay hint
local pad = utils.create_pad_array(length, "")
table.insert(line_table, start + 1, pad)
total_added = total_added + length
i = i + 1
vim.print("Added " .. total_added .. " spaces over " .. i .. "occurrences")
local pad = utils.create_pad_array(length, " ")
table.insert(line_table, start, pad)
vim.print("Added " .. length .. " spaces at " .. start)
-- total_added = total_added + length
-- i = i + 1
-- vim.print("Added " .. total_added .. " spaces over " .. i .. " occurrences")
end
line_table = compat.flatten(line_table)
end
local line = table.concat(line_table)
if line:match("^%s+$") then
Expand Down
8 changes: 4 additions & 4 deletions tests/precognition/virtline_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe("replacment charcters", function()
Caret = 1,
}

local virtual_line = precognition.build_virt_line(marks, 1)
local virtual_line = precognition.build_virt_line(marks, 1, 1)
eq("x", virtual_line[1][1])
eq(1, #virtual_line[1][1])
end)
Expand All @@ -246,7 +246,7 @@ describe("replacment charcters", function()
Caret = 1,
}

local virtual_line = precognition.build_virt_line(marks, 1)
local virtual_line = precognition.build_virt_line(marks, 1, 1)
eq("â", virtual_line[1][1])
eq(2, #virtual_line[1][1])
end)
Expand All @@ -263,7 +263,7 @@ describe("replacment charcters", function()
Dollar = 8,
}

local virtual_line = precognition.build_virt_line(marks, 8)
local virtual_line = precognition.build_virt_line(marks, 1, 8)
eq("0^e w $", virtual_line[1][1])
end)

Expand All @@ -288,7 +288,7 @@ describe("replacment charcters", function()
Dollar = 8,
}

local virtual_line = precognition.build_virt_line(marks, 8)
local virtual_line = precognition.build_virt_line(marks, 1, 8)
eq("0âe w $", virtual_line[1][1])
end)
end)

0 comments on commit 307ff71

Please sign in to comment.