:retab
This commit is contained in:
parent
f1abf864c1
commit
b22873f45f
1 changed files with 56 additions and 56 deletions
|
|
@ -14,31 +14,31 @@ local data = {}
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local todo_comments_conf = {
|
local todo_comments_conf = {
|
||||||
TODO = {
|
TODO = {
|
||||||
-- TODO:
|
-- TODO:
|
||||||
-- NOTE:
|
-- NOTE:
|
||||||
-- INFO:
|
-- INFO:
|
||||||
"TODO", "NOTE", "INFO",
|
"TODO", "NOTE", "INFO",
|
||||||
hlgroup = "TodoTODO"
|
hlgroup = "TodoTODO"
|
||||||
},
|
},
|
||||||
BUG = {
|
BUG = {
|
||||||
-- BUG:
|
-- BUG:
|
||||||
-- FIXME:
|
-- FIXME:
|
||||||
"BUG", "FIXME",
|
"BUG", "FIXME",
|
||||||
hlgroup = "TodoBUG"
|
hlgroup = "TodoBUG"
|
||||||
},
|
},
|
||||||
TEST = {
|
TEST = {
|
||||||
-- TEST:
|
-- TEST:
|
||||||
-- PERF:
|
-- PERF:
|
||||||
"TEST", "PERF",
|
"TEST", "PERF",
|
||||||
hlgroup = "TodoTEST"
|
hlgroup = "TodoTEST"
|
||||||
},
|
},
|
||||||
WARN = {
|
WARN = {
|
||||||
-- WARN:
|
-- WARN:
|
||||||
-- HACK:
|
-- HACK:
|
||||||
"WARN", "HACK",
|
"WARN", "HACK",
|
||||||
hlgroup = "TodoWARN"
|
hlgroup = "TodoWARN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local todo_hl_ns = vim.api.nvim_create_namespace("todo_highlights")
|
local todo_hl_ns = vim.api.nvim_create_namespace("todo_highlights")
|
||||||
|
|
@ -125,44 +125,44 @@ end
|
||||||
---
|
---
|
||||||
--- ensure that we only change the extmark when the node has changed
|
--- ensure that we only change the extmark when the node has changed
|
||||||
function M.todo_comments()
|
function M.todo_comments()
|
||||||
local bufnr = vim.api.nvim_win_get_buf(0)
|
local bufnr = vim.api.nvim_win_get_buf(0)
|
||||||
local ok, parser = pcall(vim.treesitter.get_parser, bufnr)
|
local ok, parser = pcall(vim.treesitter.get_parser, bufnr)
|
||||||
if not ok or not parser then
|
if not ok or not parser then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create an entry for the buffer in the data
|
-- create an entry for the buffer in the data
|
||||||
if not data[bufnr] then
|
if not data[bufnr] then
|
||||||
data[bufnr] = {}
|
data[bufnr] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Construct the query for comments.
|
-- Construct the query for comments.
|
||||||
-- We're using treesitter so that I don't have to use external tooling.
|
-- We're using treesitter so that I don't have to use external tooling.
|
||||||
local ok, comment_query = pcall(vim.treesitter.query.parse,
|
local ok, comment_query = pcall(vim.treesitter.query.parse,
|
||||||
parser:lang(),
|
parser:lang(),
|
||||||
"(comment) @comment"
|
"(comment) @comment"
|
||||||
)
|
)
|
||||||
if not ok then
|
if not ok then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
parser:parse(false, function(err, trees)
|
parser:parse(false, function(err, trees)
|
||||||
if err then
|
if err then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- store the previous todo comment's location information
|
-- store the previous todo comment's location information
|
||||||
local start_loc = nil
|
local start_loc = nil
|
||||||
local ls, le, lt = nil, nil, nil
|
local ls, le, lt = nil, nil, nil
|
||||||
|
|
||||||
local root = trees[1]:root()
|
local root = trees[1]:root()
|
||||||
for _, match in comment_query:iter_matches(root, bufnr, 0, -1) do
|
for _, match in comment_query:iter_matches(root, bufnr, 0, -1) do
|
||||||
for _, nodes in pairs(match) do
|
for _, nodes in pairs(match) do
|
||||||
for _, node in ipairs(nodes) do
|
for _, node in ipairs(nodes) do
|
||||||
if not node or node:type() ~= "comment" then
|
if not node or node:type() ~= "comment" then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
local text = vim.treesitter.get_node_text(node, bufnr)
|
local text = vim.treesitter.get_node_text(node, bufnr)
|
||||||
|
|
||||||
-- is the node previous to this node a todo comment?
|
-- is the node previous to this node a todo comment?
|
||||||
local continuation = (start_loc and start_loc + 1 == node:start())
|
local continuation = (start_loc and start_loc + 1 == node:start())
|
||||||
|
|
@ -208,11 +208,11 @@ function M.todo_comments()
|
||||||
t
|
t
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue