mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
fix(treesitter): escape quotes in :InspectTree view #24582
Problem: Anonymous nodes containing double quotes break the highlighting. Solution: Escape double quotes in anonymous nodes.
This commit is contained in:
@@ -152,6 +152,12 @@ local function get_range_str(lnum, col, end_lnum, end_col)
|
|||||||
return string.format('[%d:%d - %d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
|
return string.format('[%d:%d - %d:%d]', lnum + 1, col + 1, end_lnum + 1, end_col)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param text string
|
||||||
|
---@return string
|
||||||
|
local function escape_quotes(text)
|
||||||
|
return string.format('"%s"', text:sub(2, #text - 1):gsub('"', '\\"'))
|
||||||
|
end
|
||||||
|
|
||||||
--- Write the contents of this View into {bufnr}.
|
--- Write the contents of this View into {bufnr}.
|
||||||
---
|
---
|
||||||
---@param bufnr integer Buffer number to write into.
|
---@param bufnr integer Buffer number to write into.
|
||||||
@@ -164,8 +170,9 @@ function TSTreeView:draw(bufnr)
|
|||||||
for _, item in self:iter() do
|
for _, item in self:iter() do
|
||||||
local range_str = get_range_str(item.lnum, item.col, item.end_lnum, item.end_col)
|
local range_str = get_range_str(item.lnum, item.col, item.end_lnum, item.end_col)
|
||||||
local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
|
local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
|
||||||
|
local text = item.named and item.text or escape_quotes(item.text)
|
||||||
local line =
|
local line =
|
||||||
string.format('%s%s ; %s%s', string.rep(' ', item.depth), item.text, range_str, lang_str)
|
string.format('%s%s ; %s%s', string.rep(' ', item.depth), text, range_str, lang_str)
|
||||||
|
|
||||||
if self.opts.lang then
|
if self.opts.lang then
|
||||||
lang_hl_marks[#lang_hl_marks + 1] = {
|
lang_hl_marks[#lang_hl_marks + 1] = {
|
||||||
|
Reference in New Issue
Block a user