From 4015b05d85edd03acfcd4d92ccf4eff94e63bd4e Mon Sep 17 00:00:00 2001 From: moker-spaghetti <32996519+moker-spaghetti@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:32:18 +0900 Subject: [PATCH] Add workflow_settings.yaml validation/completion VSCode extension (#1770) * add workflow_settings.yaml validation to vscode extension * fix: shows errors on unknown properties --- vscode/BUILD | 2 + vscode/extension.ts | 31 ++++++++++++ vscode/package.json | 11 +++++ vscode/workflow_settings_yaml.schema.json | 58 +++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 vscode/workflow_settings_yaml.schema.json diff --git a/vscode/BUILD b/vscode/BUILD index 17f590bae..64c402ca9 100644 --- a/vscode/BUILD +++ b/vscode/BUILD @@ -33,6 +33,7 @@ sh_binary( ":language-configuration.json", ":package.json", ":sqlx.grammar.json", + ":workflow_settings_yaml.schema.json", ":vscode-sources", ], ) @@ -47,6 +48,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 c969b3bd0..8bfa9bfd9 100644 --- a/vscode/extension.ts +++ b/vscode/extension.ts @@ -56,4 +56,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 f0686e4cb..c279cf7b0 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..89e76da0f --- /dev/null +++ b/vscode/workflow_settings_yaml.schema.json @@ -0,0 +1,58 @@ +{ + "$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", + "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