R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
149 stars 15 forks source link

Add pyodide and webr extensions to qmd #210

Open PMassicotte opened 1 month ago

PMassicotte commented 1 month ago

webr can be used in quarto documents.

We could add

  1. .webr (https://github.com/r-wasm/quarto-live/blob/d5e88730d9807b3f1453cdcdd0f65afb39ae5ffe/docs/interactive/hybrid.qmd#L103)

  2. pyodide (https://github.com/r-wasm/quarto-live/blob/d5e88730d9807b3f1453cdcdd0f65afb39ae5ffe/docs/interactive/hybrid.qmd#L113)

    As supported code chunks https://github.com/R-nvim/R.nvim/blob/7a42582b336f9b934c33b4878eb2ce3587035074/lua/r/utils.lua#L49

They behave exactly as normal r and python chunks.

jalvesaq commented 1 month ago

This is something that I will not use, but you can add support for them if you want.

An alternative would be to add a section to the Wiki teaching users how to add a custom query to their after/queries directory to make tree-sitter-markdown recognize the blocks as R code.

jalvesaq commented 1 month ago

Adding this to nvim-treesitter config fixes the highlighting and the ability to send code to the R Console:

    {
        "nvim-treesitter/nvim-treesitter",
        config = function ()
            vim.treesitter.language.register("r", "webr")
            vim.treesitter.language.register("python", "pyodide")
        end,
    }

But we still can't use <LocalLeader>gn to jump to webr and pyodide chunks. If this is the only missing thing in the support, we can create a config option such as:

   r_chunk_lang = { "r", "python" }

that users could define as:

   r_chunk_lang = { "r", "python", "webr", "pyodide" }

Or, even better, use tree-sitter to find R and Python code chunks. In this case, users would not have to configure anything in R.nvim and it would work with whatever new types of chunks defined as either R or Python.

PMassicotte commented 1 month ago

Nice finding!

For this, how would you do it?

Or, even better, use tree-sitter to find R and Python code chunks. In this case, users would not have to configure anything in R.nvim and it would work with whatever new types of chunks defined as either R or Python.

jalvesaq commented 1 month ago

For this, how would you do it?

I don't know... But perhaps something similar to what you have done to send functions would be possible in this case.