forked from asciidoctor/asciidoctor-vscode
/
asciidocExtensions.ts
93 lines (77 loc) · 2.68 KB
/
asciidocExtensions.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as path from 'path';
const resolveExtensionResource = (extension: vscode.Extension<any>, resourcePath: string): vscode.Uri => {
return vscode.Uri.file(path.join(extension.extensionPath, resourcePath))
.with({ scheme: 'vscode-resource' });
};
const resolveExtensionResources = (extension: vscode.Extension<any>, resourcePaths: any): vscode.Uri[] => {
const result: vscode.Uri[] = [];
if (Array.isArray(resourcePaths)) {
for (const resource of resourcePaths) {
try {
result.push(resolveExtensionResource(extension, resource));
} catch (e) {
// noop
}
}
}
return result;
};
export interface AsciidocContributions {
readonly extensionPath: string;
readonly previewScripts: vscode.Uri[];
readonly previewStylesEditor: vscode.Uri[];
readonly previewStylesDefault: vscode.Uri[];
readonly asciidocItPlugins: Thenable<(md: any) => any>[];
readonly previewResourceRoots: vscode.Uri[];
}
class AsciidocExtensionContributions implements AsciidocContributions {
private readonly _scripts: vscode.Uri[] = [];
private readonly _stylesEditor: vscode.Uri[] = [];
private readonly _stylesDefault: vscode.Uri[] = [];
private readonly _previewResourceRoots: vscode.Uri[] = [];
private readonly _plugins: Thenable<(md: any) => any>[] = [];
private _loaded = false;
public constructor(
public readonly extensionPath: string,
) { }
public get previewScripts(): vscode.Uri[] {
this.ensureLoaded();
return this._scripts;
}
public get previewStylesEditor(): vscode.Uri[] {
this.ensureLoaded();
return this._stylesEditor;
}
public get previewStylesDefault(): vscode.Uri[] {
this.ensureLoaded();
return this._stylesDefault;
}
public get previewResourceRoots(): vscode.Uri[] {
this.ensureLoaded();
return this._previewResourceRoots;
}
public get asciidocItPlugins(): Thenable<(md: any) => any>[] {
this.ensureLoaded();
return this._plugins;
}
private ensureLoaded() {
if (this._loaded) {
return;
}
this._loaded = true;
for (const extension of vscode.extensions.all) {
const contributes = extension.packageJSON && extension.packageJSON.contributes;
if (!contributes) {
continue;
}
}
}
}
export function getAsciidocExtensionContributions(context: vscode.ExtensionContext): AsciidocContributions {
return new AsciidocExtensionContributions(context.extensionPath);
}