toscm / vstosc

VSCode commands from ToSc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

version installs build

vstosc

VSCode commands from ToSc and LiHu.

Installation

Open the Extensions Tab in VSCode's activity bar and search for vstosc. Then click install.

image

Usage

Hit F1 or Ctrl+Shift+P to open the Command Palette and then choose a command.

image image

For often used commands you might want to define a shortcut as shown below:

image image

Commands

runSelection

Executes the current selection in a shell (/bin/sh or cmd.exe) and replaces the selection with the command output.

image

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.

image

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.

image

testRFunction

Execute test cases for the R function where the cursor is currently positioned.

  1. 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.
  2. 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.
  3. 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

  1. Clone this repo and open the folder in VSCode
  2. Run npm install to install all dependencies
  3. Modify package.json and src/extensions.ts as required (ChatGPT is your friend).
  4. Hit F5 to and run the extension in a new Extension Development Host window.
  5. See Debugging the extension in case something isn't working as expected.
  6. Increase the version in package.json according to the rules of Semantic versioning
  7. 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:

  1. Run npm install -g @vscode/vsce to install the Visual Studio Code Extension Tool.
  2. Run vsce package to build the new package in VSCode package format .vsix
  3. Login to the VSCode Marketplace using a valid access token for the Azure DevOps Organization toscm using command vsce login toscm
  4. Publish the extension using command vsce publish

For further guidelines see VSCode Extension API and VSCode Publishing Extensions.

About

VSCode commands from ToSc

License:Other


Languages

Language:TypeScript 95.2%Language:R 4.8%