Skip to content

Commit

Permalink
Add a function to print cell metadata
Browse files Browse the repository at this point in the history
* This is useful for troubleshooting issues with cell metadata not being set.
  • Loading branch information
jlewi committed Apr 17, 2024
1 parent a248cb0 commit fe679d9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/foyle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
{
"command": "foyle.helloWorld",
"title": "Foyle HelloWorld"
},
{
"command": "foyle.printCell",
"title": "Foyle Print Cell Metadata"
}
],
"keybindings": [
Expand Down
5 changes: 5 additions & 0 deletions frontend/foyle/src/web/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export class Controller {
}

async function callExecute(cell: vscode.NotebookCell, client: client.FoyleClient): Promise<vscode.NotebookCellOutput[]> {
if (cell.metadata.hasOwnProperty("id")) {
console.log(`callExecute called on block id = ${cell.metadata["id"]}`);
} else {
console.log(`callExecute called on block without id`);
}
console.log(`callExecute called ${cell.document.getText()}`);

const request = new agentpb.ExecuteRequest();
Expand Down
30 changes: 30 additions & 0 deletions frontend/foyle/src/web/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as vscode from 'vscode';
import {FoyleClient, getTraceID} from './client';
import * as converters from './converters';
import * as docpb from "../gen/foyle/v1alpha1/doc_pb";
import * as agentpb from "../gen/foyle/v1alpha1/agent_pb";
// printCell is a debug tool that prints the contents of a cell to the console
// Its purpose is to help us debug problems by printing the contents of a cell
// In particular the cell metadata
export async function printCell() {
const editor = vscode.window.activeNotebookEditor;

if (!editor) {
return;
}

if (editor?.selection.isEmpty) {
return;
}

// We subtract 1 because end is non-inclusive
const lastSelectedCell = editor?.selection.end - 1;
var lastActiveCell = editor?.notebook.cellAt(lastSelectedCell);
console.log(`Cell value: ${lastActiveCell.document.getText()}`);
console.log(`Cell language: ${lastActiveCell.document.languageId}`);
console.log(`Cell kind: ${lastActiveCell.kind}`);

Object.keys(lastActiveCell.metadata).forEach(key => {
console.log(`Cell Metadata key: ${key} value: ${lastActiveCell.metadata[key]}`);
});
}
3 changes: 3 additions & 0 deletions frontend/foyle/src/web/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Controller } from './controller';
import {FoyleClient} from './client';
import { Serializer } from './serializer';
import * as generate from './generate';
import * as debug from './debug';
// Create a client for the backend.
const client = new FoyleClient;

Expand Down Expand Up @@ -52,6 +53,8 @@ export function activate(context: vscode.ExtensionContext) {
// Here's where we register the command that will generate a completion using the AI model
// You can set a keybinding for this command in the package.json file
context.subscriptions.push(vscode.commands.registerCommand("foyle.generate", generate.generateCompletion));

context.subscriptions.push(vscode.commands.registerCommand("foyle.printCell", debug.printCell));
context.subscriptions.push(disposable);
}

Expand Down

0 comments on commit fe679d9

Please sign in to comment.