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

Show all json schemas for yaml file in codelens #424

Merged
merged 6 commits into from
Mar 24, 2021

Conversation

evidolob
Copy link
Collaborator

What does this PR do?

Add CodeLens at the beginning of the file with all applied JSON Schema's, click on that CodeLans will open JSON Schema in separate tab:

Screen.Recording.2021-03-16.at.15.58.43.mov

Als it improves opening schemas, now all possible type of schema is supported, including schema contributed from vscode-yaml api.

Note: I still not able to add navigation to specific part of JSON Schema which cause an error, as we are losing information about positions during parsing JSON.

What issues does this PR fix or reference?

#412

Is it tested? How?

With tests and manual, just open any yaml file which has JSON Schema, CodeLens with name and file name should appears above first line.

…elens

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
@evidolob evidolob self-assigned this Mar 16, 2021
@coveralls
Copy link

coveralls commented Mar 16, 2021

Coverage Status

Coverage decreased (-0.2%) to 78.549% when pulling a2567cd on evidolob:fix-i412 into 30001e5 on redhat-developer:master.

src/languageservice/services/yamlCodeActions.ts Outdated Show resolved Hide resolved
src/languageservice/services/yamlCodeLens.ts Show resolved Hide resolved
test/yamlCodeLens.test.ts Outdated Show resolved Hide resolved
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
@gorkem
Copy link
Collaborator

gorkem commented Mar 17, 2021

I am not sure about the overall experience of this. I do not think there are many users out there who are interested to navigate to json schemas. Now this path is putting navigation to schema to the front of every yaml file for the purpose of listing the schemas that the yaml is validated against. I do not think code lenses is a good fit for that purpose.

@evidolob
Copy link
Collaborator Author

@gorkem I don't think that we have much options on this, we have a lot of issues where users reports unexpected validation errors, just because yaml-ls uses wrong schema to validate file. The main goal for this PR is to show which JSON schemas used for specific yaml file, and navigation to thous schemas is optional.

An alternative way to show which schema used is to add new vscode statusbar item, which will be vscode only and requires new non standard LSP extension.

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
@@ -93,7 +94,7 @@ function addSchemasForOf(schema: JSONSchema, result: Map<string, JSONSchema>): v

function addInnerSchemaUrls(schemas: JSONSchemaRef[], result: Map<string, JSONSchema>): void {
for (const subSchema of schemas) {
if (isJSONSchema(subSchema)) {
if (!isBoolean(subSchema)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still does not confirm that it is a JSONSchema.

"I'm looking for a dog. Is a bird? No, it's not a bird. OK, it's not a bird so it must be a dog" That does not work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have only two choices, subSchema can be boolean or JSONSchema
It would be enough to check that schema is not boolean, as rest check will do TS compiler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, since you are not using an any I guess that could work.

I was thinking that if you wanted to confirm that matched the interface then test for expected mandatory fields. But I'll leave it up to you.

…rver into fix-i412

Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
@evidolob evidolob merged commit c8a1179 into redhat-developer:master Mar 24, 2021
@evidolob evidolob deleted the fix-i412 branch March 24, 2021 09:15
@andsens
Copy link

andsens commented Apr 20, 2021

Is there any way this feature can be disabled? Sometimes it takes a while before the extension figures out the schema. When opening a file it can take 1-3 seconds before I find the line I am looking for, only for the codelens to pop in at that exact moment, shifting all the lines one down and completely ruining my concentration. It's... frustrating to say the least.

@evidolob
Copy link
Collaborator Author

@andsens Just put

    "[yaml]": {
        "editor.codeLens": false
    }

in to your settings

@gorkem
Copy link
Collaborator

gorkem commented Apr 20, 2021

@evidolob this info should be on README. on vscode-yaml

@evidolob
Copy link
Collaborator Author

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.

None yet

6 participants