diff --git a/lua/nvim-treesitter-playground/hl-info.lua b/lua/nvim-treesitter-playground/hl-info.lua index 7dc7a73..82e7197 100644 --- a/lua/nvim-treesitter-playground/hl-info.lua +++ b/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 diff --git a/plugin/nvim-treesitter-playground.lua b/plugin/nvim-treesitter-playground.lua index 8f98962..cfdc3f1 100644 --- a/plugin/nvim-treesitter-playground.lua +++ b/plugin/nvim-treesitter-playground.lua @@ -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, {})