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

KCL-Vet should tell user the error line in json/yaml file. #253

Closed
zong-zhe opened this issue Oct 24, 2022 · 2 comments
Closed

KCL-Vet should tell user the error line in json/yaml file. #253

zong-zhe opened this issue Oct 24, 2022 · 2 comments
Labels
enhancement New feature or request feat good first issue Good for newcomers help wanted Extra attention is needed tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc.

Comments

@zong-zhe
Copy link
Contributor

Feature Request

Is your feature request related to a problem? Please describe:

KCL-Vet should tell user the error line in json/yaml file.
At present, KCL-Vet can only tell the user what is wrong with the KCL constructed by KCL-Vet.

Describe the feature you'd like:

The output error message indicates which line of json/yaml is wrong.

Describe alternatives you've considered:

None

Teachability, Documentation, Adoption, Migration Strategy:

None

@zong-zhe zong-zhe added enhancement New feature or request feat labels Oct 24, 2022
@zong-zhe zong-zhe added this to the v0.4.4 Release milestone Oct 24, 2022
@zong-zhe zong-zhe self-assigned this Oct 24, 2022
@Peefy Peefy modified the milestones: v0.4.4 Release, v0.4.5 Release Dec 4, 2022
@Peefy Peefy added the tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc. label Dec 15, 2022
@Peefy Peefy modified the milestones: v0.4.5 Release, v0.4.6 Release Jan 29, 2023
@Peefy Peefy modified the milestones: v0.4.6 Release, v0.5.0 Release Apr 10, 2023
@Peefy Peefy added the help wanted Extra attention is needed label Jul 6, 2023
@Peefy Peefy removed this from the v0.5.0 Release milestone Jul 6, 2023
@Peefy Peefy added the good first issue Good for newcomers label Jul 6, 2023
@Peefy Peefy added this to the v0.6.0 Release milestone Jul 17, 2023
@Peefy Peefy modified the milestones: v0.6.0 Release, v0.7.0 Release Sep 11, 2023
@Peefy Peefy added this to KCL 2023 Sep 18, 2023
@Peefy Peefy moved this to Backlog in KCL 2023 Sep 18, 2023
@Peefy Peefy removed this from the v0.7.0 Release milestone Nov 22, 2023
@zong-zhe
Copy link
Contributor Author

zong-zhe commented Dec 5, 2023

Research on cue vet

How does cue obtain the location information of json ?

cue language is a superset of json, and the parser of cue can parse json files.

How does cue obtain the location information of yaml?

The idea of cue validating yaml is similar to KCL, which parses the yaml file into AST, and then merges the AST of the yaml file with the AST of cue for validation.

As for the location information, the location information used by cue vet has been calculated when parsing the yaml file into AST.

cue uses a third-party library to parse yaml:

https://github.com/cue-lang/cue/tree/master/internal/third_party/yaml

Reference code:

During the process of cue parsing the yaml file, the location information of the corresponding node in the AST is updated synchronously
https://github.com/cue-lang/cue/blob/b36b4775e6a890899c460f62f8e59b4182d63c2a/internal/third_party/yaml/decode.go#L190C18-L190C22
https://github.com/cue-lang/cue/blob/b36b4775e6a890899c460f62f8e59b4182d63c2a/internal/third_party/yaml/decode.go#L303
https://github.com/cue-lang/cue/blob/b36b4775e6a890899c460f62f8e59b4182d63c2a/internal/third_party/yaml/decode.go#L451C21-L451C22

kcl vet solution

The process of kcl vet validating yaml is similar to cue, currently parsing json and yaml into kcl ast. The solution is to calculate and update the file information of json/yaml when parsing the json or yaml into the AST.

KCL's resolver and runner do not check whether the file type is a KCL file, and the diagnostic emitter will not check the file type. Therefore, the error information in the json/yaml file can also be display normally.

The part that needs to be implemented is to parse the specific location of each element during parsing the json and yaml files, and then fill it into the AST synchronously.

Json element location information third-party library https://crates.io/crates/json-spanned-value
Yaml element location information third-party library https://crates.io/crates/marked-yaml

I manually mock it into kcl-vet to show the diagnostic in json file:

截屏2023-12-05 19 57 50

@Peefy
Copy link
Contributor

Peefy commented Dec 25, 2023

Closed by #944 and #949

@Peefy Peefy closed this as completed Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat good first issue Good for newcomers help wanted Extra attention is needed tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc.
Projects
No open projects
Status: v0.7.0 Release Done
Development

No branches or pull requests

2 participants