Skip to content

Commit

Permalink
feat: add custom session/icon state, add reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Dec 5, 2024
1 parent e0e292b commit 99b59be
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 12 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@
"command": "flexpilot.status.icon.menu",
"enablement": "false",
"title": "Status Icon Menu"
},
{
"command": "flexpilot.reload",
"enablement": "false",
"title": "Read storage changes"
}
],
"icons": {
Expand Down Expand Up @@ -361,11 +366,12 @@
"chatParticipantPrivate",
"chatProvider",
"chatVariableResolver",
"contribSourceControlInputBoxMenu",
"defaultChatParticipant",
"terminalExecuteCommandEvent",
"terminalSelection"
],
"engines": {
"vscode": "1.95.x"
}
}
}
26 changes: 26 additions & 0 deletions src/commands/reload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as vscode from "vscode";
import { events } from "../events";
import InlineChatParticipant from "../inline-chat";
import { logger } from "../logger";
import PanelChatParticipant from "../panel-chat";
import { storage } from "../storage";

export class ReloadCommand {
static register() {
storage.getContext().subscriptions.push(
vscode.commands.registerCommand("flexpilot.reload", () => {
InlineChatParticipant.reload();
PanelChatParticipant.reload();
events.fire({
name: "inlineCompletionProviderUpdated",
payload: { updatedAt: Date.now() },
});
events.fire({
name: "modelProvidersUpdated",
payload: { updatedAt: Date.now() },
});
}),
);
logger.info("ReloadCommand registered");
}
}
16 changes: 12 additions & 4 deletions src/inline-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { getEol } from "./utilities";
class InlineChatParticipant {
private static instance: InlineChatParticipant | null = null;
private readonly chatParticipant: vscode.ChatParticipant;
// private readonly githubSession: vscode.AuthenticationSession;
private readonly session: vscode.AuthenticationSession;
private readonly icon: vscode.Uri | undefined;

/**
* Private constructor to prevent direct instantiation.
Expand All @@ -27,12 +28,14 @@ class InlineChatParticipant {
this.handleChatRequest.bind(this),
);

// Get the GitHub session
// this.githubSession = storage.session.get();
// Get the Custom session
this.session = storage.customSession.get() || storage.session.get();
this.icon = storage.customSession.icon();

// Set up requester information
this.chatParticipant.requester = {
name: "anonymous",
name: this.session.account.label,
icon: this.icon,
};

// Set chat participant icon
Expand Down Expand Up @@ -60,6 +63,11 @@ class InlineChatParticipant {
}
}

public static reload() {
InlineChatParticipant.dispose();
InlineChatParticipant.register();
}

/**
* Handles the chat request and generates a response.
* @param {vscode.ChatRequest} request - The chat request.
Expand Down
2 changes: 2 additions & 0 deletions src/lazy-load.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommitMessageCommand } from "./commands/commit-message";
import { ConfigureModelCommand } from "./commands/configure-model";
import { ReloadCommand } from "./commands/reload";
import { StatusIconMenuCommand } from "./commands/status-icon-menu";
import { events } from "./events";
import { logger } from "./logger";
Expand Down Expand Up @@ -31,6 +32,7 @@ export const activate = async () => {
StatusIconMenuCommand.register();
CommitMessageCommand.register();
ConfigureModelCommand.register();
ReloadCommand.register();

// Handle the session change
SessionManager.register();
Expand Down
19 changes: 12 additions & 7 deletions src/panel-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ import { VariablesManager } from "./variables";
class PanelChatParticipant {
private static instance: PanelChatParticipant | null = null;
private readonly chatParticipant: vscode.ChatParticipant;
// private readonly githubSession: vscode.AuthenticationSession;
private readonly session: vscode.AuthenticationSession;
private readonly icon: vscode.Uri | undefined;

/**
* Private constructor to prevent direct instantiation.
* Initializes the chat participant with necessary providers and configurations.
*/
private constructor() {
// Get the GitHub session
// this.githubSession = storage.session.get();
// Get the custom session
this.session = storage.customSession.get() || storage.session.get();
this.icon = storage.customSession.icon();

// Create the chat participant
this.chatParticipant = vscode.chat.createChatParticipant(
Expand Down Expand Up @@ -63,10 +65,8 @@ class PanelChatParticipant {

// Set up requester information
this.chatParticipant.requester = {
name: "anonymous",
// icon: vscode.Uri.parse(
// `https://avatars.githubusercontent.com/u/${this.githubSession.account.id}`,
// ),
name: this.session.account.label,
icon: this.icon,
};

// Set up help text variables prefix
Expand Down Expand Up @@ -95,6 +95,11 @@ class PanelChatParticipant {
}
}

public static reload() {
PanelChatParticipant.dispose();
PanelChatParticipant.register();
}

/**
* Handles the chat request and generates a response.
* @param {vscode.ChatRequest} request - The chat request.
Expand Down
21 changes: 21 additions & 0 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ class StorageManager {
},
};

/**
* Custom session info instead of GitHub.
*/
public customSession = {
get: (): vscode.AuthenticationSession | undefined => {
if (!this.context) {
throw new Error("Storage manager not initialized");
}
return this.context.globalState.get("customSession");
},
icon: (): vscode.Uri | undefined => {
if (!this.context) {
throw new Error("Storage manager not initialized");
}
const url = this.context.globalState.get("customIcon");
if (url) {
return vscode.Uri.parse(url as string);
}
},
};

public models = {
/**
* Retrieves a value from model providers.
Expand Down

0 comments on commit 99b59be

Please sign in to comment.