vstosc
VSCode commands from ToSc and LiHu.
Installation
Open the Extensions Tab in VSCode's activity bar and search for vstosc
. Then click install
.
Usage
Hit F1
or Ctrl+Shift+P
to open the Command Palette and then choose a command.
For often used commands you might want to define a shortcut as shown below:
Commands
runSelection
Executes the current selection in a shell (/bin/sh
or cmd.exe
) and replaces the selection with the command output.
runCommand
Opens an input box asking the user for a command. The entered command will be run in a shell (/bin/sh
or cmd.exe
) and the output is inserted at the current cursor position. In case there is text selected while the command is executed, the selected text will be used as stdin for the command and replaced with the command's output.
updateRDocstring
Updates the roxygen2 docstring of the R function the cursor currently is in.
⚠️WARNING: This command requires the R package toscutil (version 2.7.1 or greater). For now you have to install it by hand using command: install.packages("toscutil")
from within a running R session.
🗒️NOTE: In case a function is defined multiple times in the same file. The generated roxygen2 docstring will always be based on the last definition of the function.
testRFunction
Execute test cases for the R function where the cursor is currently positioned.
- If the file path of the currently edited file matches glob pattern
{package_dir}/tests/testthat/test[-_]*.R
, command testthat::test_file("${currentFilePath}")
is sent to the currently active terminal.
- If the currently edited file matches glob pattern
{package_dir}/**/*.R
, the name of the currently edited function is determined and command testthat::test_file("{package_dir}/tests/testthat/test-{currentFunctionName}.R")
is sent instead.
- If the current editor matches neither of the above glob patterns or no terminal is active, nothing happens (except for a info message appearing that explains why nothing happens).
To speed up the develop-test-cycle even more, you might want to define a shortcut for this command. For instance, I have set up the following binding in my keybindings.json
file:
{
"key": "ctrl+shift+t",
"command": "vstosc.testRFunction",
"when": "editorTextFocus && editorLangId == 'r'"
}
knitRmd
Sends the following text to the currently active console:
rmarkdown::render("<path-of-currently-active-file")
mathMode
Inserts ~$$
at the current position and places the cursor in between $$
. A potential leading space is removed.
Contribute
- Clone this repo and open the folder in VSCode
- Run
npm install
to install all dependencies
- Modify package.json and src/extensions.ts as required (ChatGPT is your friend).
- Hit F5 to and run the extension in a new Extension Development Host window.
- See Debugging the extension in case something isn't working as expected.
- Increase the version in package.json according to the rules of Semantic versioning
- Push your changes and tag the commit (see section publish for details about the publishing process triggered by tagging a commit from the main branch)
Publish
Whenever a commit from the main branch receives a tag, the publish action is triggered, which uploads the extension vsce
to the VSCode Marketplace. In case the pipeline fails and you want to do the publishing manually, the following steps would be required:
- Run
npm install -g @vscode/vsce
to install the Visual Studio Code Extension Tool.
- Run
vsce package
to build the new package in VSCode package format .vsix
- Login to the VSCode Marketplace using a valid access token for the Azure DevOps Organization toscm using command
vsce login toscm
- Publish the extension using command
vsce publish
For further guidelines see VSCode Extension API and VSCode Publishing Extensions.