-
-
Notifications
You must be signed in to change notification settings - Fork 448
/
extension.ts
83 lines (72 loc) · 2.5 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
71
72
73
74
75
76
77
78
79
80
81
82
83
import { commands, ExtensionContext, workspace } from "vscode";
import { createConfigFile } from "./commands";
import { LoggingService } from "./LoggingService";
import { ModuleResolver } from "./ModuleResolver";
import PrettierEditService from "./PrettierEditService";
import { StatusBar } from "./StatusBar";
import { TemplateService } from "./TemplateService";
import { getConfig } from "./util";
import { RESTART_TO_ENABLE, EXTENSION_DISABLED } from "./message";
// the application insights key (also known as instrumentation key)
const extensionName = process.env.EXTENSION_NAME || "dev.prettier-vscode";
const extensionVersion = process.env.EXTENSION_VERSION || "0.0.0";
export function activate(context: ExtensionContext) {
const loggingService = new LoggingService();
loggingService.logInfo(`Extension Name: ${extensionName}.`);
loggingService.logInfo(`Extension Version: ${extensionVersion}.`);
const { enable, enableDebugLogs } = getConfig();
if (enableDebugLogs) {
loggingService.setOutputLevel("DEBUG");
}
if (!enable) {
loggingService.logInfo(EXTENSION_DISABLED);
context.subscriptions.push(
workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("prettier.enable")) {
loggingService.logWarning(RESTART_TO_ENABLE);
}
})
);
return;
}
const moduleResolver = new ModuleResolver(loggingService);
const templateService = new TemplateService(
loggingService,
moduleResolver.getGlobalPrettierInstance()
);
const statusBar = new StatusBar();
const editService = new PrettierEditService(
moduleResolver,
loggingService,
statusBar
);
editService
.registerGlobal()
.then(() => {
const createConfigFileFunc = createConfigFile(templateService);
const createConfigFileCommand = commands.registerCommand(
"prettier.createConfigFile",
createConfigFileFunc
);
const openOutputCommand = commands.registerCommand(
"prettier.openOutput",
() => {
loggingService.show();
}
);
const forceFormatDocumentCommand = commands.registerCommand(
"prettier.forceFormatDocument",
editService.forceFormatDocument
);
context.subscriptions.push(
editService,
createConfigFileCommand,
openOutputCommand,
forceFormatDocumentCommand,
...editService.registerDisposables()
);
})
.catch((err) => {
loggingService.logError("Error registering extension", err);
});
}