Skip to content

Commit

Permalink
fix(api): Don't throw error on highlight, notify and skip instead.
Browse files Browse the repository at this point in the history
Signed-off-by: Guennadi Maximov C <[email protected]>
  • Loading branch information
DrKJeff16 committed Sep 2, 2024
1 parent a8bc788 commit 52a5ce5
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions lua/user_api/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function M.hl(name, opts, bufnr)
local empty = Value.empty

if not (is_str(name) and is_tbl(opts)) or empty(name) then
error('(user_api.highlight.hl): A highlight value is not permitted!')
vim.notify('(user_api.highlight.hl): Bad arguments', vim.log.levels.ERROR)
return
end

bufnr = is_int(bufnr) and bufnr or 0
Expand All @@ -34,15 +35,22 @@ function M.hl_from_arr(A)
local empty = Value.empty

if not is_tbl(A) or empty(A) then
error('(user_api.highlight.hl_from_arr): Unable to parse argument.')
vim.notify('(user_api.highlight.hl_from_arr): Bad argument', vim.log.levels.ERROR)
return
end

for _, t in next, A do
if not (is_str(t.name) and is_tbl(t.opts)) or empty(t.name) then
error('(user_api.highlight.hl_from_arr): A highlight value is not permitted!')
vim.notify(
'(user_api.highlight.hl_from_arr): A highlight value is not permitted, skipping',
vim.log.levels.ERROR
)
goto continue
end

M.hl(t.name, t.opts)

::continue::
end
end

Expand Down Expand Up @@ -70,15 +78,26 @@ function M.hl_from_dict(D)
local empty = Value.empty

if not is_tbl(D) or empty(D) then
error('(user_api.highlight.hl_from_dict): Unable to parse argument.')
vim.notify(
'(user_api.highlight.hl_from_dict): Unable to parse argument',
vim.log.levels.ERROR
)
return
end

for k, v in next, D do
if (is_str(k) and is_tbl(v)) and not empty(k) then
M.hl(k, v)
else
error('(user_api.highlight.hl_from_dict): A highlight value is not permitted!')
if not (is_str(k) and is_tbl(v)) or empty(k) then
vim.notify(
'(user_api.highlight.hl_from_dict): A highlight value is not permitted, skipping',
vim.log.levels.ERROR
)

goto continue
end

M.hl(k, v)

::continue::
end
end

Expand Down

0 comments on commit 52a5ce5

Please sign in to comment.