-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initialisation logging and test coverage (#42)
* add logging and test coverage * update after rebase * change compile source
- Loading branch information
1 parent
d6f11bb
commit 105c34e
Showing
14 changed files
with
263 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
*.vsix | ||
wasm | ||
.DS_Store | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { vi } from 'vitest' | ||
|
||
export const notebooks = { | ||
createNotebookController: vi.fn().mockReturnValue({ | ||
createNotebookCellExecution: vi.fn().mockReturnValue({ start: vi.fn(), end: vi.fn() }) | ||
}), | ||
registerNotebookCellStatusBarItemProvider: vi.fn(), | ||
createRendererMessaging: vi.fn().mockReturnValue({ | ||
postMessage: vi.fn(), | ||
onDidReceiveMessage: vi.fn().mockReturnValue({ dispose: vi.fn() }) | ||
}) | ||
} | ||
|
||
export const Uri = { | ||
joinPath: vi.fn().mockReturnValue('/foo/bar'), | ||
parse: vi.fn() | ||
} | ||
|
||
export const workspace = { | ||
openTextDocument: vi.fn(), | ||
registerNotebookSerializer: vi.fn(), | ||
fs: { | ||
readFile: vi.fn().mockResolvedValue(Buffer.from('some wasm file')) | ||
} | ||
} | ||
|
||
export const terminal = { | ||
show: vi.fn(), | ||
sendText: vi.fn() | ||
} | ||
|
||
export const window = { | ||
showWarningMessage: vi.fn(), | ||
showInformationMessage: vi.fn(), | ||
createTerminal: vi.fn().mockReturnValue(terminal) | ||
} | ||
|
||
export const commands = { | ||
registerCommand: vi.fn() | ||
} | ||
|
||
export const env = { | ||
clipboard: { | ||
writeText: vi.fn() | ||
}, | ||
openExternal: vi.fn() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import path from 'node:path' | ||
|
||
import { NotebookCell, Uri, window, env } from 'vscode' | ||
|
||
import { CliProvider } from '../provider/cli' | ||
import { getTerminalByCell } from '../utils' | ||
|
||
export function openTerminal (cell: NotebookCell) { | ||
const terminal = getTerminalByCell(cell) | ||
if (!terminal) { | ||
return window.showWarningMessage('Couldn\'t find terminal! Was it already closed?') | ||
} | ||
return terminal.show() | ||
} | ||
|
||
export function copyCellToClipboard (cell: NotebookCell) { | ||
env.clipboard.writeText(cell.document.getText()) | ||
return window.showInformationMessage('Copied cell to clipboard!') | ||
} | ||
|
||
export async function runCLICommand (cell: NotebookCell) { | ||
if (!await CliProvider.isCliInstalled()) { | ||
return window.showInformationMessage( | ||
'Runme CLI is not installed. Do you want to download it?', | ||
'Download now' | ||
).then((openBrowser) => openBrowser && env.openExternal( | ||
Uri.parse('https://github.com/stateful/runme/releases') | ||
)) | ||
} | ||
const cliName: string = (cell.metadata?.['cliName'] || '').trim() | ||
const term = window.createTerminal(`CLI: ${cliName}`) | ||
term.show(false) | ||
term.sendText(`runme run ${cliName} --chdir="${path.dirname(cell.document.uri.fsPath)}"`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,41 @@ | ||
import path from 'node:path' | ||
|
||
import vscode from 'vscode' | ||
import { workspace, notebooks, commands, ExtensionContext } from 'vscode' | ||
|
||
import { Serializer } from './notebook' | ||
import { Kernel } from './kernel' | ||
// import { ViteServerProcess } from './server' | ||
import { ShowTerminalProvider, BackgroundTaskProvider } from './provider/background' | ||
import { PidStatusProvider } from './provider/pid' | ||
import { CopyProvider } from './provider/copy' | ||
import { getTerminalByCell, resetEnv } from './utils' | ||
import { resetEnv } from './utils' | ||
import { CliProvider } from './provider/cli' | ||
|
||
// const viteProcess = new ViteServerProcess() | ||
|
||
export async function activate (context: vscode.ExtensionContext) { | ||
console.log('[Runme] Activating Extension') | ||
const kernel = new Kernel(context) | ||
|
||
// await viteProcess.start() | ||
context.subscriptions.push( | ||
kernel, | ||
// viteProcess, | ||
vscode.workspace.registerNotebookSerializer('runme', new Serializer(context), { | ||
transientOutputs: true, | ||
transientCellMetadata: { | ||
inputCollapsed: true, | ||
outputCollapsed: true, | ||
}, | ||
}), | ||
vscode.notebooks.registerNotebookCellStatusBarItemProvider('runme', new ShowTerminalProvider()), | ||
vscode.notebooks.registerNotebookCellStatusBarItemProvider('runme', new PidStatusProvider()), | ||
vscode.notebooks.registerNotebookCellStatusBarItemProvider('runme', new CliProvider()), | ||
vscode.notebooks.registerNotebookCellStatusBarItemProvider('runme', new BackgroundTaskProvider()), | ||
vscode.notebooks.registerNotebookCellStatusBarItemProvider('runme', new CopyProvider()), | ||
vscode.commands.registerCommand('runme.openTerminal', (cell: vscode.NotebookCell) => { | ||
const terminal = getTerminalByCell(cell) | ||
if (!terminal) { | ||
return vscode.window.showWarningMessage('Couldn\'t find terminal! Was it already closed?') | ||
} | ||
return terminal.show() | ||
}), | ||
vscode.commands.registerCommand('runme.copyCellToClipboard', (cell: vscode.NotebookCell) => { | ||
vscode.env.clipboard.writeText(cell.document.getText()) | ||
return vscode.window.showInformationMessage('Copied cell to clipboard!') | ||
}), | ||
|
||
vscode.commands.registerCommand('runme.runCliCommand', async (cell: vscode.NotebookCell) => { | ||
if (!await CliProvider.isCliInstalled()) { | ||
return vscode.window.showInformationMessage( | ||
'Runme CLI is not installed. Do you want to download it?', | ||
'Download now' | ||
).then((openBrowser) => openBrowser && vscode.env.openExternal( | ||
vscode.Uri.parse('https://github.com/stateful/runme/releases') | ||
)) | ||
} | ||
const cliName: string = (cell.metadata?.['cliName'] || '').trim() | ||
const term = vscode.window.createTerminal(`CLI: ${cliName}`) | ||
term.show(false) | ||
term.sendText(`runme run ${cliName} --chdir="${path.dirname(cell.document.uri.fsPath)}"`) | ||
}), | ||
|
||
vscode.commands.registerCommand('runme.resetEnv', resetEnv) | ||
) | ||
|
||
console.log('[Runme] Extension successfully activated') | ||
} | ||
|
||
// This method is called when your extension is deactivated | ||
export function deactivate () { | ||
// viteProcess.stop() | ||
import { openTerminal, runCLICommand, copyCellToClipboard } from './commands' | ||
|
||
export class RunmeExtension { | ||
async initialise (context: ExtensionContext) { | ||
const kernel = new Kernel(context) | ||
// const viteProcess = new ViteServerProcess() | ||
// await viteProcess.start() | ||
|
||
context.subscriptions.push( | ||
kernel, | ||
// viteProcess, | ||
workspace.registerNotebookSerializer('runme', new Serializer(context), { | ||
transientOutputs: true, | ||
transientCellMetadata: { | ||
inputCollapsed: true, | ||
outputCollapsed: true, | ||
}, | ||
}), | ||
notebooks.registerNotebookCellStatusBarItemProvider('runme', new ShowTerminalProvider()), | ||
notebooks.registerNotebookCellStatusBarItemProvider('runme', new PidStatusProvider()), | ||
notebooks.registerNotebookCellStatusBarItemProvider('runme', new CliProvider()), | ||
notebooks.registerNotebookCellStatusBarItemProvider('runme', new BackgroundTaskProvider()), | ||
notebooks.registerNotebookCellStatusBarItemProvider('runme', new CopyProvider()), | ||
commands.registerCommand('runme.resetEnv', resetEnv), | ||
commands.registerCommand('runme.openTerminal', openTerminal), | ||
commands.registerCommand('runme.runCliCommand', runCLICommand), | ||
commands.registerCommand('runme.copyCellToClipboard', copyCellToClipboard) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { ExtensionContext } from 'vscode' | ||
|
||
import { RunmeExtension } from './extension' | ||
|
||
const ext = new RunmeExtension() | ||
|
||
export async function activate (context: ExtensionContext) { | ||
console.log('[Runme] Activating Extension') | ||
try { | ||
await ext.initialise(context) | ||
console.log('[Runme] Extension successfully activated') | ||
} catch (err: any) { | ||
console.log(`[Runme] Failed to initialise the extension ${err.message}`) | ||
} | ||
} | ||
|
||
export function deactivate () { | ||
console.log('[Runme] Deactivating Extension') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.