Open JulianDicken opened 7 months ago
If you need me to supply any other info lmk
Thanks for the report. I'm going to need more info, in particular, what do you mean by "no syntax highlighting at all". Does the document look like there is no syntax highlighting at all, meaning it is just black and white text? Do you find that there is no syntax highlight of R code blocks when stand-alone R code is correctly highlighted? Likewise, do you mean that regular stand-alone latex is correctly highlighted and is not highlighted in the Rnoweb document? See below for a basic reproducible example of the parser working correctly when paired with Lazy.nvim and nvim-treesitter. Please point out where your experience deviates.
Below is a very basic init.lua
using Lazy.nvim to setup nvim-treesitter, and no other plugins; note that "highlight.enable" is initially set to "false" and vim.cmd("syntax off")
:
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
-- Tree-Sitter
{ 'nvim-treesitter/nvim-treesitter',
config = function()
require'nvim-treesitter.configs'.setup {
ensure_installed = "all",
highlight = {
enable = false,
additional_vim_regex_highlighting = false,
},
indent = { enable = true, },
}
end
},
})
vim.cmd("syntax off")
And here is a very basic rnoweb document with some latex and some R code:
\documentclass[12pt,a4paper]{article}
\title{Test Document}
\begin{document}
\maketitle
\doublespacing
\section{Introduction}
Hello World!
<<echo = FALSE, results = "asis">>=
for (i in 1:10) {
print(i)
}
@
\Sexpr{one <- 1 + 1}
\end{document}
And the same document without the R code:
\documentclass[12pt,a4paper]{article}
\title{Test Document}
\begin{document}
\maketitle
\doublespacing
\section{Introduction}
Hello World!
\end{document}
And the R code by itself:
for (i in 1:10) {
print(i)
}
one <- 1 + 1
The Rnoweb document looks like this with no syntax highlighting at all:
It looks like this when you remove the vim.cmd("syntax off")
command from init.lua
and set highlight.enable
to true
:
The basic latex document looks like this:
And finally the R code by itself looks like this:
The syntax highlighting for both the R and Latex code is consistent across all 3 documents.
Here's a screenshot of an rnoweb file Here's one of an R only file
I am using the kickstart.nvim config and have only added rnoweb and r to the ensure_installed list as well as removed html: Ive also added cmp_nvim_r to the cmp config, although I don't see how that would affect treesitter, but I might be wrong on this. apart from that its the standard config. I will also note that I did get correct looking syntax highlighting for a brief moment and then it just went away. Not sure why or how. Ive also deleted the nvim cache and forced a complete reinstall of all plugins and treesitter parsers. I do get syntax highlighting on my rnoweb files if I install the latex treesitter parser, but it is obviously incorrect syntax highlighting:
I am on nvim version NVIM v0.9.5. I find this mostly weird because it works for all other files, yet I do not get any error, warning or issue during :checkhealth
Actually upon further testing it seems that in your example the R code is correctly syntax highlighted, but it is only the R code chunk. On its own the syntax highlighting of the code chunk remains the same.
It looks like you didn't install the latex parser. It's not in your list of "ensure_installed". Add latex
to that list and let me know if it works.
In the immediately above screenshot using my example code, the parser is working correctly. Can you open the basic latex document I gave, ensure it's filetype is latex
and confirm whether the syntax highlighting resembles my example screenshot above.
Sorry i cant access my computer right now — there is a screenshot where I do have the latex parser installed, it highlights latex syntax correctly, but still fails at parsing R chunks correctly, specifically it seems to completely ignore code chunks being code chunks and still treats them like latex, which leads to df$foo syntax starting a math block
The screenshot you posted has a list of ensure_installed
and latex
is not in the list. This means that you haven't installed the latex parser. If you open a latex file without the parser installed, it'll just revert back to standard Vim syntax highlighting, which does not use tree-sitter.
Here is a minimal reproduction of your config using lazy but with auto_install
set to false
:
require("lazy").setup({
-- Tree-Sitter
{ 'nvim-treesitter/nvim-treesitter',
config = function()
require'nvim-treesitter.configs'.setup {
ensure_installed = {"r", "rnoweb"},
auto_install = false,
sync_install = true,
highlight = { enable = true },
indent = { enable = true },
}
end
},
})
This is what the rnoweb document looks like without the latex parser:
It looks just like what you post. And here's what the stand alone latex document looks like:
and now after running :syntax off
Now the rnoweb
document after adding latex
to ensure_installed
:
And the stand alone latex document now that the latex parser is installed:
I'm pretty confident you didn't have the latex
parser installed.
For that screenshot I had installed the latex parser manually. If I add it to ensure installed it looks the same:
admittedly it seems to be half-correct: It just doesn't parse code blocks correctly
What does my minimal rnoweb example look like after the parser has been installed? Also what is the full code block where the parsing fails?
Bizarrely, it seems to work on the example you provided. Just doesn't work on my actual files. It works correctly in visual studio code and the files compile without a problem too.
But if it works now on my minimal example, and didn't before given the screenshot you gave, you didn't have the parser installed previously. Now the code block where it fails, how does it begin?
It also seems to not work on the file it worked without the latex parser before. (sorry this is a mistake, it didn't work there before either.) The full code block for the above screenshot is
<<resazurin, echo=FALSE, message=FALSE>>=
res_csv = read.csv("../2-Media/102-Resazurin/resazurinData.csv")
res_df = data.frame(
Group = c(
'Baseline',
'Control',
'Cells only',
'Sample 1',
'Sample 2',
'Sample 3',
'Sample 4'
),
Mean = apply(res_csv, 2, mean, na.rm = TRUE),
SD = apply(res_csv, 2, sd, na.rm = TRUE)
)
baseline = res_df[1,]
resazurin_adjusted = data.frame(
Group = c(
'Control',
'Cells only',
'Sample 1',
'Sample 2',
'Sample 3',
'Sample 4'
),
Mean = apply(res_csv[,-1] - baseline$Mean, 2, mean, na.rm = TRUE),
SD = apply(res_csv[,-1] - baseline$Mean, 2, sd, na.rm = TRUE),
Median = apply(res_csv[,-1] - baseline$Mean, 2, median, na.rm = TRUE)
)
resazurin_adjusted$AdjustedMean =
resazurin_adjusted$Mean /
resazurin_adjusted[1,]$Mean
resazurin_adjusted$AdjustedMedian =
resazurin_adjusted$Median /
resazurin_adjusted[1,]$Median
resazurin_adjusted$AdjustedLo =
(resazurin_adjusted$Mean - resazurin_adjusted$SD) /
(resazurin_adjusted[1,]$Mean + resazurin_adjusted[1,]$SD)
resazurin_adjusted$AdjustedHi =
(resazurin_adjusted$Mean + resazurin_adjusted$SD) /
(resazurin_adjusted[1,]$Mean - resazurin_adjusted[1,]$SD)
viridis_colors = pal_viridis()(length(resazurin_adjusted$Group))
resazurin_plot = ggplot(resazurin_adjusted, aes(x = Group, y = AdjustedMean, fill = Group)) +
geom_col() +
geom_errorbar(
aes(
ymin = AdjustedLo,
ymax = AdjustedHi
),
width = 0.3
) +
geom_point(
aes(
y = AdjustedMedian
),
size = 2.5
) +
scale_fill_manual(
guide = "none",
values = lighten(viridis_colors, 0.3)
) +
scale_y_continuous(
minor_breaks = c(resazurin_adjusted$AdjustedMean)
) +
xlab("Sample Group") +
ylab("Adjusted Resazurin fluorescence (%Control)") +
theme(text = element_text(size = 14.5))
ggsave("../2-Media/102-Resazurin/resazurinPlot.pdf", width = 10, height = 8)
@
But if it works now on my minimal example, and didn't before given the screenshot you gave, you didn't have the parser installed previously. Now the code block where it fails, how does it begin?
I would agree if it didn't stop working on the example file I had where it did work before. IF I had to guess this is some sort of priority issue but I am neither familiar with treesitter nor with how nvim plugins work.
In the above code, can you remove the leading white space before <<source, include=FALSE>>=
and @
that seems to make a difference (it doesn't, sorry) but still doesn't really produce correct highlights ... im so sorry this seems extremely painful of an issue
I'm getting the same issue with your code on my machine. Thanks for the report, I'll have to dig into this further.
Thanks! I hope it won't be too big of a problem to fix :)
Using the now merged code should fix this issue. The previous grammar didn't support the keys without values, <<source, include=FALSE>>=
. You can jump through some hoops to install this parser now, or you can wait for the bot at nvim-treesitter to merge the updated parser. I'm going to close this after nvim-treesitter updates and I've confirmed that version works as intended.
Im not sure it has been merged 'properly' into nvim treesitter yet (no idea how their update process works) but ive seen that there has been a commit to update the rnoweb lockfile so I think it has been updated... if that's the case im still not getting correct highlights. Updated nvim-treesitter and also reinstalled the r, rnoweb and latex parsers without any luck. Maybe it's not merged correctly yet though. If that's the case disregard this, obviously
After deleting my lazy.nvim cache, state and lockfile and forcing a full reinstall of every plugin this now works on my machine. I take that back. I think it was showing me the non treesitter highlighting. Stopped working the second time I opened the file
In my case, your example works perfectly. But it doesn't with the mandatory chunkname when you use multiple chunks.
Am I the only one who observes this kind of missing highlighting if there are chunknames in the chunk header.
Installing this via :TSInstall rnoweb does not provide me with syntax highlighting on rnw files. I also have it in ensure_installed and have called :TSUpdate all. Treesitter installs this just fine. Other files are highlighted correctly.