-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathextension.ts
executable file
·70 lines (63 loc) · 2.26 KB
/
extension.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
import * as vscode from "vscode";
import * as luals from "./luals";
import * as subscriptions from "./subscriptions";
export async function activate(context: vscode.ExtensionContext) {
console.log("loaded", context.extension.id);
registerActivationCommand(context);
if (isWowWorkspace() || await hasTocFile()) {
activateWowExtension(context);
}
}
// check if this workspace has already been used with the extension
function isWowWorkspace() {
const config = vscode.workspace.getConfiguration("Lua");
// note config.get returns the workspace config if it exists, otherwise the global user config
const workspaceValue = config.inspect("workspace.library")?.workspaceValue as string[];
if (workspaceValue) {
return workspaceValue.find((value) => value.includes("wow-api"));
}
}
async function hasTocFile() {
// the glob pattern appears to be case sensitive
const tocFiles = await vscode.workspace.findFiles("**/*.{toc,TOC}");
for (const toc of tocFiles) {
const document = await vscode.workspace.openTextDocument(toc);
for (let i = 0; i < document.lineCount; i++) {
const line = document.lineAt(i);
// there can be any number of spaces in toc format directives
// directives are case insensitive
const hasDirective = line.text.startsWith("##");
const isInterface = line.text.toLowerCase().includes("interface");
const hasColon = line.text.includes(":");
if (hasDirective && isInterface && hasColon) {
return true;
}
}
}
}
function registerActivationCommand(context: vscode.ExtensionContext) {
let isLoaded = false;
const handler = () => {
if (!isLoaded) {
isLoaded = true; // using a command already activates the extension
vscode.window.showInformationMessage("Activated WoW API extension.");
}
else {
vscode.window.showInformationMessage("WoW API extension is already activated.");
}
};
context.subscriptions.push(vscode.commands.registerCommand("wowAPI.activateExtension", handler));
}
async function activateWowExtension(context: vscode.ExtensionContext) {
subscriptions.registerCompletion(context);
subscriptions.registerHover(context);
luals.setRuntime();
luals.setWowLibrary(context);
if (await luals.isFrameXmlFolder()) {
luals.disableFrameXmlWarnings();
}
else {
luals.defineKnownGlobals();
luals.cleanupGlobals();
}
}