diff --git a/lua/r/utils.lua b/lua/r/utils.lua index 35b03c85..1f8ea2c1 100644 --- a/lua/r/utils.lua +++ b/lua/r/utils.lua @@ -1,4 +1,5 @@ local warn = require("r.log").warn +local quarto = require("r.quarto") local uv = vim.uv local M = {} @@ -82,23 +83,8 @@ function M.get_lang() -- No treesitter parser for rhelp if vim.bo.filetype == "rhelp" then return get_rhelp_lang() end - local p - if vim.bo.filetype == "rmd" or vim.bo.filetype == "quarto" then - local cline = vim.api.nvim_get_current_line() - if cline:find("^```.*child *= *") then - return "chunk_child" - elseif cline:find("^```%{") then - return "chunk_header" - elseif cline:find("^```$") then - return "chunk_end" - end - p = vim.treesitter.get_parser(vim.api.nvim_get_current_buf(), "markdown") - else - p = vim.treesitter.get_parser() - end - local c = vim.api.nvim_win_get_cursor(0) - local lang = p:language_for_range({ c[1] - 1, c[2], c[1] - 1, c[2] }):lang() - return lang + local current_chunk = quarto.get_current_code_chunk(vim.api.nvim_get_current_buf()) + return current_chunk.lang end --- Request the windows manager to focus a window.