Skip to content

Commit 4015b05

Browse files
Add workflow_settings.yaml validation/completion VSCode extension (#1770)
* add workflow_settings.yaml validation to vscode extension * fix: shows errors on unknown properties
1 parent b322655 commit 4015b05

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

vscode/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sh_binary(
3333
":language-configuration.json",
3434
":package.json",
3535
":sqlx.grammar.json",
36+
":workflow_settings_yaml.schema.json",
3637
":vscode-sources",
3738
],
3839
)
@@ -47,6 +48,7 @@ sh_binary(
4748
":README.md",
4849
":LICENSE",
4950
":sqlx.grammar.json",
51+
":workflow_settings_yaml.schema.json",
5052
":vscode-sources",
5153
],
5254
)

vscode/extension.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,35 @@ export async function activate(context: vscode.ExtensionContext) {
5656
client.onNotification("success", message => {
5757
vscode.window.showInformationMessage(message);
5858
});
59+
60+
// Recommend YAML extension if not installed
61+
// We also can add the extension to "extensionDependencies" in package.json,
62+
// but this way we can avoid forcing users to install the extension.
63+
// You can control this recommendation behavior through the setting.
64+
if (workspace.getConfiguration("dataform").get("recommendYamlExtension")) {
65+
const yamlExtension = vscode.extensions.getExtension("redhat.vscode-yaml");
66+
if (!yamlExtension) {
67+
await vscode.window.showInformationMessage(
68+
"The Dataform extension recommends installing the YAML extension for workflow_settings.yaml support.",
69+
"Install",
70+
"Don't show again"
71+
).then(selection => {
72+
if (selection === "Install") {
73+
// Open the YAML extension page
74+
vscode.env.openExternal(
75+
vscode.Uri.parse(
76+
"vscode:extension/redhat.vscode-yaml"
77+
)
78+
);
79+
} else if (selection === "Don't show again") {
80+
// Disable the recommendation
81+
workspace.getConfiguration("dataform").update(
82+
"recommendYamlExtension",
83+
false,
84+
vscode.ConfigurationTarget.Global
85+
);
86+
}
87+
});
88+
}
89+
}
5990
}

vscode/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
},
4141
"default": [],
4242
"markdownDescription": "An array of additional arguments the extension should pass to the Dataform cli while executing `dataform compile --json`."
43+
},
44+
"dataform.recommendYamlExtension": {
45+
"type": "boolean",
46+
"default": true,
47+
"markdownDescription": "Whether to recommend the YAML extension for validating `workflow_settings.yaml`."
4348
}
4449
}
4550
}
@@ -66,6 +71,12 @@
6671
"scopeName": "source.sqlx",
6772
"path": "sqlx.grammar.json"
6873
}
74+
],
75+
"yamlValidation": [
76+
{
77+
"fileMatch": "workflow_settings.yaml",
78+
"url": "./workflow_settings_yaml.schema.json"
79+
}
6980
]
7081
}
7182
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"$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.",
5+
"additionalProperties": false,
6+
"properties": {
7+
"dataformCoreVersion": {
8+
"type": "string",
9+
"description": "The desired dataform core version to compile against."
10+
},
11+
"defaultProject": {
12+
"type": "string",
13+
"description": "The default Google Cloud project (database)."
14+
},
15+
"defaultDataset": {
16+
"type": "string",
17+
"description": "The default dataset (schema)."
18+
},
19+
"defaultLocation": {
20+
"type": "string",
21+
"description": "The default BigQuery location to use."
22+
},
23+
"defaultAssertionDataset": {
24+
"type": "string",
25+
"description": "The default dataset (schema) for assertions."
26+
},
27+
"vars": {
28+
"type": "object",
29+
"description": "User-defined variables that are made available to project code during compilation. An object containing a list of key-value pairs.",
30+
"additionalProperties": {
31+
"type": "string"
32+
}
33+
},
34+
"projectSuffix": {
35+
"type": "string",
36+
"description": "The suffix to append to all Google Cloud project references."
37+
},
38+
"datasetSuffix": {
39+
"type": "string",
40+
"description": "The suffix to append to all dataset references."
41+
},
42+
"namePrefix": {
43+
"type": "string",
44+
"description": "The prefix to append to all action names."
45+
},
46+
"defaultNotebookRuntimeOptions": {
47+
"type": "object",
48+
"description": "Default runtime options for Notebook actions.",
49+
"outputBucket": {
50+
"type": "string",
51+
"description": "Storage bucket to output notebooks to after their execution."
52+
}
53+
}
54+
},
55+
"required": [
56+
"dataformCoreVersion"
57+
]
58+
}

0 commit comments

Comments
 (0)