Skip to content

Commit a7d2fb5

Browse files
authored
Merge pull request #278 from xuhuanzy/upstream
update tooltip
2 parents 288103c + 98d8c62 commit a7d2fb5

File tree

2 files changed

+50
-60
lines changed

2 files changed

+50
-60
lines changed

src/emmyContext.ts

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,24 @@ interface StatusBarConfig {
4040
readonly backgroundColor?: vscode.ThemeColor;
4141
}
4242

43+
interface TooltipAction {
44+
readonly label: string;
45+
readonly command: string;
46+
readonly icon: string;
47+
readonly tooltip?: string;
48+
}
49+
4350
/**
4451
* EmmyLua extension context manager
4552
* Manages language client, status bar, and extension state
4653
*/
4754
export class EmmyContext implements vscode.Disposable {
4855
public readonly LANGUAGE_ID = 'lua' as const;
49-
56+
5057
private _client?: LanguageClient;
5158
private _serverStatus: ServerStatus;
5259
private readonly _statusBar: vscode.StatusBarItem;
5360
private readonly _disposables: vscode.Disposable[] = [];
54-
private _startTime?: Date;
5561

5662
constructor(
5763
public readonly debugMode: boolean,
@@ -62,10 +68,10 @@ export class EmmyContext implements vscode.Disposable {
6268
vscode.StatusBarAlignment.Left,
6369
100
6470
);
65-
71+
6672
// Status bar click shows quick pick menu instead of direct action
6773
this._statusBar.command = 'emmy.showServerMenu';
68-
74+
6975
this._disposables.push(this._statusBar);
7076
this.updateStatusBar();
7177
}
@@ -107,16 +113,6 @@ export class EmmyContext implements vscode.Disposable {
107113
return this._serverStatus.state === ServerState.Starting;
108114
}
109115

110-
/**
111-
* Get server uptime in seconds (if running)
112-
*/
113-
get serverUptime(): number | undefined {
114-
if (!this._startTime || !this.isServerRunning) {
115-
return undefined;
116-
}
117-
return Math.floor((Date.now() - this._startTime.getTime()) / 1000);
118-
}
119-
120116
/**
121117
* Update server status to starting
122118
*/
@@ -132,7 +128,6 @@ export class EmmyContext implements vscode.Disposable {
132128
* Update server status to running
133129
*/
134130
setServerRunning(message?: string): void {
135-
this._startTime = new Date();
136131
this._serverStatus = {
137132
state: ServerState.Running,
138133
message: message || 'EmmyLua language server is running',
@@ -155,7 +150,6 @@ export class EmmyContext implements vscode.Disposable {
155150
* Update server status to stopped
156151
*/
157152
setServerStopped(message?: string): void {
158-
this._startTime = undefined;
159153
this._serverStatus = {
160154
state: ServerState.Stopped,
161155
message: message || 'EmmyLua language server is stopped',
@@ -179,7 +173,6 @@ export class EmmyContext implements vscode.Disposable {
179173
* Update server status to error
180174
*/
181175
setServerError(message: string, details?: string): void {
182-
this._startTime = undefined;
183176
this._serverStatus = {
184177
state: ServerState.Error,
185178
message,
@@ -266,7 +259,7 @@ export class EmmyContext implements vscode.Disposable {
266259
} else if (selected.label.includes('Stop')) {
267260
await vscode.commands.executeCommand('emmy.stopServer');
268261
} else if (selected.label.includes('Start')) {
269-
await vscode.commands.executeCommand('emmy.restartServer');
262+
await vscode.commands.executeCommand('emmy.startServer');
270263
} else if (selected.label.includes('Server Info')) {
271264
this.showServerInfo();
272265
} else if (selected.label.includes('Output')) {
@@ -290,15 +283,6 @@ export class EmmyContext implements vscode.Disposable {
290283
info.push(`**Message:** ${this._serverStatus.message}`);
291284
}
292285

293-
if (this.serverUptime !== undefined) {
294-
const uptime = this.formatUptime(this.serverUptime);
295-
info.push(`**Uptime:** ${uptime}`);
296-
}
297-
298-
if (this._startTime) {
299-
info.push(`**Started:** ${this._startTime.toLocaleString()}`);
300-
}
301-
302286
if (this.debugMode) {
303287
info.push('', `**Debug Mode:** Enabled`);
304288
}
@@ -320,32 +304,14 @@ export class EmmyContext implements vscode.Disposable {
320304
});
321305
}
322306

323-
/**
324-
* Format uptime in human-readable format
325-
*/
326-
private formatUptime(seconds: number): string {
327-
const days = Math.floor(seconds / 86400);
328-
const hours = Math.floor((seconds % 86400) / 3600);
329-
const minutes = Math.floor((seconds % 3600) / 60);
330-
const secs = seconds % 60;
331-
332-
const parts: string[] = [];
333-
if (days > 0) parts.push(`${days}d`);
334-
if (hours > 0) parts.push(`${hours}h`);
335-
if (minutes > 0) parts.push(`${minutes}m`);
336-
if (secs > 0 || parts.length === 0) parts.push(`${secs}s`);
337-
338-
return parts.join(' ');
339-
}
340-
341307
// ==================== Private Methods ====================
342308

343309
/**
344310
* Update status bar display
345311
*/
346312
private updateStatusBar(): void {
347313
const config = this.getStatusBarConfig();
348-
314+
349315
this._statusBar.text = `${config.icon}EmmyLua`;
350316
this._statusBar.color = config.color;
351317
this._statusBar.backgroundColor = config.backgroundColor;
@@ -394,27 +360,49 @@ export class EmmyContext implements vscode.Disposable {
394360

395361
// Title
396362
tooltip.appendMarkdown('**EmmyLua Language Server**\n\n');
363+
tooltip.appendMarkdown('---\n\n');
397364

398365
// Status
399366
tooltip.appendMarkdown(`Status: \`${this._serverStatus.state}\`\n\n`);
400367

401-
// Message
402-
if (this._serverStatus.message) {
403-
tooltip.appendText(this._serverStatus.message);
404-
tooltip.appendText('\n\n');
368+
const actions = this.getTooltipActions();
369+
if (actions.length) {
370+
const links = actions.map((action) => {
371+
const tooltipText = action.tooltip
372+
? ` "${action.tooltip.replace(/"/g, '\\"')}"`
373+
: '';
374+
return `[${action.icon} ${action.label}](command:${action.command}${tooltipText})`;
375+
});
376+
tooltip.appendMarkdown(links.join('\n\n'));
377+
tooltip.appendMarkdown('\n\n');
405378
}
406379

407-
// Uptime
408-
if (this.serverUptime !== undefined) {
409-
const uptime = this.formatUptime(this.serverUptime);
410-
tooltip.appendMarkdown(`Uptime: \`${uptime}\`\n\n`);
411-
}
380+
return tooltip;
381+
}
412382

413-
// Actions hint
414-
tooltip.appendMarkdown('---\n\n');
415-
tooltip.appendMarkdown('*Click to show server menu*');
383+
/**
384+
* Quick actions shown in the tooltip
385+
*/
386+
private getTooltipActions(): TooltipAction[] {
387+
const actions: TooltipAction[] = [];
388+
const state = this._serverStatus.state;
389+
390+
if (state !== ServerState.Stopped && state !== ServerState.Stopping) {
391+
actions.push({
392+
label: 'Stop server',
393+
command: 'emmy.stopServer',
394+
icon: '$(stop-circle)',
395+
tooltip: 'Stop the EmmyLua language server',
396+
});
397+
}
416398

417-
return tooltip;
399+
actions.push({
400+
label: 'Restart server',
401+
command: 'emmy.restartServer',
402+
icon: '$(debug-restart)',
403+
tooltip: 'Restart the EmmyLua language server',
404+
});
405+
return actions;
418406
}
419407

420408
/**

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ async function restartServer(): Promise<void> {
317317
} else {
318318
extensionContext.setServerStopping('Restarting server...');
319319
try {
320-
await client.stop();
320+
if (client.isRunning()) {
321+
await client.stop();
322+
}
321323
await startServer();
322324
} catch (error) {
323325
const errorMessage = error instanceof Error ? error.message : String(error);

0 commit comments

Comments
 (0)