Skip to content

Conversation

tobias-tengler
Copy link
Contributor

No description provided.

@tobias-tengler tobias-tengler changed the title (WIP) Add editor support for JSON config schema [WIP] Add editor support for JSON config schema Jun 23, 2024
@tobias-tengler tobias-tengler force-pushed the json-schema-editor-support branch from f99e430 to 82ea067 Compare June 23, 2024 21:10
@tobias-tengler tobias-tengler force-pushed the json-schema-editor-support branch 3 times, most recently from 65293b7 to 29ede39 Compare June 24, 2024 05:56
@captbaritone
Copy link
Contributor

captbaritone commented Jun 25, 2024

I just had another idea. Since the VSCode extension already knows how to invoke the compiler binary, and the compiler binary can construct the json schema, what if we added a separate compiler command to return the schema text on stdout? It seems like that might be simpler. It would also work better for us internally since we don't access the compiler via an NPM module but a separate binary deployment which would be hard to update to also sync a sibling file.

I'll work on a compile diff to add this support.

@tobias-tengler tobias-tengler force-pushed the json-schema-editor-support branch 2 times, most recently from 9c31623 to 0982908 Compare June 28, 2024 19:36
@tobias-tengler tobias-tengler changed the base branch from json-schema to main June 28, 2024 19:37
@tobias-tengler tobias-tengler marked this pull request as ready for review June 28, 2024 19:37
@tobias-tengler tobias-tengler changed the title [WIP] Add editor support for JSON config schema Add editor support for JSON config schema Jun 28, 2024

provideTextDocumentContent(uri: Uri): ProviderResult<string> {
if (uri.authority === PACKAGE_JSON_RELAY_CONFIG_SCHEMA_PATH) {
return `{"properties": { "relay": { "$ref": "${RelayTextDocumentContentProvider.scheme}://${RELAY_CONFIG_SCHEMA_PATH}", "description": "Relay.js configuration" }}}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This little recursion trick is so clever. Nice.

}

if (uri.authority === RELAY_CONFIG_SCHEMA_PATH) {
this.cachedJsonSchema ||= this.loadConfigJsonSchema();
Copy link
Contributor

Choose a reason for hiding this comment

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

If the user changes their relay binary path in the config file, does this get invalidated correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but you have to restart the extension anyways because the binary information is only loaded once at startup atm.


if (binaryVersion) {
const hasConfigJsonSchemaCommand =
semver.satisfies(binaryVersion, '>=18.0') ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably needs to be updated depending on what the release schedule will be like. Just picked the next major for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it will be in the next release, can we just say >17.0.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, one more realization. What happens if you use a version of the compiler from the @main NPM tag? Will that work or not? Would be cool to be able to test this end to end before the next release by installing the new version of the extension and installing relay-compiler@main (note that @main releases are currently stuck due to broken CI)

@tobias-tengler tobias-tengler force-pushed the json-schema-editor-support branch from 0982908 to 7e70f40 Compare June 28, 2024 19:49
@tobias-tengler
Copy link
Contributor Author

The Prettier and ESLint rules are conflicting... Nice

@tobias-tengler tobias-tengler force-pushed the json-schema-editor-support branch from 7e70f40 to 8a02bdb Compare June 28, 2024 20:07
@@ -25,6 +25,7 @@ module.exports = {
'operator-linebreak': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/object-curly-spacing': 'off',
'@typescript-eslint/brace-style': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call.

@tobias-tengler
Copy link
Contributor Author

Verified that it would attempt to load the JSON schema for a prerelease compiler (but it wasn't working of course since there isn't a released version with the config-json-schema command yet).
Should be good to go :)

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@captbaritone merged this pull request in c434290.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants