-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
225 lines (194 loc) · 6.8 KB
/
Copy pathextension.js
File metadata and controls
225 lines (194 loc) · 6.8 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
const vscode = require("vscode");
const MOTIVATE_COMMAND = "code-motivator.motivate";
const CONFIG_SECTION = "codeMotivator";
const MESSAGE_INTERVAL_KEY = "messageInterval";
const CELEBRATION_STEP = 50;
const DEFAULT_MESSAGE_INTERVAL = 300000;
const MESSAGES = [
"🔥 ¡Vas increíble! Sigue así",
"💪 Cada línea de código cuenta",
"🚀 Eres un crack del código",
"⚡ El bug no tiene chance contra ti",
"🎯 Focus mode: ACTIVATED",
"🌟 Tu código es arte",
"💻 Tú puedes con esto",
"🦾 Debugging = ser detective",
"💻 Hoy serás imparable",
"🎨 El código limpio es poesía",
"😎 Ese commit va a quedar legendario",
"🤙 Tranqui, ya casi sale",
"🧠 Tu cerebro está en modo pro",
"☕ Respira, estás haciendo magia",
"🎮 Programar es tu superpoder",
"👾 Los bugs tiemblan cuando te ven",
"🌮 Después de esto, te mereces algo rico",
"🔮 Tu yo del futuro te lo va a agradecer",
"💯 Estás rompiendo el teclado de lo pro que eres",
"🏆 Este código merece un premio",
"🎸 Estás codeando como rockstar",
"🍕 Stack Overflow estaría orgulloso",
"🐛 Los bugs te tienen miedo",
"✨ Esa función quedó hermosa",
"🎯 100% concentración, 0% distracciones",
"🚁 Estás volando con este código",
"🔊 Tu código habla por sí solo",
"🎭 Shakespeare escribía, tú programas",
"🦸 Eres el héroe que este proyecto necesita",
"📚 Cada error es aprendizaje",
"🌊 Fluyes al programar",
"🎪 Este proyecto será épico",
"🍔 Code, test, commit, repeat",
"🎤 Tu código canta",
"🌈 Estás creando algo increíble",
"⭐ Ese algoritmo quedó perfecto",
"🎲 La suerte está de tu lado hoy",
"🧩 Cada función encaja perfecto",
"🎊 ¡BOOM! Esa solución fue brillante",
"🌙 Codeando hasta el amanecer (pero descansa)",
"🎈 La motivación está a tope",
"🥇 Primera clase, primera línea",
"🎵 Tu código tiene ritmo",
"🌺 Ese merge va a quedar limpio",
"🎿 Deslizándote entre las líneas",
"🏄 Surfeando el código como nadie",
"🥳 Celebremos cada pequeño avance",
"🍿 Este código es mejor que una película",
"🌻 Tu esfuerzo florecerá pronto",
"🎓 Aprendiendo y mejorando cada día",
];
function getRandomMessage(random = Math.random) {
return MESSAGES[Math.floor(random() * MESSAGES.length)];
}
function getConfiguredInterval(workspace = vscode.workspace) {
const rawValue = workspace
.getConfiguration(CONFIG_SECTION)
.get(MESSAGE_INTERVAL_KEY, DEFAULT_MESSAGE_INTERVAL);
return Number.isFinite(rawValue) && rawValue > 0
? rawValue
: DEFAULT_MESSAGE_INTERVAL;
}
function createSessionTracker(documents = []) {
const lineCountsByDocument = new Map();
let totalAddedLines = 0;
let nextCelebrationTarget = CELEBRATION_STEP;
for (const document of documents) {
lineCountsByDocument.set(document.uri.toString(), document.lineCount);
}
return {
registerDocument(document) {
lineCountsByDocument.set(document.uri.toString(), document.lineCount);
},
unregisterDocument(document) {
lineCountsByDocument.delete(document.uri.toString());
},
trackDocumentChange(document) {
const documentKey = document.uri.toString();
const previousLineCount = lineCountsByDocument.get(documentKey) ?? document.lineCount;
const currentLineCount = document.lineCount;
const addedLines = Math.max(0, currentLineCount - previousLineCount);
lineCountsByDocument.set(documentKey, currentLineCount);
if (addedLines > 0) {
totalAddedLines += addedLines;
}
const reachedCelebrationTarget = totalAddedLines >= nextCelebrationTarget;
if (reachedCelebrationTarget) {
while (totalAddedLines >= nextCelebrationTarget) {
nextCelebrationTarget += CELEBRATION_STEP;
}
}
return {
totalAddedLines,
reachedCelebrationTarget,
};
},
getTotalAddedLines() {
return totalAddedLines;
},
};
}
function updateStatusBar(statusBarItem, totalAddedLines) {
statusBarItem.text = `$(rocket) ${totalAddedLines} líneas añadidas`;
}
function showMotivationalMessage(window = vscode.window, random = Math.random) {
const message = getRandomMessage(random);
return window.showInformationMessage(message);
}
function activate(context) {
console.log("Code Motivator está activo!");
const sessionTracker = createSessionTracker(vscode.workspace.textDocuments);
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
100,
);
statusBarItem.tooltip = "Code Motivator";
updateStatusBar(statusBarItem, sessionTracker.getTotalAddedLines());
statusBarItem.show();
let motivationalTimer;
const restartMotivationalTimer = () => {
if (motivationalTimer) {
clearInterval(motivationalTimer);
motivationalTimer = undefined;
}
const interval = getConfiguredInterval();
motivationalTimer = setInterval(() => {
void showMotivationalMessage();
}, interval);
};
const motivateCommand = vscode.commands.registerCommand(MOTIVATE_COMMAND, () => {
void showMotivationalMessage();
});
const textDocumentChangeListener = vscode.workspace.onDidChangeTextDocument((event) => {
const { totalAddedLines, reachedCelebrationTarget } = sessionTracker.trackDocumentChange(
event.document,
);
updateStatusBar(statusBarItem, totalAddedLines);
if (reachedCelebrationTarget) {
void vscode.window.showInformationMessage(
`🔥 ¡${totalAddedLines} líneas añadidas en esta sesión!`,
);
}
});
const textDocumentOpenListener = vscode.workspace.onDidOpenTextDocument((document) => {
sessionTracker.registerDocument(document);
});
const textDocumentCloseListener = vscode.workspace.onDidCloseTextDocument((document) => {
sessionTracker.unregisterDocument(document);
});
const configurationChangeListener = vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration(`${CONFIG_SECTION}.${MESSAGE_INTERVAL_KEY}`)) {
restartMotivationalTimer();
}
});
restartMotivationalTimer();
void vscode.window.showInformationMessage(
"💪 Code Motivator activado. Usa Ctrl+Alt+M o Cmd+Alt+M para motivarte.",
);
context.subscriptions.push(
motivateCommand,
statusBarItem,
textDocumentChangeListener,
textDocumentOpenListener,
textDocumentCloseListener,
configurationChangeListener,
new vscode.Disposable(() => {
if (motivationalTimer) {
clearInterval(motivationalTimer);
}
}),
);
}
function deactivate() {}
module.exports = {
activate,
deactivate,
__testing: {
CELEBRATION_STEP,
DEFAULT_MESSAGE_INTERVAL,
MESSAGES,
createSessionTracker,
getConfiguredInterval,
getRandomMessage,
showMotivationalMessage,
updateStatusBar,
},
};