redhat-developer / vscode-yaml

YAML support for VS Code with built-in kubernetes syntax support
MIT License
671 stars 224 forks source link

There should be a way to specify Schema file that is part of the project #123

Open lashchev opened 6 years ago

lashchev commented 6 years ago

During active development, especially for a small or local or private project there is no justification to post schema to some hosted location, like Schema store.

yaml.schemas settings should allow specifying ${workspaceFolder} placeholder in file:///local-path or, ideally, just recognize relative path notation

For example: /schemas/my-schema.json should mean that schema file is located in file:///${workspaceFolder}/schemas/my-schema.json

The only way it works right now is if we specify absolute path of the schema file on local file system in Worspace settings file, but it doesn't work in generall, because different developers / dev boxes have different folder names/structure.

VSCode-yaml extension v0.0.16 VSCode: (windows portable install) Version: 1.27.2 Commit: f46c4c469d6e6d8c46f268d1553c5dc4b475840f Date: 2018-09-12T16:17:45.060Z Electron: 2.0.7 Chrome: 61.0.3163.100 Node.js: 8.9.3 V8: 6.1.534.41 Architecture: x64

JPinkney commented 6 years ago

If i'm not mistaken you can do something like:

yaml.schemas: {
    "./schemas/my-schema.json": "my.schema.yaml"
}

So that "./schemas/my-schema.json is applied to my.schema.yaml.

Relative paths should work.

lashchev commented 6 years ago

@JPinkney Your example indeed works, but only in single-folder workspace (at least we couldn't make it work in muulti-root workpsace). Is there any trick on how to make it work in multi-folder workspace?

If feels like it be better to support standard VSCode reference variables as in https://code.visualstudio.com/docs/editor/variables-reference

Could you please clarify what do you mean by relative paths? Relative to what?

Also, we need a way to specify that schema location is relative to the YAML file. The simplified folder structure of our data is like this:

\dataSet1\data\my.yaml
\dataSet1\schemas\mySchema.json
\dataSet2\data\my.yaml
\dataSet2\schemas\mySchema.json

So, we would like to specify something like this in yaml.schemas:

"my.yaml": "../schemas/mySchema.json"

Currently, ../schemas will point to the folder one level above of the project folder.

boopathi commented 5 years ago

I'd like to use

where some schemas are shared between multiple projects.

jmigual commented 8 months ago

I was trying to get something like:

# yaml-language-server: ${workspaceFolder}/my-schema.json

But it didn't seem to work. Would this be possible?

ptr727 commented 6 months ago

Yes please, setting schema sets an absolute path that works on just that system not any system.

ChristopherJTrent commented 2 months ago

If i'm not mistaken you can do something like:

yaml.schemas: {
    "./schemas/my-schema.json": "my.schema.yaml"
}

So that "./schemas/my-schema.json is applied to my.schema.yaml.

Relative paths should work.

this appears to have been removed in favor of the rather frustratingly unhelpful error message "unable to load schema from '/<whatever path you specified>': No Content." Would it be possible to either have the marketplace description updated to note what is meant by

"It is possible to specify a yaml schema using a modeline. Schema url can be a relative path. If a relative path is specified, it is calculated from yaml file path, not from workspace root path"

or have the extension updated to use a more user-friendly path resolution method?

EDIT: It turns out I was incorrect on this. I just encountered a bit of a footgun created by a mismatch between the marketplace description and the README. Reading the README here gives the correct information, while the information in the vscode marketplace appears to be outdated. Definitely would be happy to see an update to the marketplace page to bring it in line with the README here.