Skip to content

Commit

Permalink
Merge branch 'main' into count_motions
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 authored May 22, 2024
2 parents 7b204b0 + 455f527 commit 0dd4c9c
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 126 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ return {
config = {
-- startVisible = true,
-- showBlankVirtLine = true,
-- highlightColor = "Comment",
-- hints = {
-- Caret = { text = "^", prio = 2 },
-- Dollar = { text = "$", prio = 1 },
Expand Down
7 changes: 5 additions & 2 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ local M = {}
---@class Precognition.Config
---@field startVisible boolean
---@field showBlankVirtLine boolean
---@field highlightColor string
---@field hints Precognition.HintConfig
---@field gutterHints Precognition.GutterHintConfig

---@class Precognition.PartialConfig
---@field startVisible? boolean
---@field showBlankVirtLine? boolean
---@field highlightColor? string
---@field hints? Precognition.HintConfig
---@field gutterHints? Precognition.GutterHintConfig

Expand Down Expand Up @@ -70,6 +72,7 @@ local defaultHintConfig = {
local default = {
startVisible = true,
showBlankVirtLine = true,
highlightColor = "Comment",
hints = defaultHintConfig,
gutterHints = {
--prio is not currentlt used for gutter hints
Expand Down Expand Up @@ -142,7 +145,7 @@ local function build_virt_line(marks, line_len)
if line:match("^%s+$") then
return {}
end
table.insert(virt_line, { line, "Comment" })
table.insert(virt_line, { line, config.highlightColor })
return virt_line
end

Expand Down Expand Up @@ -174,7 +177,7 @@ local function apply_gutter_hints(gutter_hints, bufnr)
end
vim.fn.sign_define(gutter_name_prefix .. hint, {
text = config.gutterHints[hint].text,
texthl = "Comment",
texthl = config.highlightColor,
})
local ok, res = pcall(vim.fn.sign_place, 0, gutter_group, gutter_name_prefix .. hint, bufnr, {
lnum = loc,
Expand Down
2 changes: 1 addition & 1 deletion lua/precognition/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ M.char_classes = {
---@param big_word boolean
---@return integer
function M.char_class(char, big_word)
big_word = big_word or false
assert(type(big_word) == "boolean", "big_word must be a boolean")
local cc = M.char_classes
local byte = string.byte(char)

Expand Down
8 changes: 4 additions & 4 deletions lua/precognition/vertical_motions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function M.next_paragraph_line(bufnr)
local cursorline, _ = unpack(vim.api.nvim_win_get_cursor(0))
while not found and cursorline < visibleline do
local cursorlinecontent = buffcontent[cursorline]
while cursorline < visibleline and cursorlinecontent:match("^%s*$") do
while cursorline < visibleline and cursorlinecontent:match("^[\n\r]*$") do
cursorline = cursorline + 1
cursorlinecontent = buffcontent[cursorline]
end
-- find next blank line below
while cursorline < visibleline and not found do
cursorline = cursorline + 1
cursorlinecontent = buffcontent[cursorline]
if cursorlinecontent:match("^%s*$") then
if cursorlinecontent:match("^[\n\r]*$") then
found = true
end
end
Expand All @@ -54,15 +54,15 @@ function M.prev_paragraph_line(bufnr)
local cursorline, _ = unpack(vim.api.nvim_win_get_cursor(0))
while not found and cursorline > visibleline do
local cursorlinecontent = buffcontent[cursorline]
while cursorline > visibleline and cursorlinecontent:match("^%s*$") do
while cursorline > visibleline and cursorlinecontent:match("^[\n\r]*$") do
cursorline = cursorline - 1
cursorlinecontent = buffcontent[cursorline]
end
-- find next blank line above
while cursorline > visibleline and not found do
cursorline = cursorline - 1
cursorlinecontent = buffcontent[cursorline]
if cursorlinecontent:match("^%s*$") then
if cursorlinecontent:match("^[\n\r]*$") then
found = true
end
end
Expand Down
52 changes: 51 additions & 1 deletion tests/precognition/e2e_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ describe("e2e tests", function()
eq(7, vim.tbl_count(autocmds))
end)

-- 0.1 onlu?
-- 0.1 only
-- it("namespace is created", function()
-- local ns = vim.api.nvim_get_namespaces()
--
-- eq(1, ns["precognition"])
-- eq(2, ns["precognition_gutter"])
-- :end)
-- end)
--
it("virtual line is displayed and updated", function()
local buffer = vim.api.nvim_create_buf(true, false)
Expand All @@ -59,12 +60,16 @@ describe("e2e tests", function()

for _, extmark in pairs(gutter_extmarks) do
if extmark[4].sign_text == "G " then
eq("Comment", extmark[4].sign_hl_group)
eq(5, extmark[2])
elseif extmark[4].sign_text == "gg" then
eq("Comment", extmark[4].sign_hl_group)
eq(0, extmark[2])
elseif extmark[4].sign_text == "{ " then
eq("Comment", extmark[4].sign_hl_group)
eq(0, extmark[2])
elseif extmark[4].sign_text == "} " then
eq("Comment", extmark[4].sign_hl_group)
eq(2, extmark[2])
else
assert(false, "unexpected sign text")
Expand All @@ -73,6 +78,7 @@ describe("e2e tests", function()

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])
eq("Comment", extmarks[3].virt_lines[1][1][2])

vim.api.nvim_win_set_cursor(0, { 1, 6 })
precognition.on_cursor_moved()
Expand Down Expand Up @@ -148,4 +154,48 @@ describe("e2e tests", function()
end
end
end)

it("virtual line text color can be customised", function()
precognition.setup({ highlightColor = "Function" })
local buffer = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buffer)
vim.api.nvim_buf_set_lines(
buffer,
0,
-1,
false,
{ "Hello World this is a test", "line 2", "", "line 4", "", "line 6" }
)
vim.api.nvim_win_set_cursor(0, { 1, 1 })

precognition.on_cursor_moved()

local extmarks = vim.api.nvim_buf_get_extmark_by_id(buffer, precognition.ns, precognition.extmark, {
details = true,
})

local gutter_extmarks = get_gutter_extmarks(buffer)

for _, extmark in pairs(gutter_extmarks) do
if extmark[4].sign_text == "G " then
eq("Function", extmark[4].sign_hl_group)
eq(5, extmark[2])
elseif extmark[4].sign_text == "gg" then
eq("Function", extmark[4].sign_hl_group)
eq(0, extmark[2])
elseif extmark[4].sign_text == "{ " then
eq("Function", extmark[4].sign_hl_group)
eq(0, extmark[2])
elseif extmark[4].sign_text == "} " then
eq("Function", extmark[4].sign_hl_group)
eq(2, extmark[2])
else
assert(false, "unexpected sign text")
end
end

eq(vim.api.nvim_win_get_cursor(0)[1] - 1, extmarks[1])
eq("b e w $", extmarks[3].virt_lines[1][1][1])
eq("Function", extmarks[3].virt_lines[1][1][2])
end)
end)
Loading

0 comments on commit 0dd4c9c

Please sign in to comment.