Skip to content

Commit

Permalink
[mod] 0.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
apb2006 committed May 3, 2023
1 parent f86ce7a commit 25e8bbd
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vscode/**
.vscode-test/**
out/test/**
docs/**
src/**
.gitignore
.yarnrc
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

An experimental XQuery [notebook for VSCode](https://code.visualstudio.com/blogs/2021/11/08/custom-notebooks).

![image](docs/notepad.png)
## Requirements

Currently hardcoded for:
Expand Down
Binary file added docs/notepad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xquery-notebook",
"displayName": "XQuery notebook",
"version": "0.0.14",
"version": "0.0.15",
"description": "Notebook supporting XQuery cells. The XQuery cells are evaluated using a BaseX server. ",
"preview": true,
"publisher": "quodatum",
Expand Down
2 changes: 1 addition & 1 deletion src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class XQueryKernel {
])]);

execution.end(true, Date.now());
} catch (err) {
} catch (err:any) {
execution.replaceOutput([new vscode.NotebookCellOutput([
vscode.NotebookCellOutputItem.json(err)
])]);
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const NOTEBOOK_TYPE = 'quodatum-notebook-serializer';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('quodatum-notebook-serializer.createXQNotebook', async () => {
const language = 'xquery';
const defaultValue = ` fn:current-current-dateTime() `;
const defaultValue = ` fn:current-dateTime() `;
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, defaultValue, language);
const data = new vscode.NotebookData([cell]);
data.metadata = {
Expand Down
18 changes: 10 additions & 8 deletions src/languages/javascript-cell.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {CellProvider} from './cellprovider';
import { CellProvider } from './cellprovider';

export class JavascriptCell implements CellProvider {

async eval(code: string): Promise<any> {
try {
return eval?.(`"use strict";(${code})`);
} catch (err :any) {
return err;
}
}
return new Promise((resolve, reject) => {
try {
resolve(eval?.(`"use strict";(${code})`));
} catch (err :any) {
reject({'message': err.message});
}
});
}
}
8 changes: 5 additions & 3 deletions src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface RawNotebookCell {
value: string;
kind: vscode.NotebookCellKind;
editable?: boolean;
outputs?:string[];
}

export class SampleContentSerializer implements vscode.NotebookSerializer {
Expand Down Expand Up @@ -46,11 +47,12 @@ export class SampleContentSerializer implements vscode.NotebookSerializer {
const contents: RawNotebookData = { cells: [] };

for (const cell of data.cells) {
contents.cells.push({
const item:RawNotebookCell={
kind: cell.kind,
language: cell.languageId,
value: cell.value
});
value: cell.value};
if(cell.outputs?.length) console.log("AA");
contents.cells.push(item);
}

return new TextEncoder().encode(JSON.stringify(contents));
Expand Down
2 changes: 1 addition & 1 deletion test.xq-notebook
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells":[{"kind":2,"language":"xquery","value":" db:list()"},{"kind":2,"language":"javascript","value":"Date.xnow()"},{"kind":2,"language":"xquery","value":"current-dateTime()"},{"kind":2,"language":"xquery","value":"currfent-date()"},{"kind":1,"language":"markdown","value":"# Folders with `yyyy-mm-dd` format in year"},{"kind":2,"language":"xquery","value":"67\r\n"},{"kind":2,"language":"xquery","value":"declare variable $year:=\"2023\";\r\ndeclare variable $base:=\"P:\\pictures\\Pictures\\2023\\\";\r\ndeclare variable $folders:=file:list($base)[matches(.,\"\\d{4}-\\d{2}-\\d{2}\\\\\")]! substring(.,1,10);\r\n$folders"}]}
{"cells":[{"kind":1,"language":"markdown","value":"Examples for use"},{"kind":2,"language":"xquery","value":" db:list()"},{"kind":2,"language":"javascript","value":"Date.xnow()"},{"kind":2,"language":"xquery","value":"current-dateTime()"},{"kind":2,"language":"xquery","value":"currfent-date()"},{"kind":1,"language":"markdown","value":"## List subfolders of year with format `yyyy-mm-dd`"},{"kind":2,"language":"xquery","value":"declare variable $year:=\"2023\";\r\ndeclare variable $base:=\"P:\\pictures\\Pictures\\2023\\\";\r\ndeclare variable $folders:=file:list($base)[matches(.,\"\\d{4}-\\d{2}-\\d{2}\\\\\")]! substring(.,1,10);\r\n$folders"}]}

0 comments on commit 25e8bbd

Please sign in to comment.