This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
53 lines (47 loc) · 1.61 KB
/
extension.js
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
// The module 'vscode' contains the VS Code extensibility API Import the module
// and reference it with the alias vscode in your code below
const vscode = require('vscode');
const DocumentRender = require('./render');
// this method is called when your extension is activated your extension is
// activated the very first time the command is executed
const support_exts = ["json", "yml", "yaml"];
function preview(context) {
let render = new DocumentRender(context);
var editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
let text = editor
.document
.getText();
let uri = render.render(editor.document.fileName, text);
vscode.window.showErrorMessage(uri);
vscode
.commands
.executeCommand('vscode.previewHtml', uri , vscode.ViewColumn.Two, "OpenAPI Preview")
.then(null, reason => {
vscode
.window
.showErrorMessage(reason);
});
}
function activate(context) {
// console.log("openapi view activate");
let disposable = vscode
.commands
.registerCommand('extension.previewInSide', function () {
preview(context);
vscode.workspace.onDidSaveTextDocument((event) => {
if (support_exts.indexOf(event.fileName.split('.').pop()) > -1){
preview(context);
}
});
});
context
.subscriptions
.push(disposable);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {}
exports.deactivate = deactivate;