Skip to content

Commit

Permalink
Define Inputs corresponding definition to enable code localization.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jul 13, 2024
1 parent 5874b86 commit 4b04390
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http:
- Fixed closing text delimiter localization.
- Hide comma separator when localizing names and docs.
- Permit comma separators between text literals, docs, and names, allowing line breaks for text.
- Define `Input`s corresponding definition to enable code localization.

## 0.10.4 2024-07-08

Expand Down
2 changes: 2 additions & 0 deletions src/nodes/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ export default class Context {
visit(node: Node) {
this.stack.push(node);
}

unvisit() {
this.stack.pop();
}

visited(node: Node) {
return this.stack.includes(node);
}
Expand Down
15 changes: 15 additions & 0 deletions src/nodes/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import SimpleExpression from './SimpleExpression';
import Evaluate from './Evaluate';
import Refer from '@edit/Refer';
import ExpressionPlaceholder from './ExpressionPlaceholder';
import type Definition from './Definition';

export default class Input extends SimpleExpression {
readonly name: Token;
Expand Down Expand Up @@ -122,6 +123,20 @@ export default class Input extends SimpleExpression {
return this.value.evaluateTypeGuards(current, guard);
}

/** Get the bind to which this input corresponds. */
getCorrespondingDefinition(context: Context): Definition | undefined {
const parent = context.getRoot(this)?.getParent(this);
if (parent instanceof Evaluate) {
const fun = parent.getFunction(context);
if (fun)
return fun.inputs.find((input) =>
input.hasName(this.getName()),
);
}

return undefined;
}

getName() {
return this.name.getText();
}
Expand Down

0 comments on commit 4b04390

Please sign in to comment.