Skip to content

Commit 569d566

Browse files
authored
Only warn of parsers needed by the current filetype (#589)
* Only warn of parsers needed by the current filetype * Delete language detection that doesn't work * Warn about one parser at a time
1 parent 7a30958 commit 569d566

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

lua/r/config.lua

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,22 +1360,34 @@ M.check_health = function()
13601360
"parser" .. (config.is_windows and "\\" or "/") .. "*.*",
13611361
true
13621362
)
1363-
if
1364-
not has_parser("r", parsers)
1365-
or not has_parser("markdown", parsers)
1366-
or not has_parser("rnoweb", parsers)
1367-
or not has_parser("yaml", parsers)
1368-
then
1369-
swarn(
1370-
'R.nvim requires treesitter parsers for "r", "markdown", "rnoweb", and "yaml". Please, install them.'
1371-
)
1363+
1364+
local needed = { "r" }
1365+
if vim.tbl_contains({ "rmd", "quarto", "rnoweb", "typst" }, vim.bo.filetype) then
1366+
table.insert(needed, "yaml")
1367+
end
1368+
if vim.tbl_contains({ "rmd", "quarto" }, vim.bo.filetype) then
1369+
table.insert(needed, "markdown")
1370+
table.insert(needed, "markdown_inline")
1371+
elseif vim.bo.filetype == "rnoweb" then
1372+
table.insert(needed, "rnoweb")
1373+
elseif vim.bo.filetype == "typst" then
1374+
table.insert(needed, "typst")
1375+
end
1376+
for _, v in pairs(needed) do
1377+
if not has_parser(v, parsers) then
1378+
swarn(
1379+
'R.nvim requires the tree-sitter parser for "'
1380+
.. v
1381+
.. '". Please, install it.'
1382+
)
1383+
break
1384+
end
13721385
end
13731386

13741387
if #smsgs > 0 then
13751388
local plural = #smsgs > 1 and "s" or ""
1376-
local msg = "\n " .. table.concat(smsgs, "\n ")
1377-
require("r.edit").add_to_debug_info("Startup warning" .. plural, msg)
1378-
msg = "R.nvim warning" .. plural .. ":" .. msg
1389+
local msg = " " .. table.concat(smsgs, "\n ")
1390+
require("r.edit").add_to_debug_info("Startup warning" .. plural, "\n" .. msg)
13791391
vim.schedule(function()
13801392
vim.defer_fn(function() require("r.log").warn(msg) end, 200)
13811393
end)

lua/r/edit.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@ local check_lang = function()
220220

221221
-- Expected language at different cursor positions
222222
local qlangs = {
223-
{ "yaml", 2, 0, "" },
224223
{ "markdown", 4, 0, "" },
225-
{ "markdown_inline", 5, 0, "" },
226224
{ "r", 8, 0, "" },
227225
}
228226

0 commit comments

Comments
 (0)