feat: buf highlights for current buffer fuzzy find (#732)

* feat: Add buffer highlights from treesitter

* fix: Handle not having tree sitter in some buffers

* fixup

* fixup

* fixup: move back to old node
This commit is contained in:
TJ DeVries
2021-04-06 19:59:42 -04:00
committed by GitHub
parent d0cf646f65
commit 0b2c801978
5 changed files with 104 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
local a = vim.api
local ns = a.nvim_create_namespace("treesitter/highlighter")
print(ns)
local bufnr = 0
-- P(a.nvim_buf_get_extmarks(bufnr, ns, 0, -1, { details = true }))
local parser = vim.treesitter.get_parser(bufnr, "lua")
local query = vim.treesitter.get_query("lua", "highlights")
P(query)
local root = parser:parse()[1]:root()
print("root", root)
local highlighter = vim.treesitter.highlighter.new(parser)
local highlighter_query = highlighter:get_query("lua")
for id, node, metadata in query:iter_captures(root, bufnr, 0, -1) do
local row1, col1, row2, col2 = node:range()
print(highlighter_query.hl_cache[id])
-- print(id, node, metadata, vim.treesitter.get_node_text(node, bufnr))
-- print(">>>>", row1, col1, row2, col2)
end