Skip to content

Instantly share code, notes, and snippets.

@borkdude
Created April 22, 2022 19:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkdude/4351b562a19ff6fed2eb803bdb5afade to your computer and use it in GitHub Desktop.
Save borkdude/4351b562a19ff6fed2eb803bdb5afade to your computer and use it in GitHub Desktop.
Nbb in VSCode extension
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const path = require('path');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
async function activate(context) {
const nbb = await import('nbb');
await import('nbb/lib/nbb_promesa.js');
globalThis.vscode = vscode;
const res = await nbb.loadFile(path.resolve(__dirname, 'script.cljs'));
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "borkdude" is now active!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('borkdude.helloWorld', res.command);
context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}
(ns script
(:require
[clojure.edn :as edn]
[goog.string :as gstring]
[promesa.core :as p]))
(def vscode js/vscode)
(defn command []
(vscode.window.showInformationMessage "Hello world from nbb!")
(p/let [input (vscode.window.showInputBox #js {:placeHolder "Add these numbers"
:prompt "Add these numbers"})
input (gstring/format "[%s]" input)
input (edn/read-string input)
sum (apply + input)]
(vscode.window.showInformationMessage (str "The sum: " sum))))
#js {:command command}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment