aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/dev.lua
diff options
context:
space:
mode:
authorObserverOfTime <chronobserver@disroot.org>2023-08-07 16:16:12 +0300
committerGitHub <noreply@github.com>2023-08-07 06:16:12 -0700
commit369f58797dbd3c0e18035d26e6f5d6634be7a2a9 (patch)
treeecd639771d45cc9c63c1ec61eac1c6234479a215 /runtime/lua/vim/treesitter/dev.lua
parent3a21c3afe61e5bb76f4b81c1a961b2558e2c8f0a (diff)
downloadrneovim-369f58797dbd3c0e18035d26e6f5d6634be7a2a9.tar.gz
rneovim-369f58797dbd3c0e18035d26e6f5d6634be7a2a9.tar.bz2
rneovim-369f58797dbd3c0e18035d26e6f5d6634be7a2a9.zip
fix(treesitter): escape quotes in :InspectTree view #24582
Problem: Anonymous nodes containing double quotes break the highlighting. Solution: Escape double quotes in anonymous nodes.
Diffstat (limited to 'runtime/lua/vim/treesitter/dev.lua')
-rw-r--r--runtime/lua/vim/treesitter/dev.lua9
1 files changed, 8 insertions, 1 deletions
diff --git a/runtime/lua/vim/treesitter/dev.lua b/runtime/lua/vim/treesitter/dev.lua
index 1bb5a08205..e94e8f08dc 100644
--- a/runtime/lua/vim/treesitter/dev.lua
+++ b/runtime/lua/vim/treesitter/dev.lua
@@ -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)
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}.
---
---@param bufnr integer Buffer number to write into.
@@ -164,8 +170,9 @@ function TSTreeView:draw(bufnr)
for _, item in self:iter() do
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 text = item.named and item.text or escape_quotes(item.text)
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
lang_hl_marks[#lang_hl_marks + 1] = {