-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
82 lines (73 loc) · 2.44 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
76
77
78
79
80
81
82
const vscode = require('vscode');
const path = require('path');
const playSound = require('play-sound')();
let enableSounds = true;
function activate(context) {
// Register a command to toggle sounds
context.subscriptions.push(
vscode.commands.registerCommand('myExtension.toggleSounds', () => {
enableSounds = !enableSounds;
vscode.window.showInformationMessage(`Sounds are now ${enableSounds ? 'enabled' : 'disabled'}.`);
})
);
// Register a listener for file save events
context.subscriptions.push(
vscode.workspace.onDidSaveTextDocument((document) => {
if (enableSounds) {
const saveSoundPath = path.join(__dirname, 'sounds', 'save.mp3');
playSound.play(saveSoundPath, (err) => {
if (err) console.log('Error playing sound:', err);
});
}
})
);
// Register a listener for push events
context.subscriptions.push(
vscode.workspace.onDidPush(() => {
if (enableSounds) {
const pushSoundPath = path.join(__dirname, 'sounds', 'push.mp3');
playSound.play(pushSoundPath, (err) => {
if (err) console.log('Error playing sound:', err);
});
vscode.window.showInformationMessage('Push successful!');
}
})
);
// Register a listener for hover events
const disposableHover = vscode.languages.registerHoverProvider('*', {
provideHover(document, position) {
if (enableSounds) {
const hoverSoundPath = path.join(__dirname, 'sounds', 'hover.mp3');
playSound.play(hoverSoundPath, (err) => {
if (err) console.log('Error playing sound:', err);
});
}
return null;
}
});
context.subscriptions.push(disposableHover);
// Register a listener for error events
const disposableError = vscode.languages.registerDiagnosticCollectionProvider('*', {
onDidChangeDiagnostics(e) {
if (enableSounds) {
const errorSoundPath = path.join(__dirname, 'sounds', 'error.mp3');
playSound.play(errorSoundPath, (err) => {
if (err) console.log('Error playing sound:', err);
});
}
}
});
context.subscriptions.push(disposableError);
// Play a sound on extension activation
const startupSoundPath = path.join(__dirname, 'sounds', 'startup.mp3');
playSound.play(startupSoundPath, (err) => {
if (err) console.log('Error playing sound:', err);
});
}
function deactivate() {
enableSounds = false;
}
module.exports = {
activate,
deactivate
};