-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextension.js
50 lines (44 loc) · 1.38 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
const vscode = require("vscode")
const { formatCurrentFile, formatProject, copyPintJsonToRoot } = require("./utils/commands")
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
context.subscriptions.push(
vscode.commands.registerCommand("laravel-pint-vscode.format", async () => {
await formatProject()
})
)
context.subscriptions.push(
vscode.commands.registerCommand("laravel-pint-vscode.format-file", async () => {
await formatCurrentFile()
})
)
context.subscriptions.push(
vscode.commands.registerCommand("laravel-pint-vscode.publish-config", async () => {
copyPintJsonToRoot()
})
)
context.subscriptions.push(
vscode.workspace.onWillSaveTextDocument(async (event) => {
if (event.document.fileName.endsWith(".php")) {
let allConfig = JSON.parse(JSON.stringify(await vscode.workspace.getConfiguration()))
try {
if (allConfig.editor.laravel.pint.enabled) {
await formatCurrentFile(false)
}
} catch (e) {
// console.log(e)
}
}
})
)
}
// this method is called when your extension is deactivated
function deactivate() {
//
}
module.exports = {
activate,
deactivate
}