File tree Expand file tree Collapse file tree 4 files changed +70
-1
lines changed
packages/databricks-vscode Expand file tree Collapse file tree 4 files changed +70
-1
lines changed Original file line number Diff line number Diff line change 4242 " onView:clusterView" ,
4343 " onTaskType:databricks" ,
4444 " onDebugResolve:databricks" ,
45- " onDebugResolve:databricks-workflow"
45+ " onDebugResolve:databricks-workflow" ,
46+ " workspaceContains:**/databricks.yml" ,
47+ " workspaceContains:**/bundle.yml" ,
48+ " workspaceContains:**/databricks.yaml" ,
49+ " workspaceContains:**/bundle.yaml"
4650 ],
4751 "main" : " out/extension.js" ,
4852 "types" : " out/extension.d.ts" ,
Original file line number Diff line number Diff line change 1+ import { CliWrapper } from "../cli/CliWrapper" ;
2+ import { extensions , Uri } from "vscode" ;
3+ import path from "node:path" ;
4+
5+ export async function generateBundleSchema ( cli : CliWrapper ) {
6+ // get freshly generated bundle schema
7+ const bundleSchema = await cli . getBundleSchema ( ) ;
8+
9+ // URI scheme for DABs JSON schemas
10+ const dabsUriScheme = "dabs" ;
11+
12+ // URI for bundle root config json schema
13+ const rootConfigSchemaUri = `${ dabsUriScheme } :///root.json` ;
14+
15+ const extensionYaml = extensions . getExtension ( "redhat.vscode-yaml" ) ;
16+ if ( extensionYaml ) {
17+ const redHatYamlSchemaApi = await extensionYaml . activate ( ) ;
18+
19+ // We use the API exposed from teh activate() function of the redhat.vscode-yaml
20+ // extension to registor a custom schema provider
21+ redHatYamlSchemaApi . registerContributor (
22+ "dabs" ,
23+ ( resource : string ) => {
24+ const validFileNames : string [ ] = [
25+ "databricks.yml" ,
26+ "databricks.yaml" ,
27+ "bundle.yml" ,
28+ "bundle.yaml" ,
29+ ] ;
30+ for ( const name of validFileNames ) {
31+ if ( path . basename ( resource ) === name ) {
32+ return rootConfigSchemaUri ;
33+ }
34+ }
35+ return undefined ;
36+ } ,
37+ ( uri : string ) => {
38+ // Any JSON schemas with URI scheme = "dabs" resolves here
39+ const parsedUri = Uri . parse ( uri ) ;
40+ if ( parsedUri . scheme === dabsUriScheme ) {
41+ return bundleSchema ;
42+ }
43+ }
44+ ) ;
45+ }
46+ }
Original file line number Diff line number Diff line change @@ -95,6 +95,15 @@ export class CliWrapper {
9595 return result ;
9696 }
9797
98+ public async getBundleSchema ( ) : Promise < string > {
99+ const execFile = promisify ( execFileCb ) ;
100+ const { stdout} = await execFile (
101+ this . context . asAbsolutePath ( "./bin/bricks" ) ,
102+ [ "bundle" , "schema" ]
103+ ) ;
104+ return stdout ;
105+ }
106+
98107 getAddProfileCommand ( profile : string , host : URL ) : Command {
99108 return {
100109 command : this . context . asAbsolutePath ( "./bin/bricks" ) ,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {workspaceConfigs} from "./WorkspaceConfigs";
2121import { PackageJsonUtils , UtilsCommands } from "./utils" ;
2222import { ConfigureAutocomplete } from "./language/ConfigureAutocomplete" ;
2323import { WorkspaceFsCommands , WorkspaceFsDataProvider } from "./workspace-fs" ;
24+ import { generateBundleSchema } from "./bundle/GenerateBundle" ;
2425
2526export async function activate (
2627 context : ExtensionContext
@@ -297,6 +298,15 @@ export async function activate(
297298 )
298299 ) ;
299300
301+ // generate a json schema for bundle root and load a custom provider into
302+ // redhat.vscode-yaml extension to validate bundle config files with this schema
303+ generateBundleSchema ( cli ) . catch ( ( e ) => {
304+ NamedLogger . getOrCreate ( "Extension" ) . error (
305+ "Failed to load bundle schema: " ,
306+ e
307+ ) ;
308+ } ) ;
309+
300310 connectionManager . login ( false ) . catch ( ( e ) => {
301311 NamedLogger . getOrCreate ( "Extension" ) . error ( "Login error" , e ) ;
302312 } ) ;
You can’t perform that action at this time.
0 commit comments