-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
75 lines (65 loc) · 1.96 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const vscode = require("vscode");
const webViewContent = require("./webViewContent");
const path = require("path");
const Utils = require("./src/utils");
/*******************
* Constants
*******************/
const SUPPORTED_FILES = ["javascript", "typescript", "javascriptreact", "typescriptreact"];
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
// track current webview
let currentPanel = undefined;
context.subscriptions.push(
vscode.commands.registerCommand("rtlcheatsheet.rtlCheatsheet", () => {
const columnToShowIn = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined;
if (currentPanel) {
currentPanel.reveal(columnToShowIn);
} else {
const styleRoot = vscode.Uri.file(
path.join(context.extensionPath, "style")
);
currentPanel = vscode.window.createWebviewPanel(
"rtlCheatsheet",
"React Testing Library Cheatsheet",
vscode.ViewColumn.Beside,
{
localResourceRoots: [styleRoot],
}
);
currentPanel.webview.html = webViewContent.getWebViewContent(
currentPanel.webview.cspSource,
currentPanel.webview.asWebviewUri(styleRoot)
);
// Reset when the current panel is closed
currentPanel.onDidDispose(
() => {
currentPanel = undefined;
},
null,
context.subscriptions
);
}
}),
vscode.languages.registerHoverProvider(SUPPORTED_FILES, {
provideHover(doc, pos) {
const { range, link } = Utils.getPropertyRangeAtPosition(doc, pos);
if (range === undefined) {
return;
}
const markdownString = Utils.buildMarkdownString(link);
return new vscode.Hover(markdownString, range);
},
})
);
}
exports.activate = activate;
function deactivate() {}
module.exports = {
activate,
deactivate,
};