Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggest template variables when symbol is unknown #48

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

ddneilson
Copy link
Contributor

What was the problem/requirement? (What/Why)

When the user has a format string in their template that references a template variable that doesn't exist (either at that scope or otherwise) we just provide a generic "symbol unknown" style error message. We can do better.

What was the solution? (How)

Add a recommender based on the edit distance between the unknown symbol and the available symbols at that location. This is mostly targetting typo errors (e.g. "Parm.Foo" instead of "Param.Foo") right now, so we also have a threshold distance to avoid some misleading suggestions.

What is the impact of this change?

Given a template like:

specificationVersion: jobtemplate-2023-09
name: DemoJob
parameterDefinitions:
- name: Foo
  type: INT
steps:
- name: DemoStep
  script:
    actions:
      onRun:
        command: echo
        args:
        - "{{Parm.Foo}}"

We generate the error:

__root__ -> steps[0] -> script -> actions -> onRun -> args[0]:
        Variable Parm.Foo does not exist at this location. Did you mean: Param.Foo

How was this change tested?

I added unit tests to cover the new functionality.

Was this change documented?

No need.

Is this a breaking change?

Nope.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ddneilson ddneilson requested a review from a team as a code owner February 5, 2024 00:14
@ddneilson ddneilson force-pushed the ddneilson/edit_distance branch 3 times, most recently from 3aa8ef6 to eee23f5 Compare February 6, 2024 16:37
Problem:
 When the user has a format string in their template that references a
template variable that doesn't exist (either at that scope or otherwise)
we just provide a generic "symbol unknown" style error message. We can
do better.

Solution:
 Add a recommender based on the edit distance between the unknown symbol
and the available symbols at that location. This is mostly targetting
typo errors (e.g. "Parm.Foo" instead of "Param.Foo") right now, so we
also have a threshold distance to avoid some misleading suggestions.

Result:

Given a template like:

```yaml
specificationVersion: jobtemplate-2023-09
name: DemoJob
parameterDefinitions:
- name: Foo
  type: INT
steps:
- name: DemoStep
  script:
    actions:
      onRun:
        command: echo
        args:
        - "{{Parm.Foo}}"
```

We generate the error:

```
__root__ -> steps[0] -> script -> actions -> onRun -> args[0]:
        Variable Parm.Foo does not exist at this location. Did you mean: Param.Foo
```

Signed-off-by: Daniel Neilson <53624638+ddneilson@users.noreply.github.com>
@ddneilson ddneilson merged commit 435971a into mainline Feb 6, 2024
15 checks passed
@ddneilson ddneilson deleted the ddneilson/edit_distance branch February 6, 2024 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants