Skip to content

Commit e4431ad

Browse files
committed
notebooks
notebooks notebooks notebooks notebooks notebook notebooks fix for ipynb notebooks notebooks notebooks
1 parent 25fb0bf commit e4431ad

14 files changed

+225
-26
lines changed

samples/notebooks/polyglot/Azure logs.ipynb

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,75 @@
171171
],
172172
"metadata": {
173173
"kernelspec": {
174-
"display_name": ".NET (PowerShell)",
175-
"language": "PowerShell",
176-
"name": ".net-powershell"
174+
"display_name": ".NET (C#)",
175+
"language": "C#",
176+
"name": ".net-csharp"
177177
},
178178
"language_info": {
179179
"file_extension": ".ps1",
180180
"mimetype": "text/x-powershell",
181181
"name": "PowerShell",
182182
"pygments_lexer": "powershell",
183183
"version": "7.0"
184+
},
185+
"polyglot_notebook": {
186+
"kernelInfo": {
187+
"defaultKernelName": "powershell",
188+
"items": [
189+
{
190+
"aliases": [],
191+
"name": "powershell"
192+
},
193+
{
194+
"aliases": [
195+
"frontend"
196+
],
197+
"languageName": null,
198+
"name": "vscode"
199+
},
200+
{
201+
"aliases": [],
202+
"languageName": "Mermaid",
203+
"name": "mermaid"
204+
},
205+
{
206+
"aliases": [
207+
"js"
208+
],
209+
"languageName": "JavaScript",
210+
"name": "javascript"
211+
},
212+
{
213+
"aliases": [],
214+
"name": "webview"
215+
},
216+
{
217+
"aliases": [],
218+
"languageName": null,
219+
"name": "value"
220+
},
221+
{
222+
"aliases": [],
223+
"languageName": "HTML",
224+
"name": "html"
225+
},
226+
{
227+
"aliases": [
228+
"powershell"
229+
],
230+
"languageName": "PowerShell",
231+
"name": "pwsh"
232+
},
233+
{
234+
"aliases": [
235+
"f#",
236+
"F#"
237+
],
238+
"languageName": "F#",
239+
"name": "fsharp"
240+
}
241+
]
242+
}
184243
}
185244
},
186245
"nbformat": 4,

samples/notebooks/polyglot/COVID-19-fsharp.dib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!meta
22

3-
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"csharp","aliases":["c#","C#"],"languageName":"C#"},{"name":".NET","aliases":[]},{"name":"fsharp","aliases":["f#","F#"],"languageName":"F#"},{"name":"html","aliases":[],"languageName":"HTML"},{"name":"kql","aliases":[],"languageName":"KQL"},{"name":"mermaid","aliases":[],"languageName":"Mermaid"},{"name":"pwsh","aliases":["powershell"],"languageName":"PowerShell"},{"name":"sql","aliases":[],"languageName":"SQL"},{"name":"value","aliases":[]},{"name":"vscode","languageName":null,"aliases":["frontend"]}]}}
3+
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"csharp","aliases":["c#","C#"],"languageName":"C#"},{"name":".NET","aliases":[]},{"name":"fsharp","aliases":["f#","F#"],"languageName":"F#"},{"name":"html","aliases":[],"languageName":"HTML"},{"name":"kql","aliases":[],"languageName":"KQL"},{"name":"mermaid","aliases":[],"languageName":"Mermaid"},{"name":"pwsh","aliases":["powershell"],"languageName":"PowerShell"},{"name":"sql","aliases":[],"languageName":"SQL"},{"name":"value","aliases":[]},{"name":"vscode","aliases":["frontend"]}]}}
44

55
#!markdown
66

samples/notebooks/polyglot/COVID-19.ipynb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@
394394
},
395395
{
396396
"aliases": [],
397+
"languageName": null,
397398
"name": ".NET"
398399
},
399400
{
@@ -433,13 +434,26 @@
433434
},
434435
{
435436
"aliases": [],
437+
"languageName": null,
436438
"name": "value"
437439
},
438440
{
439441
"aliases": [
440442
"frontend"
441443
],
444+
"languageName": null,
442445
"name": "vscode"
446+
},
447+
{
448+
"aliases": [
449+
"js"
450+
],
451+
"languageName": "JavaScript",
452+
"name": "javascript"
453+
},
454+
{
455+
"aliases": [],
456+
"name": "webview"
443457
}
444458
]
445459
}

samples/notebooks/polyglot/Variable sharing.ipynb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,54 @@
441441
"name": "C#",
442442
"pygments_lexer": "csharp",
443443
"version": "8.0"
444+
},
445+
"polyglot_notebook": {
446+
"kernelInfo": {
447+
"defaultKernelName": "csharp",
448+
"items": [
449+
{
450+
"aliases": [
451+
"c#",
452+
"C#"
453+
],
454+
"languageName": "C#",
455+
"name": "csharp"
456+
},
457+
{
458+
"aliases": [
459+
"js"
460+
],
461+
"languageName": "JavaScript",
462+
"name": "javascript"
463+
},
464+
{
465+
"aliases": [],
466+
"name": "webview"
467+
},
468+
{
469+
"aliases": [],
470+
"languageName": null,
471+
"name": ".NET"
472+
},
473+
{
474+
"aliases": [
475+
"frontend"
476+
],
477+
"languageName": null,
478+
"name": "vscode"
479+
},
480+
{
481+
"aliases": [],
482+
"languageName": "Mermaid",
483+
"name": "mermaid"
484+
},
485+
{
486+
"aliases": [],
487+
"languageName": null,
488+
"name": "value"
489+
}
490+
]
491+
}
444492
}
445493
},
446494
"nbformat": 4,

samples/notebooks/polyglot/d3js.ipynb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@
267267
"frontend"
268268
],
269269
"name": "vscode"
270+
},
271+
{
272+
"aliases": [
273+
"js"
274+
],
275+
"languageName": "JavaScript",
276+
"name": "javascript"
277+
},
278+
{
279+
"aliases": [],
280+
"name": "webview"
270281
}
271282
]
272283
}

samples/notebooks/polyglot/github repo milestone report.ipynb

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,45 @@
663663
"defaultKernelName": "csharp",
664664
"items": [
665665
{
666-
"aliases": [],
666+
"aliases": [
667+
"c#",
668+
"C#"
669+
],
670+
"languageName": "C#",
667671
"name": "csharp"
672+
},
673+
{
674+
"aliases": [
675+
"js"
676+
],
677+
"languageName": "JavaScript",
678+
"name": "javascript"
679+
},
680+
{
681+
"aliases": [],
682+
"name": "webview"
683+
},
684+
{
685+
"aliases": [],
686+
"languageName": null,
687+
"name": ".NET"
688+
},
689+
{
690+
"aliases": [
691+
"frontend"
692+
],
693+
"languageName": null,
694+
"name": "vscode"
695+
},
696+
{
697+
"aliases": [],
698+
"languageName": "Mermaid",
699+
"name": "mermaid"
700+
},
701+
{
702+
"aliases": [],
703+
"languageName": null,
704+
"name": "value"
668705
}
669706
]
670707
}

samples/notebooks/polyglot/polyglot telemetry.dib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!meta
22

3-
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"csharp","aliases":[]}]}}
3+
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"name":"csharp","languageName":"C#","aliases":["c#","C#"]},{"name":".NET","aliases":[]},{"name":"fsharp","languageName":"F#","aliases":["f#","F#"]},{"name":"html","languageName":"HTML","aliases":[]},{"name":"kql","languageName":"KQL","aliases":[]},{"name":"mermaid","languageName":"Mermaid","aliases":[]},{"name":"pwsh","languageName":"PowerShell","aliases":["powershell"]},{"name":"sql","languageName":"SQL","aliases":[]},{"name":"value","aliases":[]},{"name":"vscode","aliases":["frontend"]}]}}
44

55
#!csharp
66

src/polyglot-notebooks-vscode-common/src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export function registerFileCommands(context: vscode.ExtensionContext, parserSer
327327
};
328328

329329
const createForIpynb = viewType === constants.JupyterViewType;
330-
const rawNotebookMetadata = metadataUtilities.getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(notebookDocumentMetadata, createForIpynb);
330+
const rawNotebookMetadata = metadataUtilities.getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(notebookDocumentMetadata, {}, createForIpynb);
331331
const content = new vscode.NotebookData([cell]);
332332
content.metadata = rawNotebookMetadata;
333333
const notebook = await vscode.workspace.openNotebookDocument(viewType, content);

src/polyglot-notebooks-vscode-common/src/documentSemanticTokenProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTo
8484
if (notebook) {
8585
const isIpynb = metadataUtilities.isIpynbNotebook(notebook);
8686
const bareMetadata = metadataUtilities.createDefaultNotebookDocumentMetadata();
87-
const rawBareMetadata = metadataUtilities.getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(bareMetadata, isIpynb);
87+
const rawBareMetadata = metadataUtilities.getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(bareMetadata, notebook.metadata, isIpynb);
8888
const _succeeded = await vscodeNotebookManagement.replaceNotebookMetadata(notebook.uri, rawBareMetadata);
8989
const kernelInfos = metadataUtilities.getKernelInfosFromNotebookDocument(notebook);
9090
this.dynamicTokenProvider.rebuildNotebookGrammar(notebook.uri, kernelInfos, true);

src/polyglot-notebooks-vscode-common/src/metadataUtilities.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export function getRawInteractiveDocumentMetadataFromNotebookDocumentMetadata(no
286286
return notebookDocumentMetadata;
287287
}
288288

289-
export function getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(notebookDocumentMetadata: NotebookDocumentMetadata, createForIpynb: boolean): { [key: string]: any } {
289+
export function getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(notebookDocumentMetadata: NotebookDocumentMetadata, documentRawMetadata: { [key: string]: any }, createForIpynb: boolean): { [key: string]: any } {
290290
const rawMetadata: { [key: string]: any } = {};
291291

292292
if (createForIpynb) {
@@ -301,9 +301,27 @@ export function getRawNotebookDocumentMetadataFromNotebookDocumentMetadata(noteb
301301
rawMetadata.polyglot_notebook = notebookDocumentMetadata;
302302
}
303303

304+
merge(rawMetadata, documentRawMetadata);
304305
return rawMetadata;
305306
}
306307

308+
function merge(destination: { [key: string]: any }, source: { [key: string]: any }) {
309+
const sourceKeys = Object.keys(source);
310+
for (const key of sourceKeys) {
311+
if (destination[key] === undefined) {
312+
destination[key] = source[key];
313+
} else {
314+
if (source[key] !== undefined && source[key] !== null) {
315+
if (typeof destination[key] === 'object') {
316+
merge(destination[key], source[key]);
317+
}
318+
} else {
319+
let a = 123;
320+
}
321+
}
322+
}
323+
}
324+
307325
export function mergeNotebookCellMetadata(baseMetadata: NotebookCellMetadata, metadataWithNewValues: NotebookCellMetadata): NotebookCellMetadata {
308326
const resultMetadata = { ...baseMetadata };
309327
if (metadataWithNewValues.kernelName) {
@@ -354,10 +372,10 @@ function createDefaultNotebookCellMetadata(): NotebookCellMetadata {
354372
return {};
355373
}
356374

357-
export function areEquivalentObjects(object1: { [key: string]: any }, object2: { [key: string]: any }) {
375+
export function areEquivalentObjects(object1: { [key: string]: any }, object2: { [key: string]: any }): boolean {
358376
const isObject = (object: any) => {
359377
return object !== null && typeof object === 'object';
360-
}
378+
};
361379

362380
const object1Keys = Object.keys(object1);
363381
const object2Keys = Object.keys(object2);
@@ -367,28 +385,32 @@ export function areEquivalentObjects(object1: { [key: string]: any }, object2: {
367385
}
368386

369387
for (const key of object1Keys) {
388+
key;//?
370389
const value1 = object1[key];//?
371390
const value2 = object2[key];//?
372391
const bothAreObjects = isObject(value1) && isObject(value2); //?
373-
if ((bothAreObjects && !areEquivalentObjects(value1, value2))) {
374-
return false;
375-
}
392+
const bothAreArrays = Array.isArray(value1) && Array.isArray(value2);
376393

377-
if (Array.isArray(value1) && Array.isArray(value2)) {
378-
if (value1.length !== value2.length) {
394+
if (bothAreArrays) {
395+
if (value1.length !== value2.length) {//?
379396
return false;
380397
}
381-
382398
for (let index = 0; index < value1.length; index++) {
383399
const element1 = value1[index];//?
384400
const element2 = value2[index];//?
385401
if (!areEquivalentObjects(element1, element2)) {
386402
return false;
387403
}
388404
}
389-
390-
}
391-
else if (value1 !== value2) {
405+
} else if (bothAreObjects) {
406+
const equivalent = areEquivalentObjects(value1, value2);
407+
if (!equivalent) {
408+
return false;
409+
}
410+
} else if (value1 !== value2) //?
411+
{
412+
value1;//?
413+
value2;//?
392414
return false;
393415
}
394416
}

0 commit comments

Comments
 (0)