Skip to content

Commit a41a729

Browse files
Update notebook variable inheritance for variable changes
1 parent 48200e2 commit a41a729

4 files changed

Lines changed: 65 additions & 2 deletions

File tree

apps/client-e2e/src/tests/interactions/_interactions-runner.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { NotebookProblemsTrackRight } from './notebooks/notebook-problems-track-
3838
import { NotebookCompletionBasic } from './notebooks/notebooks-completion-basic';
3939
import { NotebooksInteractRight } from './notebooks/notebooks-interact-right';
4040
import { NotebooksNoDuplicateRoutines } from './notebooks/notebooks-no-duplicate-routines';
41+
import { NotebooksNoUndefinedVars } from './notebooks/notebooks-no-undefined-vars';
4142
import { BasicSymbolicLinks } from './symbolic-links/basic-symbolic-links';
4243
import { BasicSymbolicLinksWithProblems } from './symbolic-links/basic-symbolic-links-with-problems';
4344
import { InteractionSymbolicLinkProblemReporting } from './symbolic-links/interaction-symbolic-links-problem-reporting';
@@ -221,6 +222,11 @@ INTERACTIONS_RUNNER.addTest({
221222
fn: NotebookImpliedPrintProblemReporting,
222223
});
223224

225+
INTERACTIONS_RUNNER.addTest({
226+
name: 'Notebooks properly inherit variables',
227+
fn: NotebooksNoUndefinedVars,
228+
});
229+
224230
INTERACTIONS_RUNNER.addTest({
225231
name: 'Detect duplicate globals from two PRO files',
226232
fn: DuplicateGlobals,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { GetExtensionPath, Sleep } from '@idl/shared';
2+
import { OpenNotebookInVSCode } from '@idl/vscode/shared';
3+
import expect from 'expect';
4+
import * as vscode from 'vscode';
5+
6+
import { CLIENT_E2E_CONFIG } from '../../client-e2e-config.interface';
7+
import { RunnerFunction } from '../../runner.interface';
8+
9+
/**
10+
* Verifies our variables are defined
11+
*/
12+
export const NotebooksNoUndefinedVars: RunnerFunction = async (init) => {
13+
const doc = await OpenNotebookInVSCode(
14+
GetExtensionPath('idl/test/client-e2e/notebooks/no-undefined-vars.idlnb')
15+
);
16+
17+
// short pause
18+
await Sleep(CLIENT_E2E_CONFIG.DELAYS.PROBLEMS_NOTEBOOK);
19+
20+
// no problems in first cell
21+
expect(
22+
vscode.languages.getDiagnostics(doc.cellAt(0).document.uri).length
23+
).toEqual(0);
24+
25+
// no problems in second cell
26+
expect(
27+
vscode.languages.getDiagnostics(doc.cellAt(1).document.uri).length
28+
).toEqual(0);
29+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "2.0.0",
3+
"cells": [
4+
{
5+
"type": "code",
6+
"content": [
7+
"e = envi(/headless)"
8+
],
9+
"metadata": {},
10+
"outputs": []
11+
},
12+
{
13+
"type": "code",
14+
"content": [
15+
"print, e.task_names, /implied_print"
16+
],
17+
"metadata": {},
18+
"outputs": []
19+
}
20+
]
21+
}

libs/parsing/index/src/lib/helpers/populate-notebook-variables.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export function PopulateNotebookVariables(
8585
*/
8686
const otherVarName = otherVars[j];
8787

88-
// inherit variable
88+
/**
89+
* Inherit variable that we detect
90+
*/
8991
if (otherVarName in ourMain) {
9092
/**
9193
* Check if we need to set the variable (it hasnt been processed already)
@@ -109,13 +111,18 @@ export function PopulateNotebookVariables(
109111
weSet[otherVarName] = undefined;
110112
}
111113

112-
// if we arent defined, inherit
114+
// if we arent defined in our cell, inherit
113115
if (!ourMain[otherVarName].meta.isDefined) {
114116
ourMain[otherVarName].meta.isDefined =
115117
otherMain[otherVarName].meta.isDefined;
116118
ourMain[otherVarName].meta.type = otherMain[otherVarName].meta.type;
117119
ourMain[otherVarName].meta.isStaticClass =
118120
otherMain[otherVarName].meta.isStaticClass;
121+
122+
// if the other variable is defined, then set as we dont reset for post-processing
123+
if (otherMain[otherVarName].meta.isDefined) {
124+
ourMain[otherVarName].meta.canReset = false;
125+
}
119126
}
120127
} else {
121128
// copy

0 commit comments

Comments
 (0)