Closed idavydov closed 1 week ago
Here's a .qmd
file which reproducibly leads to the error for me. If I minimize it further the error either disappears or changes to a different one.
If I run styler::style_file("err1.qmd")
explicitly, the file is not changed:
Styling 1 files:
err1.qmd ✔
────────────────────────────────────────
Status Count Legend
✔ 1 File unchanged.
ℹ 0 File changed.
✖ 0 Styling threw an error.
────────────────────────────────────────
We always call style_text
while we should call style_text
to format a selection of lines and save the buffer and, then, call style_file
to format the whole file.
Could you, please, try https://github.com/R-nvim/R.nvim/pull/226 ?
this seem to fix it, thanks! the only thing, I get console output and no new prompt after that. I think either the output should be suppressed or new prompt should be outputted after styling.
> Styling 1 files:
.../err1.qmd ✔
────────────────────────────────────────
Status Count Legend
✔ 1 File unchanged.
ℹ 0 File changed.
✖ 0 Styling threw an error.
────────────────────────────────────────
Running style_file()
quietly now. Please, do this before trying the branch again because I didn't increase nvimcom
version number:
echo 'remove.packages("nvimcom")' | R
The functions of the formatR
package are not working well with R.nvim
. Since styler
has the same functionality, I would rather remove formatR
as an option than fix its integration with R.nvim
. Does anyone know of any advantages of formatR
over styler
?
thanks a lot, this fixed it for me.
I never used formatR, so cannot contribute to the styler
vs formatR
discussion.
I am using conform to format all my code.
conform.nvim
depends on the languageserver
which depends on styler
. So, perhaps we should simply remove the :RFormat
command from R.nvim
and add a page to the Wiki with tips on getting a complete IDE for R.
Does conform.nvim
work well with Quarto documents?
Does
conform.nvim
work well with Quarto documents?
Yes very good. Here is my config.
return { -- Autoformat
"stevearc/conform.nvim",
enabled = true,
config = function()
local conform = require("conform")
conform.setup({
notify_on_error = true,
format_on_save = {
timeout_ms = 2000,
lsp_fallback = true,
},
formatters_by_ft = {
css = { "prettier" },
scss = { "prettier" },
lua = { "mystylua" },
python = { "isort", "black" },
quarto = { "injected", "prettier" },
rmd = { "injected", "prettier" },
bash = { "shfmt" },
r = { "mystyler" },
latex = { "latexindent" },
sql = { "sqlformatter" },
markdown = { "prettier" },
toml = { "taplo" },
yaml = { "prettier" },
html = { "prettier" },
},
formatters = {
mystylua = {
command = "stylua",
args = {
"--indent-type",
"Spaces",
"--indent-width",
"4",
"-",
"--quote-style",
"AutoPreferDouble",
},
},
mystyler = {
command = "R",
args = { "-s", "-e", "styler::style_file(commandArgs(TRUE)[1])", "--args", "$FILENAME" },
stdin = false,
},
sqlformatter = {
command = "sql-formatter",
args = {
"-l=bigquery",
'--config={"tabWidth": 2, "keywordCase":"upper", "expressionWidth":80, "linesBetweenQueries":2}',
},
},
},
})
-- Customize the "injected" formatter
conform.formatters.injected = {
options = {
ignore_errors = false,
lang_to_ext = {
bash = "sh",
c_sharp = "cs",
elixir = "exs",
javascript = "js",
julia = "jl",
latex = "tex",
markdown = "md",
python = "py",
ruby = "rb",
rust = "rs",
teal = "tl",
r = "r",
typescript = "ts",
},
lang_to_formatters = {},
},
}
require("conform").formatters.prettier = {
options = {
ft_parsers = {
quarto = "markdown",
rmd = "markdown",
},
},
}
end,
}
thanks a lot, this fixed it for me.
Thanks for the feedback! The pull request was merged.
I'm having issues with formatting .Rmd/.qmd files. When I call
:RFormat
I get the following error:The last portion represents the contents of the
.Rmd
/.qmd
file.