From 5c844ae911ab29c6595a2bb2f377c836b8b9fb91 Mon Sep 17 00:00:00 2001 From: Philippe Massicotte Date: Tue, 3 Nov 2026 08:54:40 -0500 Subject: [PATCH] fix(pipe): do not skip webr code chunks in qmd document I often use the pipe chain breaker (https://github.com/R-nvim/R.nvim/blob/0cfd62ac84505cd33b96949d083214f30cd040e3/lua/r/maps.lua#L277) and this was not working with webr code chunk. I was getting The cursor is not inside a piped expression With this PR, all r-related code chunks are detected, including webr code chunks. The pipe chain breaker now works with webr code chunks. --- lua/r/buffer.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lua/r/buffer.lua b/lua/r/buffer.lua index e7c6ecf9..6105bb19 100644 --- a/lua/r/buffer.lua +++ b/lua/r/buffer.lua @@ -25,20 +25,29 @@ M.create_r_buffer = function() "markdown", [[ (fenced_code_block - (info_string (language) @lang (#eq? @lang "r")) + (info_string (language) @lang) (code_fence_content) @content) ]] ) + local is_r = require("r.chunk").is_r local lines = {} local last_end = 0 local root = get_root_node(bufnr) if not root then return end - for id, node in query:iter_captures(root, bufnr, 0, -1) do - if query.captures[id] == "content" then - local start_row, _, end_row, _ = node:range() + for _, match in query:iter_matches(root, bufnr, 0, -1, { all = true }) do + local lang_node, content_node + for id, nodes in pairs(match) do + local name = query.captures[id] + if name == "lang" then lang_node = nodes[#nodes] end + if name == "content" then content_node = nodes[#nodes] end + end + + local lang = lang_node and vim.treesitter.get_node_text(lang_node, bufnr) + if content_node and lang and is_r(lang) then + local start_row, _, end_row, _ = content_node:range() -- Replace non-R content (including the chunk delimiters) with -- blank lines