Skip to content

Commit

Permalink
Improvements to .R file chunks: (#1455)
Browse files Browse the repository at this point in the history
- Add option Run Chunk and Move to Next Chunk
- Highlight code chunks differently for base `.R` file.
Highlighting the background just highlights the
whole entire screen.
Instead match `.py` and use border for current cell
  • Loading branch information
kylebutts authored Nov 27, 2023
1 parent c05d696 commit 54f924c
Show file tree
Hide file tree
Showing 4 changed files with 625 additions and 461 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"onCommand:r.runSelectionInActiveTerm",
"onCommand:r.selectCurrentChunk",
"onCommand:r.runCurrentChunk",
"onCommand:r.runCurrentChunkAndMove",
"onCommand:r.runPreviousChunk",
"onCommand:r.runNextChunk",
"onCommand:r.runAboveChunks",
Expand Down Expand Up @@ -566,6 +567,11 @@
"category": "R",
"command": "r.runCurrentChunk"
},
{
"title": "Run Current Chunk and Move to Next Chunk",
"category": "R",
"command": "r.runCurrentChunkAndMove"
},
{
"title": "Run Previous Chunk",
"category": "R",
Expand Down Expand Up @@ -938,13 +944,13 @@
"command": "r.runCurrentChunk",
"key": "Ctrl+shift+enter",
"mac": "cmd+shift+enter",
"when": "editorTextFocus && editorLangId == 'rmd'"
"when": "editorTextFocus && (editorLangId == 'rmd' || editorLangId == 'r')"
},
{
"command": "r.runAboveChunks",
"key": "Ctrl+alt+p",
"mac": "cmd+alt+p",
"when": "editorTextFocus && editorLangId == 'rmd'"
"when": "editorTextFocus && (editorLangId == 'rmd' || editorLangId == 'r')"
},
{
"command": "r.runSource",
Expand Down Expand Up @@ -1523,6 +1529,7 @@
"enum": [
"r.selectCurrentChunk",
"r.runCurrentChunk",
"r.runCurrentChunkAndMove",
"r.runAboveChunks",
"r.runCurrentAndBelowChunks",
"r.runBelowChunks",
Expand Down
17 changes: 10 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
'r.runCommand': rTerminal.runCommand,
'r.runSourcewithEcho': () => { void rTerminal.runSource(true); },

// rmd related
'r.knitRmd': () => { void rmdKnitManager?.knitRmd(false, undefined); },
'r.knitRmdToPdf': () => { void rmdKnitManager?.knitRmd(false, 'pdf_document'); },
'r.knitRmdToHtml': () => { void rmdKnitManager?.knitRmd(false, 'html_document'); },
'r.knitRmdToAll': () => { void rmdKnitManager?.knitRmd(false, 'all'); },
// chunk related
'r.selectCurrentChunk': rmarkdown.selectCurrentChunk,
'r.runCurrentChunk': rmarkdown.runCurrentChunk,
'r.runCurrentChunkAndMove': rmarkdown.runCurrentChunkAndMove,
'r.runPreviousChunk': rmarkdown.runPreviousChunk,
'r.runNextChunk': rmarkdown.runNextChunk,
'r.runAboveChunks': rmarkdown.runAboveChunks,
Expand All @@ -98,6 +95,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
'r.goToNextChunk': rmarkdown.goToNextChunk,
'r.runChunks': rTerminal.runChunksInTerm,

// rmd related
'r.knitRmd': () => { void rmdKnitManager?.knitRmd(false, undefined); },
'r.knitRmdToPdf': () => { void rmdKnitManager?.knitRmd(false, 'pdf_document'); },
'r.knitRmdToHtml': () => { void rmdKnitManager?.knitRmd(false, 'html_document'); },
'r.knitRmdToAll': () => { void rmdKnitManager?.knitRmd(false, 'all'); },

'r.rmarkdown.newDraft': () => rmarkdown.newDraft(),
'r.rmarkdown.setKnitDirectory': () => rmdKnitManager?.setKnitDir(),
'r.rmarkdown.showPreviewToSide': () => rmdPreviewManager?.previewRmd(vscode.ViewColumn.Beside),
Expand Down Expand Up @@ -202,10 +205,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
// initialize the package/help related functions
globalRHelp = await rHelp.initializeHelp(context, rExtension);

// register codelens and complmetion providers for r markdown
// register codelens and completion providers for r markdown and r files
vscode.languages.registerCodeLensProvider(['r', 'rmd'], new rmarkdown.RMarkdownCodeLensProvider());
vscode.languages.registerCompletionItemProvider('rmd', new rmarkdown.RMarkdownCompletionItemProvider(), ' ', ',');

vscode.languages.registerFoldingRangeProvider('r', new rmarkdown.RChunkFoldingProvider());

// register (session) hover and completion providers
vscode.languages.registerHoverProvider(['r', 'rmd'], new completions.HoverProvider());
Expand Down
Loading

0 comments on commit 54f924c

Please sign in to comment.