7HR4IZ3 / acode_plugin_coderunner

Code runner plugin for acode
3 stars 2 forks source link

Code Runner

Acodex plugin Is required to use this extension

Acode plugin for running code directly from acode

Run Code

Exposed API

let runner = acode.require("code.runner");

// Function Handler
runner.addHandler({
  name: "python", extension: "py",
  match: "*.py", handler(file) {
    if (useIpython) {
      return `cd $dir && ipython ${file.name}`
    } else {
      return `cd $dir && python ${file.name}`
    }
  }
})

// String handler
runner.addHandler({
  name: "javascript",
  extension: "js",
  command: "node $path"
})

// Remove handlers.
runner.removeHandler("javascipt");

runner.addHandler({
  name: "NPM",
  match(file) {
    return file.name == "package.json";
  },
  handler(file) {
    return "npm run"
  }
})

Add Handler Parameter

runner.addHandler accepts an object with the following keys:

name: Name to be displayed if multiple handlers are found.

extension: File extension (optional).

match: Regex string or function (sync or async) to be matched with the file name or called with the file.

handler: Function (sync or async) called with editorManagee.activeFile, which should return the command (string).

command: String command used to run the file.

Command Placeholders

"$name" -> File name

"$nameNoExt" -> Name without extension

"$dir" -> File Absolute Directory

"$dirNoSlash" -> File Directory without ending slash

"$uri" -> File Uri

"$workspaceUrl" -> Folder amongst open folders which the file belongs to.

Updates

v1.0.2
  • Added keyboard shortcut ctrl+r
  • Alerts you if acodex is not installed.
  • Logs to "Acode SDK" logger if installed.
  • Supports up to 50 languages
v1.0.3, v1.0.4
  • Bug fixes
  • Ability to run package.json scripts
v1.0.5
  • Added option to edit and add commands from settings page
v1.0.6
  • Changed commands structure from [extension, command] to { name: string, extension: string or match: regex | string | function, handler: function or command: string }
  • Removed `addWildcard` and `removeWildcard` functions use `addHandler` with match function instead
  • Added ability to select between multiple handler natches.
  • Added setting to replace default run button
v1.0.7
  • Added ability to run projects (based on the content of the workspace directory). E.g: Opening a folder with the file 'package.json' allows you to run the 'NPM' project which gives you the optikn to select from the scripts defined in 'package.json'. Opening a project with 'manage.py' allows you to run the 'django' project.
  • Added option to select between built-in runner (acode) or using terminal.
  • Added option to disable Projects runner in settings.
v1.0.8, 1.0.9
  • Bug fixes