Skip to content

Commit

Permalink
Disambiguate input paths to nodes by preserving source.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 14, 2023
1 parent 1b6e01c commit a82ad86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,10 @@ export default class Project {
}

/** Given a path, try to resolve a corresponding node in one of the sources. */
resolvePath(path: Path) {
// Resolve the node from the path.
let evaluate: Node | undefined = undefined;
for (const root of this.roots) {
evaluate = root.resolvePath(path);
if (evaluate !== undefined) break;
}
return evaluate;
resolvePath(sourceNumber: number, path: Path) {
const source = this.getSources()[sourceNumber];
if (source === undefined) return undefined;
else return source.root.resolvePath(path);
}

/** True if one of the project's contains the given node. */
Expand Down
15 changes: 14 additions & 1 deletion src/runtime/Evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ export default class Evaluator {
* can have multiple streams associated with it.
*/
#inputs: (null | {
/** The index of the source from which the stream originated */
source: number;
/** The path to the node in the source */
path: Path;
/** The count of the stream created */
number: number;
/** Exactly when the input occurred */
stepIndex: number;
/** The raw data of the event */
raw: unknown;
silent: boolean;
})[] = [];
Expand Down Expand Up @@ -308,7 +314,10 @@ export default class Evaluator {
// See if we can find the corresponding stream.
else {
// Resolve the node from the path.
const evaluate = this.project.resolvePath(input.path);
const evaluate = this.project.resolvePath(
input.source,
input.path
);

// Couldn't find the node, or it's not an evaluate? Stop here.
if (evaluate === undefined) {
Expand Down Expand Up @@ -1230,7 +1239,11 @@ export default class Evaluator {
"Warning: Couldn't find the stream associated with an evaluate."
);
else {
const source = this.project
.getSources()
.findIndex((source) => source.root === root);
this.#inputs.push({
source,
path: root.getPath(evaluate),
number,
stepIndex: this.#stepIndex,
Expand Down

0 comments on commit a82ad86

Please sign in to comment.