Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Foyle status bar in the lower right corner #1757

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/extension/ai/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as ghost from './ghost'
import * as stream from './stream'
import * as generate from './generate'
import * as events from './events'
import { SessionManager } from './sessions'

// AIManager is a class that manages the AI services.
export class AIManager {
log: ReturnType<typeof getLogger>
Expand Down Expand Up @@ -69,6 +71,29 @@ export class AIManager {
vscode.window.onDidChangeActiveTextEditor(cellGenerator.handleOnDidChangeActiveTextEditor),
// vscode.window.onDidChangeActiveTextEditor(localOnDidChangeActiveTextEditor),
)

// Create a new status bar item aligned to the right
let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
statusBarItem.text = 'Session: <None>'
statusBarItem.tooltip = 'Foyle Session ID; click to copy to clipboard.'

// Attach a command to the status bar item
statusBarItem.command = 'extension.copyStatusBarText'
// Command to copy the status bar text to the clipboard
const copyTextCommand = vscode.commands.registerCommand('extension.copyStatusBarText', () => {
// Copy the status bar text to the clipboard
const pieces = statusBarItem.text.split(' ')
let id = '<no session>'
if (pieces.length >= 1) {
id = pieces[pieces.length - 1]
}
vscode.env.clipboard.writeText(id)
})
statusBarItem.show()
this.subscriptions.push(copyTextCommand)
this.subscriptions.push(statusBarItem)

SessionManager.resetManager(statusBarItem)
}

// Cleanup method. We will use this to clean up any resources when extension is closed.
Expand Down
17 changes: 15 additions & 2 deletions src/extension/ai/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LogEvent, LogEventType } from '@buf/jlewi_foyle.bufbuild_es/foyle/v1alpha1/agent_pb'
import { ulid } from 'ulidx'
import * as vscode from 'vscode'

import { getEventReporter } from './events'

Expand All @@ -25,19 +26,27 @@ export class SessionManager {
static instance: SessionManager

sessionID: string
statusBar: vscode.StatusBarItem | null

constructor() {
constructor(statusBar: vscode.StatusBarItem | null) {
this.sessionID = ulid()
this.statusBar = statusBar
}

public static getManager(): SessionManager {
if (!SessionManager.instance) {
SessionManager.instance = new SessionManager()
// N.B. This shouldn't be triggered because we should initialize the manager
// in the AIManager
SessionManager.instance = new SessionManager(null)
}

return SessionManager.instance
}

public static resetManager(statusBar: vscode.StatusBarItem) {
SessionManager.instance = new SessionManager(statusBar)
}

// getID returns the current session id
public getID(): string {
return this.sessionID
Expand All @@ -57,6 +66,10 @@ export class SessionManager {
openEvent.type = LogEventType.SESSION_START
openEvent.contextId = this.sessionID

if (this.statusBar !== null) {
this.statusBar.text = `Session: ${this.sessionID}`
}

getEventReporter().reportEvents([closeEvent, openEvent])
return this.sessionID
}
Expand Down