-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better code chunk extraction #356
Conversation
…arto documents This commit allow to retrieve all code chunks from rmd/qmd documents as well as their parameters (eval: true, for example). Utility functions to filter chunk by the code language (r, python at the moment) as well if the code chunk is marked as eval: true or eval = TRUE.
…ssage for accuracy
…Console Introduce `source_chunk` function to send a command to the R Console for sourcing the current chunk. This enhances the modularity and reusability of the code by separating the logic for sending chunks from other functionalities. Update `chunks_up_to_here` to utilize `source_chunk` for improved clarity and maintainability.
Simplify the process of sending code chunks by integrating R and Python handling into a single function. Remove redundant internal function and streamline chunk retrieval and filtering using the quarto module.
…nction to improve code readability and maintainability
…ction to clarify behavior based on language type
…perties and improve code organization
…s and improve code readability by using range method in chunk operations
…d improve debugging with print statements
…_params for clarity
a550666
to
5afcf17
Compare
I rebased the pull request on the main branch. |
No rush to merge if you want to test it. I have used this branch for the last 2–3 days without issue. Do not hesitate to co-author some code if you have suggestion/comment |
I can't review it carefully for the next days, and almost never someone comment on pull requests. So, we have to merge them to make people try the code. I think we can merge it now. |
Sounds good! |
Thanks! |
Below a detailed description of this PR using Copilot. Basically, it introduces a new class
Chunk
and various helper function to get and filter chunks in quarto and rmd documents. It also refactors the sending of current and all above chunks.The only user-visible change aligns with a discussion point: when sending all above chunks, the current chunk is now excluded. This approach ensures that partial code isn't mistakenly sent to the terminal, preventing execution errors—particularly when sending all above chunks alongside individual lines from the current chunk.
For example:
It will send the incomplete code.
This pull request introduces several significant changes to the handling of code chunks in R and Quarto documents, including the addition of a new
Chunk
class, refactoring of functions for sending code chunks, and enhancements to the way code chunks are parsed and executed.Improvements to code chunk handling:
lua/r/quarto.lua
: Introduced a newChunk
class to encapsulate code chunk properties and added several helper functions to parse and manage code chunks. These functions includeget_code_chunks
,parse_info_string_params
,parse_code_chunk_params
,get_current_code_chunk
,get_chunks_above_cursor
,get_all_code_chunks
,filter_code_chunks_by_lang
,filter_code_chunks_by_eval
, andcodelines_from_chunks
. [1] [2]Refactoring of functions for sending code chunks:
lua/r/maps.lua
: Updated the key mappings to use the newsend_current_chunk
function instead ofsend_R_chunk
.lua/r/rmd.lua
: Refactored thesend_R_chunk
andsend_py_chunk
functions into a singlesend_current_chunk
function that handles both R and Python code chunks.lua/r/send.lua
: Added a newsource_chunk
function to send code chunks to the R console and updated thechunks_up_to_here
function to use the new chunk handling methods. [1] [2]Dependency updates:
lua/r/rmd.lua
: Added a dependency on the newquarto
module.lua/r/send.lua
: Added a dependency on the newquarto
module.