-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbundleAutocompleteProvider.ts
More file actions
65 lines (60 loc) · 2.33 KB
/
Copy pathbundleAutocompleteProvider.ts
File metadata and controls
65 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {CliWrapper} from "../cli/CliWrapper";
import {ExtensionContext, extensions, Uri} from "vscode";
import {BundleFileSet} from "./BundleFileSet";
import {BundleWatcher} from "./BundleWatcher";
export async function registerBundleAutocompleteProvider(
cli: CliWrapper,
bundleFileSet: BundleFileSet,
bundleWatcher: BundleWatcher,
context: ExtensionContext
) {
// get freshly generated bundle schema
const bundleSchema = await cli.getBundleSchema();
// URI scheme for DABs JSON schemas
const dabsUriScheme = "dabs";
// URI for bundle root config json schema
const rootConfigSchemaUri = `${dabsUriScheme}:///declarative-automation-bundles.json`;
const extensionYaml = extensions.getExtension("redhat.vscode-yaml");
if (extensionYaml) {
const redHatYamlSchemaApi = await extensionYaml.activate();
// We use the API exposed from teh activate() function of the redhat.vscode-yaml
// extension to registor a custom schema provider
let bundleFileList = await bundleFileSet.allFiles();
context.subscriptions.push(
bundleWatcher.onDidChangeRootFile(async () => {
bundleFileList = await bundleFileSet.allFiles();
}),
bundleWatcher.onDidCreate(async (e) => {
bundleFileList.push(e);
}),
bundleWatcher.onDidDelete(async (e) => {
const idx = bundleFileList.findIndex(
(v) => v.fsPath === e.fsPath
);
if (idx !== -1) {
bundleFileList.splice(idx, 1);
}
})
);
redHatYamlSchemaApi.registerContributor(
"dabs",
(resource: string) => {
const resourceUri = Uri.parse(resource);
if (
bundleFileList.find(
(i) => i.fsPath === resourceUri.fsPath
) !== undefined
) {
return rootConfigSchemaUri;
}
},
(uri: string) => {
// Any JSON schemas with URI scheme = "dabs" resolves here
const parsedUri = Uri.parse(uri);
if (parsedUri.scheme === dabsUriScheme) {
return bundleSchema;
}
}
);
}
}