Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added packages/vscode-typescript-repl/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/vscode-typescript-repl/icon_square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions packages/vscode-typescript-repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "vscode-typescript-repl",
"displayName": "TypeScript REPL",
"description": "Run TypeScript instantly.",
"version": "0.0.4",
"version": "0.0.6",
"icon": "icon_square.png",
"engines": {
"vscode": "^1.81.0"
},
Expand Down Expand Up @@ -53,11 +54,7 @@
"package:test": "npm version prerelease --no-workspaces-update --preid alpha && yarn package"
},
"dependencies": {
"@effect/data": "^0.18.3",
"@effect/io": "^0.39.0",
"@effect/schema": "^0.34.0",
"@swc/core": "^1.3.83",
"@types/ramda": "^0.29.3",
"pirates": "^4.0.6",
"ramda": "^0.29.0",
"swc-ts-repl-transpile": "workspace:^",
Expand All @@ -67,6 +64,7 @@
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@types/ramda": "^0.29.9",
"@types/vscode": "^1.81.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
Expand All @@ -81,8 +79,12 @@
"bugs": {
"url": "https://github.com/alex-dixon/vscode-typescript-repl/issues"
},
"homepage": "https://github.com/alex-dixon/vscode-typescript-repl#readme",
"keywords": [],
"author": "",
"license": "ISC"
"homepage": "https://github.com/alex-dixon/vscode-typescript-repl",
"keywords": [
"vscode",
"typescript",
"repl"
],
"author": "Alex Dixon <email@alexdixon.io>",
"license": "MIT"
}
49 changes: 34 additions & 15 deletions packages/vscode-typescript-repl/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {logger} from "./logger";
import {createREPL, evaluate, repls} from "./repl";
import * as path from 'node:path'
import * as vscode from 'vscode';
import { EventEmitter } from 'node:stream';

let myREPL = createREPL({name: 'test-repl-id'})
let chan = vscode.window.createOutputChannel("typescript-repl")
Expand Down Expand Up @@ -74,25 +75,43 @@ export function activate(context: vscode.ExtensionContext) {

})
}

chan.appendLine(text + " =>")

const result = await evaluate({
code: text,
filename: currentlyOpenTabFilePath,
replId: myREPL.id,
__dirname: currentlyOpenTabDirname
}, undefined)

if (result.type === 'error') {
vscode.window.showInformationMessage(result.text);
chan.appendLine(result.text)
} else if (result.type === 'print') {
chan.appendLine(result.result)
// TODO. This is annoying because it forces the user to look at the panel...It looks like it doesn't show up otherwise though
chan.show(true)
// vscode.window.showInformationMessage(result.result);
} else {
console.error(result)
throw new Error("Unhandled result")
}
__dirname: currentlyOpenTabDirname,
}, {
send: (topic:string, message:any)=> {
logger.debug("Recieved", topic, message)
if (topic==='repl:output') {
if (message.type==='error') {
chan.appendLine(message.text)
}
if (message.type==='print') {
// if (message.input) {
// chan.appendLine(message.input.code + " =>")
// }
chan.appendLine(message.result)
chan.show(true)
}
}
}})

// if (result.type === 'error') {
// vscode.window.showInformationMessage(result.text);
// chan.appendLine(result.text)
// } else if (result.type === 'print') {
// chan.appendLine(result.result)
// // TODO. This is annoying because it forces the user to look at the panel...It looks like it doesn't show up otherwise though
// chan.show(true)
// // vscode.window.showInformationMessage(result.result);
// } else {
// console.error(result)
// throw new Error("Unhandled result")
// }
} catch (e) {
console.error(e)
vscode.window.showInformationMessage(e.toString());
Expand Down
22 changes: 19 additions & 3 deletions packages/vscode-typescript-repl/src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ const print = (x: unknown) =>

const api = {
emit: (socket: any, topic: any, payload: any) => {
console.log("emit", {socket, topic, payload})
socket?.send(topic,payload)
// console.log("emit", {socket, topic, payload})
},
broadcast: (topic: string, payload: any) => {
console.log("broadcast", topic, payload)
Expand Down Expand Up @@ -346,7 +347,7 @@ export const evaluate = async (args: EvaluateInput, socket: unknown): Promise<Er
// todo. append to an array in order to return stuff maybe, or a cb/stream
api.emit(socket, "repl:output", {
type: "print",
result: args.map((x) => print(x)).join(" "),
result: args.map((x) => typeof x === "string" ? x : print(x)).join(" "),
filename: filenameOrNamespace,
// todo. view should just print this absent input info
input: {},
Expand Down Expand Up @@ -406,7 +407,22 @@ export const evaluate = async (args: EvaluateInput, socket: unknown): Promise<Er
jsCode = tsToJS(args.code)
} catch (e) {
console.error("tsToJS error", e)
return e
const error = {
type: "error" as const,
text: (e as Error).toString(),
filename: filenameOrNamespace,
input: {
type: "expr",
code: args.code,
filename: filenameOrNamespace,
},
// todo. ?
// message: e.message,
// stack: e.stack,
}

// @ts-expect-error ridiculous
return error
}

let ret
Expand Down