From 32bdbe30e58a3548653996c4fe8c703bfc8a31fb Mon Sep 17 00:00:00 2001 From: Moker Date: Sun, 26 May 2024 20:04:59 +0900 Subject: [PATCH 1/2] add workflow_settings.yaml validation to vscode extension --- vscode/BUILD | 2 + vscode/extension.ts | 31 ++++++++++++ vscode/package.json | 11 +++++ vscode/workflow_settings_yaml.schema.json | 57 +++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 vscode/workflow_settings_yaml.schema.json diff --git a/vscode/BUILD b/vscode/BUILD index 5d557b009..9f0370ccf 100644 --- a/vscode/BUILD +++ b/vscode/BUILD @@ -32,6 +32,7 @@ sh_binary( ":language-configuration.json", ":package.json", ":sqlx.grammar.json", + ":workflow_settings_yaml.schema.json", ":vscode-sources", ], ) @@ -46,6 +47,7 @@ sh_binary( ":README.md", ":LICENSE", ":sqlx.grammar.json", + ":workflow_settings_yaml.schema.json", ":vscode-sources", ], ) diff --git a/vscode/extension.ts b/vscode/extension.ts index 94f51656d..aa320f35b 100644 --- a/vscode/extension.ts +++ b/vscode/extension.ts @@ -53,4 +53,35 @@ export async function activate(context: vscode.ExtensionContext) { client.onNotification("success", message => { vscode.window.showInformationMessage(message); }); + + // Recommend YAML extension if not installed + // We also can add the extension to "extensionDependencies" in package.json, + // but this way we can avoid forcing users to install the extension. + // You can control this recommendation behavior through the setting. + if (workspace.getConfiguration("dataform").get("recommendYamlExtension")) { + const yamlExtension = vscode.extensions.getExtension("redhat.vscode-yaml"); + if (!yamlExtension) { + await vscode.window.showInformationMessage( + "The Dataform extension recommends installing the YAML extension for workflow_settings.yaml support.", + "Install", + "Don't show again" + ).then(selection => { + if (selection === "Install") { + // Open the YAML extension page + vscode.env.openExternal( + vscode.Uri.parse( + "vscode:extension/redhat.vscode-yaml" + ) + ); + } else if (selection === "Don't show again") { + // Disable the recommendation + workspace.getConfiguration("dataform").update( + "recommendYamlExtension", + false, + vscode.ConfigurationTarget.Global + ); + } + }); + } + } } diff --git a/vscode/package.json b/vscode/package.json index e5eff7ace..76c9a5bfe 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -40,6 +40,11 @@ }, "default": [], "markdownDescription": "An array of additional arguments the extension should pass to the Dataform cli while executing `dataform compile --json`." + }, + "dataform.recommendYamlExtension": { + "type": "boolean", + "default": true, + "markdownDescription": "Whether to recommend the YAML extension for validating `workflow_settings.yaml`." } } } @@ -66,6 +71,12 @@ "scopeName": "source.sqlx", "path": "sqlx.grammar.json" } + ], + "yamlValidation": [ + { + "fileMatch": "workflow_settings.yaml", + "url": "./workflow_settings_yaml.schema.json" + } ] } } \ No newline at end of file diff --git a/vscode/workflow_settings_yaml.schema.json b/vscode/workflow_settings_yaml.schema.json new file mode 100644 index 000000000..b7e7bf4e5 --- /dev/null +++ b/vscode/workflow_settings_yaml.schema.json @@ -0,0 +1,57 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "$comment": "Created from 'protos/configs.proto'. Even options are specified as 'required' in proto, they might be specified from the CLI options, so leave them optional except for the dataformCoreVersion which is required in compile.", + "properties": { + "dataformCoreVersion": { + "type": "string", + "description": "The desired dataform core version to compile against." + }, + "defaultProject": { + "type": "string", + "description": "The default Google Cloud project (database)." + }, + "defaultDataset": { + "type": "string", + "description": "The default dataset (schema)." + }, + "defaultLocation": { + "type": "string", + "description": "The default BigQuery location to use." + }, + "defaultAssertionDataset": { + "type": "string", + "description": "The default dataset (schema) for assertions." + }, + "vars": { + "type": "object", + "description": "User-defined variables that are made available to project code during compilation. An object containing a list of key-value pairs.", + "additionalProperties": { + "type": "string" + } + }, + "projectSuffix": { + "type": "string", + "description": "The suffix to append to all Google Cloud project references." + }, + "datasetSuffix": { + "type": "string", + "description": "The suffix to append to all dataset references." + }, + "namePrefix": { + "type": "string", + "description": "The prefix to append to all action names." + }, + "defaultNotebookRuntimeOptions": { + "type": "object", + "description": "Default runtime options for Notebook actions.", + "outputBucket": { + "type": "string", + "description": "Storage bucket to output notebooks to after their execution." + } + } + }, + "required": [ + "dataformCoreVersion" + ] +} \ No newline at end of file From 4be2f6fc450fdfcf056cb0952d01c3963f4b6627 Mon Sep 17 00:00:00 2001 From: Moker Date: Thu, 27 Jun 2024 19:12:53 +0900 Subject: [PATCH 2/2] fix: shows errors on unknown properties --- vscode/workflow_settings_yaml.schema.json | 1 + 1 file changed, 1 insertion(+) diff --git a/vscode/workflow_settings_yaml.schema.json b/vscode/workflow_settings_yaml.schema.json index b7e7bf4e5..89e76da0f 100644 --- a/vscode/workflow_settings_yaml.schema.json +++ b/vscode/workflow_settings_yaml.schema.json @@ -2,6 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "$comment": "Created from 'protos/configs.proto'. Even options are specified as 'required' in proto, they might be specified from the CLI options, so leave them optional except for the dataformCoreVersion which is required in compile.", + "additionalProperties": false, "properties": { "dataformCoreVersion": { "type": "string",