microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.78k stars 28.73k forks source link

[json] create links for values of format `uri-reference` #128971

Open siegenthalerroger opened 3 years ago

siegenthalerroger commented 3 years ago

When authoring json it'd be great to have a richer experience when referencing other files, without having the overhead of defining a file:// URI whenever this is required (see example below). image

I would expect this behaviour by standard when the schema is defining the values as file-references, this is also related to my more pertinent issue in the vscode-yaml repository concerning the handling of k8s kustomize resources (vscode-yaml#559)

aeschli commented 3 years ago

when the schema is defining the values as file-references

Does that exist already? I'd rather not define new vscode non-standard formats.

siegenthalerroger commented 3 years ago

I've never seen it used sadly (as above) and looking at the reference (https://cswr.github.io/JsonSchema/spec/basic_types/) seems to also support the fact that it doesn't have this. On the other hand there are references that state that this does exist using an additional (optional) format definition in the schema definition (https://json-schema.org/understanding-json-schema/reference/string.html#format).

I'm currently unable to check whether vscode actually respects/supports these different formats, do you happen to know? If it is supported (and this would be preferable), then the issue clearly lies with the schema authors :)

aeschli commented 3 years ago

Yes. we support most of the format kinds. I think that format uri-reference would work for relative paths as well.

We have automatic link rendering if a value is in the URL form (scheme://authority/...). That's cheap as we can generate this without a need to test if the path exists. For relative paths this is not so easy. A lot of strings could be valid relative paths. It would be look strange if all strings get an link underline. So IMO for relative paths we require a format, such as formaturi-reference`

If you want to work on this and add link support for all elements that have format uri-reference that woukld be cool. But not sure that this would solve your request.

siegenthalerroger commented 3 years ago

Hi, sorry for the delay

If I understood you correctly, it is true that vscode currently doesn't use the format: uri-reference even if it is defined in the schema of a file right?

That would explain the issue in the vscode-yaml plugin aswell: https://github.com/redhat-developer/vscode-yaml/issues/559#issuecomment-909560115

aeschli commented 3 years ago

format: uri-reference is used for validation as seen here https://github.com/microsoft/vscode-json-languageservice/blob/main/src/parser/jsonParser.ts#L661

but not for link detection