-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 relative paths for JSON schema associations (Fix #7140) #7225
Conversation
@akosyakov |
|
Yes, those cases are also covered. |
const fileUri = new URI(schemaConfig.url); | ||
if (fileUri.scheme === 'file') { | ||
const filePath = fileUri.path.toString(); | ||
const workspaceRootPath = this.workspace.rootPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not handle multi root case. We should fetch json.schemas
scoped by resource URI from each root and then apply such schemas only in the scope of a corresponding root.
Thank you for your review! Still, I have the problem (as described earlier in the first comment, section 'Remark') with loading the reference for a JSON schema that was defined with an absolute path. But, this problem only seems to exist in a single-root-workspace. |
An error seems to come from here: https://github.com/microsoft/vscode-json-languageservice/blob/2ea5ad3d2ffbbe40dea11cfe764a502becf113ce/src/services/jsonSchemaService.ts#L437-L452 Maybe you can debug it somehow or read through the code assuming your path. |
f5547ef
to
f134faf
Compare
I have tracked down the problem by debugging the vscode json language server. It listens additionally to changes of the workspace settings, and hence there the relative paths were not resolved properly. |
Signed-off-by: Nina Doschek <ndoschek@eclipsesource.com>
Signed-off-by: Nina Doschek <ndoschek@eclipsesource.com>
Signed-off-by: Nina Doschek <ndoschek@eclipsesource.com> Rebase on master
Hi @akosyakov ! |
@ndoschek sorry that it takes so long, I'm looking at it this week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is the right direction but resolutions should happen via Language Client middleware as in VS Code json extension: https://github.com/microsoft/vscode/blob/45aa0bf525b08d7e23c9b10ca65f1de55949e601/extensions/json-language-features/client/src/jsonMain.ts#L137-L140 You basically can copy code from there.
Before you continue working on it: we are going to delete this extension by mid of July and use VS Code extension instead which will automatically resolve the issue.
|
||
resolve<T>(preferenceName: string, resourceUri?: string): PreferenceResolveResult<T> { | ||
// resolve relative paths for json schema settings in workspace scope | ||
if (preferenceName === 'json.schemas' && this.getScope() === PreferenceScope.Workspace) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be done by clients? It does not look good to introduce handling of individual preferences into the preference service logic.
@@ -119,6 +149,24 @@ export class JsonClientContribution extends BaseLanguageClientContribution { | |||
} | |||
} | |||
|
|||
protected initializeJsonPreferencesAssociations(): void { | |||
const userSettings = this.preferenceService.inspect<JsonSchemaConfiguration[]>('json.schemas'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused why we need to worry about json.schemas
. We send complete json
configuration to JSON language server whenever it is changed. I don't think we need to pass it additionally as part of json/schemaAssociations
.
Thank you for your answer! Do I understand you correctly, that the Theia json extension is being replaced by the vscode json extension in July? |
Yes, we plan to deliver it latest mid July. |
What it does
JSON preferences now also accept relative paths inside a theia workspace to associate JSON schemas to JSON files.
Absolute paths and URLs still work as expected.
Remark
As mentioned in #7140, I came across a minor problem, namely the jsonSchemaService (vscode-json-languageservice) returns the following warning:
Problems loading reference 'file:///test/my-schema-definition.json': Unable to load schema from '/test/my-schema-definition.json': ENOENT: no such file or directory, open '/test/my-schema-definition.json'.
The JSON schema support works as expected now also for relative paths, but this warning occurs in files that are associated with JSON schemas via relative paths.
How to test
e.g.
/testing.json
and/.schemas/json-schema.json
e.g.
Review checklist
Reminder for reviewers
Signed-off-by: Nina Doschek ndoschek@eclipsesource.com