Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

chore: remove :TSNodeUnderCursor/:TSHighlightCapturesUnderCursor #104

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 0 additions & 67 deletions lua/nvim-treesitter-playground/hl-info.lua
@@ -1,75 +1,8 @@
local utils = require "nvim-treesitter-playground.utils"
local highlighter = require "vim.treesitter.highlighter"
local ts_utils = require "nvim-treesitter.ts_utils"
local parsers = require "nvim-treesitter.parsers"

local M = {}

function M.get_treesitter_hl()
local bufnr = vim.api.nvim_get_current_buf()
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
row = row - 1

local results = utils.get_hl_groups_at_position(bufnr, row, col)
local highlights = {}
for _, hl in pairs(results) do
local line = "* **@" .. hl.capture .. "**"
if hl.priority then
line = line .. "(" .. hl.priority .. ")"
end
table.insert(highlights, line)
end
return highlights
end

function M.get_syntax_hl()
local line = vim.fn.line "."
local col = vim.fn.col "."
local matches = {}

for _, i1 in ipairs(vim.fn.synstack(line, col)) do
local i2 = vim.fn.synIDtrans(i1)
local n1 = vim.fn.synIDattr(i1, "name")
local n2 = vim.fn.synIDattr(i2, "name")
table.insert(matches, "* " .. n1 .. " -> **" .. n2 .. "**")
end

return matches
end

function M.show_hl_captures()
local buf = vim.api.nvim_get_current_buf()
local result = {}

local function add_to_result(matches, source)
if #matches == 0 then
return
end

table.insert(result, "# " .. source)

for _, match in ipairs(matches) do
table.insert(result, match)
end
end

if highlighter.active[buf] then
local matches = M.get_treesitter_hl()
add_to_result(matches, "Treesitter")
end

if vim.b.current_syntax ~= nil or #result == 0 then
local matches = M.get_syntax_hl()
add_to_result(matches, "Syntax")
end

if #result == 0 then
table.insert(result, "* No highlight groups found")
end

vim.lsp.util.open_floating_preview(result, "markdown", { border = "single", pad_left = 4, pad_right = 4 })
end

-- Show Node at Cursor
---@param opts? table with optional fields
--- - full_path: (boolean, default false) show full path to current node
Expand Down
8 changes: 6 additions & 2 deletions plugin/nvim-treesitter-playground.lua
Expand Up @@ -19,10 +19,14 @@ end, {})
api.nvim_create_user_command("TSNodeUnderCursor", function()
require("nvim-treesitter-playground.hl-info").show_ts_node()
end, {})
---@deprecated
api.nvim_create_user_command("TSCaptureUnderCursor", function()
require("nvim-treesitter-playground.hl-info").show_hl_captures()
vim.notify("TSCaptureUnderCursor was removed. Use Neovim's built-in `:Inspect` instead!", vim.log.levels.ERROR)
end, {})
---@deprecated
api.nvim_create_user_command("TSHighlightCapturesUnderCursor", function()
require("nvim-treesitter-playground.hl-info").show_hl_captures()
vim.notify(
"TSHighlightCapturesUnderCursor was removed. Use Neovim's built-in `:Inspect` instead!",
vim.log.levels.ERROR
)
end, {})