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

support specifying schema via $schema key #354

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robberphex
Copy link

@robberphex robberphex commented Nov 16, 2020

What does this PR do?

Using $schema key to specify schema

What issues does this PR fix or reference?

Is it tested? How?

CI: Test getSchemaFromFileContent


There is a json file with $schema key:

{
    "$schema": "https://json.schemastore.org/package",
    "name": "name"
}

Auto-completion works based on schema (at VSCode).

But when I convert json to yaml:

$schema: https://json.schemastore.org/package
name: name

Auto-completion doesn't works. So, could yaml-language-server support $schema key? That what this PR do.

@evidolob
Copy link
Collaborator

@robberphex Thx for the contribution.
It would be nice if you fix prettier/eslint errors, to let CI run tests.

@robberphex robberphex force-pushed the schema-tag branch 2 times, most recently from 1dc5125 to 73bd43b Compare November 16, 2020 08:04
@coveralls
Copy link

coveralls commented Nov 16, 2020

Coverage Status

Coverage increased (+0.08%) to 79.094% when pulling c2596fc on RobberPhex:schema-tag into 2bae915 on redhat-developer:master.

@evidolob
Copy link
Collaborator

@JPinkney Can you look on this PR?

@JPinkney
Copy link
Contributor

I won't have time to look at it until next week. But I have a quick question. Since the $schema key is non-standard what happens if a user has a schema with additionalProperties: false? Does the $schema key report an error?

@evidolob
Copy link
Collaborator

@JPinkney Thx, that's what I thinking about.
@robberphex yaml-language-server supports comment based alternative for this feature.

Copy link
Contributor

@JPinkney JPinkney left a comment

Choose a reason for hiding this comment

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

I just tested it out and it seems to work well. I suppose this could be addressing a similar but slightly different use case then: https://github.com/redhat-developer/yaml-language-server#using-inlined-schema. With the inline $schema you can set the schema per yaml document and as long as whatever you are submitting the yaml to accepts additional properties then it should be fine. With the modeline it's only being set in the first document and works well in cases when the yaml cannot have additional properties.

I think a check would need to be added to the parser to not throw an error on $schema though. If I try and use the composer schema which doesn't allow additional properties:

$schema: http://json.schemastore.org/composer
abandoned: false

the autocompletion and hover work but I get: Property $schema is not allowed.yaml-schema: http://json.schemastore.org/composer on the $schema key

@shsuman
Copy link

shsuman commented Feb 18, 2021

Do you guys have any plan to merge this PR ?

@evidolob
Copy link
Collaborator

@shsuman We need to have changes in yaml parser/validator to do not throw error like Property $schema is not allowed. before we can merge this. I can look on it next week.

@shsuman
Copy link

shsuman commented Feb 18, 2021

Hello @evidolob ,
Thanks for your reply. We are planning to fork your repo and we would really want this $schema property to work. So, if you could give us a timeline for this feature to be available so that we don't have to do duplicate work

@JPinkney
Copy link
Contributor

@shsuman Just out of curiosity is there any particular reason why you would be forking?

cc @gorkem

@gorkem
Copy link
Collaborator

gorkem commented Feb 18, 2021

@shsuman Do not fork or publish the yaml LSP with your own extension such things usually breaks our functionality. We have already had similar cases with different MSFT teams. I think we have an understanding that this is not a good practice.

@joshuawilson
Copy link
Member

@shsuman PRs are welcome.

@shsuman
Copy link

shsuman commented Feb 19, 2021

@gorkem Thank you for your response. We are currently in discussion with our team regarding this issue. I will get back to you on the same

@shsuman
Copy link

shsuman commented Feb 22, 2021

@gorkem Can you briefly describe what problems have you seen in the past with other extensions shipping the Yaml LSP ?

The one thing that we are seeing is duplicate errors and suggestions but other than that we have not observed anything which would either break ours' or yours' functionality.

@gorkem
Copy link
Collaborator

gorkem commented Feb 22, 2021

@shsuman Our release cycles are not synchronized, you probably are not going to refresh the LSP as often as we do. We end up with getting bug reports for all the YAML issues. Even months after they are fixed.

It is not fair for anybody to expect us to spend time triaging bug reports because somebody have not done the right thing. Therefore, as discussed in this issue, we will warn and even disable functionality in case of conflicts.

evidolob added a commit to evidolob/yaml-language-server that referenced this pull request Mar 1, 2021
evidolob added a commit that referenced this pull request Mar 2, 2021
* #354 Fix 'fileMatch' pattern to match whole file name

Signed-off-by: Yevhen Vydolob <[email protected]>

* add test

Signed-off-by: Yevhen Vydolob <[email protected]>
@shsuman
Copy link

shsuman commented Mar 2, 2021

Hey @gorkem!

We appreciate you taking the time to listen to our query. We'd love to provide you with some context on who we are as a team and what we're hoping to achieve with the YAML language server (LS).

We're the Azure Machine Learning (ML) extension team in VS Code. Our extension aims to provide an enhanced developer experience for data scientists and ML engineers targeting the Azure ML service. Many of these users edit YAML configuration files in Code thus we were hoping to be able to provide them with schema validation and completions.

Our plan was to extend your LS to create our own Azure ML language server to provide dynamic completions and preview definitions of cloud resources in addition to the schema-based completions provided by the YAML LS. Currently our completions framework is closely coupled with the LSP validation as we have specific Azure ML tags in our schema which inform when and what completions to surface.

We would love to hear your thoughts regarding the usage and extension of the LSP. Would it be possible for our teams to meet/collaborate to address any concerns you have or talk through alternative approaches? One thing to note is that our customer segment (Azure ML users editing YAML files) is a very small subset of your overall customer base (all VS Code YAML authors) so we don't expect your repository to get flooded with outdated bug reports.

Please let us know if you have any additional questions. We look forward to hearing from you!

Best,

Shantnu Suman on behalf of the Azure ML extension team

@gorkem
Copy link
Collaborator

gorkem commented Mar 2, 2021

@shsuman
Currently we have APIs to provide schemas dynamically that will allow the YAML LS to provide validation code assist etc. We do support a few JSON schema extensions too. I am not sure if those ways would be enough but of course we are open to introducing more extensibility if there are use cases for it.

Are you looking to extend the Yaml LS or vscode-yaml though?

@shsuman
Copy link

shsuman commented Mar 4, 2021

Hey @gorkem,

Thank you for your reply.

To answer your question, we are trying to extend the Yaml LS and not vscode-yaml.

Also, my team just had a couple of follow up questions:
1. Do you have any documentation on the APIs that you talked about in your last response ?
2. What did you mean by "We do support a few JSON schema extensions too." ?

Lastly, we would highly appreciate it if you would be willing to hop on a call with us to discuss it in detail ? If yes, let me know your preferred contact method as well as your preferred time.

Regards,
Shantnu Suman on behalf of the Azure ML extension team

@shsuman
Copy link

shsuman commented Mar 12, 2021

@gorkem Just a friendly follow up on my last message. Let me know if you have any questions or concerns

@gorkem
Copy link
Collaborator

gorkem commented Mar 16, 2021

@JPinkney Do you have reference to the extension API and JSON schema extensions that we support. I thought it was a package on npm but I could not find it.

@gorkem
Copy link
Collaborator

gorkem commented Mar 16, 2021

@shsuman pinged @JPinkney he reminded me where we recorded things take a look at https://github.com/redhat-developer/vscode-yaml/wiki/Extension-API

@shsuman
Copy link

shsuman commented Mar 23, 2021

@gorkem These API won't prove much useful to us as we are trying to contribute to completions as well as diagnostics dynamically i.e. generated through our extension and not the schemas. For this very purpose, we need to be able to directly contribute to the completions as well as diagnostics returned by the LS

@gorkem
Copy link
Collaborator

gorkem commented Mar 26, 2021

I do not grok why you would need to run your own copy of the LS, if you are trying to have additional diagnostics or completions. You can register multiple providers for a file.

@shsuman
Copy link

shsuman commented Mar 26, 2021

@gorkem Because we are putting tags in our schema ("arm_type"), we are using those tags from the schema to determine whether to provide completions and also what completions to provide for a given node

@safareli
Copy link

@evidolob mentioned that this PR may cause validation errors if JSON Schema doesn’t allow additional properties for "root" Object. here redhat-developer/vscode-yaml#567 (comment)

As a user I do prefer to have this PR merged and be able to use $schema, with the caveat that until the parser changes are made it might throw on noAdditionalProperties.

@carlosedp
Copy link

Still no news on merging this?

@bollwyvl
Copy link
Contributor

bollwyvl commented May 18, 2024

I didn't see this before doing so, but opened #970 taking a slightly different approach. I'd really rather not consider ignoring "additionalProperties": false, and think the magic comment is just fine in that case. But supporting schema that allow/require $schema seems like a pretty straightforward win.

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.

10 participants