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

Feature/20250226-SplitCommands #326

Merged
merged 7 commits into from
Feb 26, 2025
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node --target=es2020",
"esbuild": "yarn esbuild-base --sourcemap",
"esbuild-watch": "yarn esbuild-base -- --sourcemap --watch",
"test-compile": "tsc -p ./",
"compile": "tsc -p ./",
"deploy": "vsce publish --yarn",
"clean": "node ./utilities/scripts/clean.js"
},
Expand Down
5 changes: 5 additions & 0 deletions src/commands/ICommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ICommand {
readonly id: string

execute(...args: any[]): void | Promise<void>
}
9 changes: 2 additions & 7 deletions src/commands/commandManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { commands, Disposable } from 'vscode'

export interface Command {
readonly id: string

execute(...args: any[]): void
}
import { ICommand } from '@app/commands'

export class CommandManager {
private readonly _commands = new Map<string, Disposable>()
Expand All @@ -16,7 +11,7 @@ export class CommandManager {
this._commands.clear()
}

public register<T extends Command>(command: T): Disposable {
public register<T extends ICommand>(command: T): Disposable {
this._registerCommand(command.id, command.execute, command)
return new Disposable(() => {
this._commands.delete(command.id)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/configuration/showQuickpick.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ExtensionContext } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { ConfigurationQuickPickProvider } from '@app/providers'

export default class SettingsCommand implements Command {
export default class SettingsCommand implements ICommand {
public readonly id = 'vscode-openai.configuration.show.quickpick'
private _configurationQuickPick: ConfigurationQuickPickProvider
public constructor(context: ExtensionContext) {
this._configurationQuickPick =
ConfigurationQuickPickProvider.getInstance(context)
}

public async execute(): Promise<void> {
await this._configurationQuickPick.execute()
public async execute() {
this._configurationQuickPick.execute()
}
}
4 changes: 2 additions & 2 deletions src/commands/conversation/copyClipboardSummary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { env } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { showMessageWithTimeout } from '@app/apis/vscode'
import { IConversation } from '@app/interfaces'

export default class ClipboardCopyConversationSummaryCommand
implements Command
implements ICommand
{
public readonly id = '_vscode-openai.conversation.clipboard-copy.summary'

Expand Down
4 changes: 2 additions & 2 deletions src/commands/conversation/delete.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { window } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'
import { ConversationStorageService } from '@app/services'

export default class DeleteConversationCommand implements Command {
export default class DeleteConversationCommand implements ICommand {
public readonly id = '_vscode-openai.conversation.delete'

public execute(args: { data: IConversation }) {
Expand Down
8 changes: 4 additions & 4 deletions src/commands/conversation/newPersona.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ExtensionContext } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { quickPickCreateConversation } from '@app/utilities/quickPicks'

export default class NewConversationPersonaCommand implements Command {
export default class NewConversationPersonaCommand implements ICommand {
public readonly id = 'vscode-openai.conversation.new.persona'
public constructor(private _context: ExtensionContext) {}

public async execute(): Promise<void> {
await quickPickCreateConversation(this._context)
public async execute() {
quickPickCreateConversation(this._context)
}
}
6 changes: 3 additions & 3 deletions src/commands/conversation/newStandard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'
import { getSystemPersonas } from '@app/models'
import { ConversationStorageService } from '@app/services'
import { VSCODE_OPENAI_QP_PERSONA } from '@app/constants'

export default class NewConversationStandardCommand implements Command {
export default class NewConversationStandardCommand implements ICommand {
public readonly id = 'vscode-openai.conversation.new.standard'

public async execute(): Promise<void> {
public async execute() {
const persona = getSystemPersonas().find(
(a) => a.roleName === VSCODE_OPENAI_QP_PERSONA.GENERAL
)!
Expand Down
4 changes: 2 additions & 2 deletions src/commands/conversation/openJson.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ViewColumn, window, workspace } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'

export default class ShowConversationJsonCommand implements Command {
export default class ShowConversationJsonCommand implements ICommand {
public readonly id = '_vscode-openai.conversation.show.json'

public execute(args: { data: IConversation }) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/conversation/openMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ViewColumn, window, workspace } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'

export default class ShowConversationMarkdownCommand implements Command {
export default class ShowConversationMarkdownCommand implements ICommand {
public readonly id = '_vscode-openai.conversation.show.markdown'

public execute(args: { data: IConversation }) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/conversation/openWebview.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'
import { ConversationStorageService } from '@app/services'

export default class OpenConversationWebviewCommand implements Command {
export default class OpenConversationWebviewCommand implements ICommand {
public readonly id = '_vscode-openai.conversation.open.webview'

public execute(args: { data: IConversation }) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/conversations/deleteAll.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { window } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { ConversationStorageService } from '@app/services'

export default class DeleteAllConversationsCommand implements Command {
export default class DeleteAllConversationsCommand implements ICommand {
public readonly id = '_vscode-openai.conversations.delete-all'

public async execute(): Promise<void> {
public async execute() {
window
.showInformationMessage(
'Are you sure you want to delete ALL conversation?',
Expand Down
6 changes: 3 additions & 3 deletions src/commands/conversations/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { ConversationStorageService } from '@app/services'

export default class RefreshConversationsCommand implements Command {
export default class RefreshConversationsCommand implements ICommand {
public readonly id = '_vscode-openai.conversations.refresh'

public async execute(): Promise<void> {
public async execute() {
ConversationStorageService.instance.refresh()
}
}
6 changes: 3 additions & 3 deletions src/commands/conversations/settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { commands } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'

export default class SettingsConversationsCommand implements Command {
export default class SettingsConversationsCommand implements ICommand {
public readonly id = '_vscode-openai.conversations.settings'

public async execute(): Promise<void> {
public async execute() {
commands.executeCommand(
'workbench.action.openSettings',
'vscode-openai.conversation-configuration'
Expand Down
6 changes: 3 additions & 3 deletions src/commands/editor/codeBounty.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { getSystemPersonas } from '@app/models'
import {
compareResultsToClipboard,
getEditorPrompt,
} from '@app/utilities/editor'
import { VSCODE_OPENAI_QP_PERSONA } from '@app/constants'

export default class CodeBountyCommand implements Command {
export default class CodeBountyCommand implements ICommand {
public readonly id = '_vscode-openai.editor.code.bounty'

public async execute(): Promise<void> {
public async execute() {
const prompt = await getEditorPrompt('editor.code.bounty')
const persona = getSystemPersonas().find(
(a) => a.roleName === VSCODE_OPENAI_QP_PERSONA.DEVELOPER
Expand Down
8 changes: 4 additions & 4 deletions src/commands/editor/codeComment.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { getSystemPersonas } from '@app/models'
import {
compareResultsToClipboard,
getEditorPrompt,
} from '@app/utilities/editor'
import { VSCODE_OPENAI_QP_PERSONA } from '@app/constants'

export default class CodeCommentCommand implements Command {
export default class CodeCommentCommand implements ICommand {
public readonly id = '_vscode-openai.editor.code.comment'

public async execute(): Promise<void> {
public async execute() {
const prompt = await getEditorPrompt('editor.code.comment')
const persona = getSystemPersonas().find(
(a) => a.roleName === VSCODE_OPENAI_QP_PERSONA.DEVELOPER
)
await compareResultsToClipboard(persona, prompt)
compareResultsToClipboard(persona, prompt)
}
}
8 changes: 4 additions & 4 deletions src/commands/editor/codeExplain.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { getSystemPersonas } from '@app/models'
import {
compareResultsToClipboard,
getEditorPrompt,
} from '@app/utilities/editor'
import { VSCODE_OPENAI_QP_PERSONA } from '@app/constants'

export default class CodeExplainCommand implements Command {
export default class CodeExplainCommand implements ICommand {
public readonly id = '_vscode-openai.editor.code.explain'

public async execute(): Promise<void> {
public async execute() {
const prompt = await getEditorPrompt('editor.code.explain')
const persona = getSystemPersonas().find(
(a) => a.roleName === VSCODE_OPENAI_QP_PERSONA.DEVELOPER
)
await compareResultsToClipboard(persona, prompt)
compareResultsToClipboard(persona, prompt)
}
}
8 changes: 4 additions & 4 deletions src/commands/editor/codeOptimize.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { getSystemPersonas } from '@app/models'
import {
compareResultsToClipboard,
getEditorPrompt,
} from '@app/utilities/editor'
import { VSCODE_OPENAI_QP_PERSONA } from '@app/constants'

export default class CodeOptimizeCommand implements Command {
export default class CodeOptimizeCommand implements ICommand {
public readonly id = '_vscode-openai.editor.code.optimize'

public async execute(): Promise<void> {
public async execute() {
const prompt = await getEditorPrompt('editor.code.optimize')
const persona = getSystemPersonas().find(
(a) => a.roleName === VSCODE_OPENAI_QP_PERSONA.DEVELOPER
)
await compareResultsToClipboard(persona, prompt)
compareResultsToClipboard(persona, prompt)
}
}
8 changes: 4 additions & 4 deletions src/commands/editor/codePatterns.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { getSystemPersonas } from '@app/models'
import {
compareResultsToClipboard,
getEditorPrompt,
} from '@app/utilities/editor'
import { VSCODE_OPENAI_QP_PERSONA } from '@app/constants'

export default class CodePatternsCommand implements Command {
export default class CodePatternsCommand implements ICommand {
public readonly id = '_vscode-openai.editor.code.pattern'

public async execute(): Promise<void> {
public async execute() {
const prompt = await getEditorPrompt('editor.code.pattern')
const persona = getSystemPersonas().find(
(a) => a.roleName === VSCODE_OPENAI_QP_PERSONA.DEVELOPER
)
await compareResultsToClipboard(persona, prompt)
compareResultsToClipboard(persona, prompt)
}
}
8 changes: 4 additions & 4 deletions src/commands/editor/settings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { commands } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'

export default class SettingsCommand implements Command {
export default class SettingsCommand implements ICommand {
public readonly id = '_vscode-openai.editor.settings'

public async execute(): Promise<void> {
await commands.executeCommand(
public async execute() {
commands.executeCommand(
'workbench.action.openSettings',
'vscode-openai.editor.code'
)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/embeddings/delete.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { window } from 'vscode'
import { EmbeddingTreeDataProvider, EmbeddingTreeItem } from '@app/providers'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { EmbeddingStorageService } from '@app/services'

export default class RefreshCommand implements Command {
export default class RefreshCommand implements ICommand {
public readonly id = '_vscode-openai.embeddings.delete.resource'
public constructor(private _instance: EmbeddingTreeDataProvider) {}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/embeddings/newConversationEmbedding.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'
import { ConversationStorageService } from '@app/services'
import { EmbeddingTreeItem } from '@app/providers'
import { getQueryResourcePersona } from '@app/models'

export default class NewConversationEmbeddingCommand implements Command {
export default class NewConversationEmbeddingCommand implements ICommand {
public readonly id = 'vscode-openai.embeddings.new.conversation'

public async execute(node: EmbeddingTreeItem) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/embeddings/newConversationEmbeddingAll.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { IConversation } from '@app/interfaces'
import { ConversationStorageService } from '@app/services'
import { getQueryResourcePersona } from '@app/models'
import { VSCODE_OPENAI_EMBEDDING } from '@app/constants'

export default class NewConversationEmbeddingAllCommand implements Command {
export default class NewConversationEmbeddingAllCommand implements ICommand {
public readonly id = 'vscode-openai.embeddings.new.conversation-all'

public async execute(): Promise<void> {
public async execute() {
const persona = getQueryResourcePersona()
const conversation: IConversation =
await ConversationStorageService.instance.create(
Expand Down
6 changes: 3 additions & 3 deletions src/commands/embeddings/newEmbeddingFile.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { OpenDialogOptions, window } from 'vscode'
import { Command } from '@app/commands'
import { ICommand } from '@app/commands'
import { EmbeddingStorageService } from '@app/services'
import {
createDebugNotification,
createErrorNotification,
} from '@app/apis/node'
import { embeddingResource } from '@app/apis/embedding'

export default class NewEmbeddingFileCommand implements Command {
export default class NewEmbeddingFileCommand implements ICommand {
public readonly id = '_vscode-openai.embeddings.new.file'

public async execute(): Promise<void> {
public async execute() {
// Define the options for the open dialog
const options: OpenDialogOptions = {
canSelectMany: true,
Expand Down
Loading
Loading