Skip to content

Commit

Permalink
remove user-newchat and submitType entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
sqs committed Oct 3, 2024
1 parent aa2f79b commit d95e593
Show file tree
Hide file tree
Showing 19 changed files with 9 additions and 47 deletions.
1 change: 0 additions & 1 deletion agent/src/TestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ export class TestClient extends MessageHandler {
message: {
command: 'submit',
text,
submitType: 'user-newchat',
contextItems: params?.contextFiles,
},
})
Expand Down
12 changes: 5 additions & 7 deletions agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import * as uuid from 'uuid'
import type { MessageConnection } from 'vscode-jsonrpc'
import type { CommandResult } from '../../vscode/src/CommandResult'
import { formatURL } from '../../vscode/src/auth/auth'
import { executeExplainCommand, executeSmellCommand } from '../../vscode/src/commands/execute'
import type { CodyCommandArgs } from '../../vscode/src/commands/types'
import { loadTscRetriever } from '../../vscode/src/completions/context/retrievers/tsc/load-tsc-retriever'
import { supportedTscLanguages } from '../../vscode/src/completions/context/retrievers/tsc/supportedTscLanguages'
import type { CompletionItemID } from '../../vscode/src/completions/logger'
Expand Down Expand Up @@ -1082,12 +1084,10 @@ export class Agent extends MessageHandler implements ExtensionClient {
})

// The arguments to pass to the command to make sure edit commands would also run in chat mode
const commandArgs = [{ source: 'editor' }]
const commandArgs: Partial<CodyCommandArgs> = { source: 'editor' }

this.registerAuthenticatedRequest('commands/explain', () => {
return this.createChatPanel(
vscode.commands.executeCommand('cody.command.explain-code', commandArgs)
)
return this.createChatPanel(executeExplainCommand(commandArgs))
})

this.registerAuthenticatedRequest('editTask/accept', async ({ id }) => {
Expand Down Expand Up @@ -1179,9 +1179,7 @@ export class Agent extends MessageHandler implements ExtensionClient {
})

this.registerAuthenticatedRequest('commands/smell', () => {
return this.createChatPanel(
vscode.commands.executeCommand('cody.command.smell-code', commandArgs)
)
return this.createChatPanel(executeSmellCommand(commandArgs))
})

this.registerAuthenticatedRequest('commands/custom', ({ key }) => {
Expand Down
1 change: 0 additions & 1 deletion agent/src/cli/command-bench/strategy-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function evaluateChatStrategy(
id,
message: {
command: 'submit',
submitType: 'user-newchat',
text: task.question,
contextItems,
},
Expand Down
1 change: 0 additions & 1 deletion agent/src/cli/command-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export async function chatAction(options: ChatOptions): Promise<number> {
id,
message: {
command: 'submit',
submitType: 'user-newchat',
text: messageText,
contextItems,
},
Expand Down
4 changes: 0 additions & 4 deletions agent/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'My name is Lars Monsen.',
submitType: 'user-newchat',
},
})
)
Expand All @@ -282,7 +281,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'What is my name?',
submitType: 'user-newchat',
},
})
)
Expand Down Expand Up @@ -313,7 +311,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'What model are you?',
submitType: 'user-newchat',
},
})
)
Expand All @@ -330,7 +327,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'What model are you?',
submitType: 'user-newchat',
},
})
)
Expand Down
9 changes: 0 additions & 9 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
public async handleUserMessageSubmission({
requestID,
inputText,
isEdit,
mentions,
editorState,
signal,
Expand All @@ -595,7 +594,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
}: {
requestID: string
inputText: PromptString
isEdit?: boolean
mentions: ContextItem[]
editorState: SerializedPromptEditorState | null
signal: AbortSignal
Expand Down Expand Up @@ -649,12 +647,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
return this.clearAndRestartSession()
}

if (!isEdit && !this.chatBuilder.isEmpty()) {
span.addEvent('clearAndRestartSession')
await this.clearAndRestartSession()
signal.throwIfAborted()
}

this.chatBuilder.addHumanMessage({
text: inputText,
editorState,
Expand Down Expand Up @@ -970,7 +962,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
return await this.handleUserMessageSubmission({
requestID,
inputText: text,
isEdit: true,
mentions: contextFiles,
editorState,
signal: abortSignal,
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/chat/chat-view/ChatsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,18 @@ export class ChatsController implements vscode.Disposable {
*/
private async submitChat({
text,
submitType,
contextItems,
source = DEFAULT_EVENT_SOURCE,
command,
}: ExecuteChatArguments): Promise<ChatSession | undefined> {
let provider: ChatController
// If the sidebar panel is visible and empty, use it instead of creating a new panel
if (submitType === 'user-newchat' && this.panel.isVisible() && this.panel.isEmpty()) {
if (this.panel.isVisible() && this.panel.isEmpty()) {
provider = this.panel
} else {
provider = await this.getOrCreateEditorChatController()
}
await provider.clearAndRestartSession()
const abortSignal = provider.startNewSubmitOrEditOperation()
const editorState = editorStateFromPromptString(text)
await provider.handleUserMessageSubmission({
Expand Down
8 changes: 0 additions & 8 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,8 @@ interface ExtensionAttributionMessage {
error?: string | undefined | null
}

/**
* ChatSubmitType represents the type of chat submission.
* - 'user': The user starts a new chat panel.
* - 'user-newchat': The user reuses the current chat panel.
*/
export type ChatSubmitType = 'user' | 'user-newchat'

export interface WebviewSubmitMessage extends WebviewContextMessage {
text: string
submitType: Extract<ChatSubmitType, 'user-newchat'>

/** An opaque value representing the text editor's state. @see {ChatMessage.editorState} */
editorState?: unknown | undefined | null
Expand Down
1 change: 0 additions & 1 deletion vscode/src/code-actions/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class ExplainCodeAction implements vscode.CodeActionProvider {
{
text: instruction,
source: 'code-action:explain',
submitType: 'user-newchat',
} satisfies ExecuteChatArguments,
],
title: 'Ask Cody to Explain',
Expand Down
6 changes: 2 additions & 4 deletions vscode/src/commands/execute/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import {
} from '@sourcegraph/cody-shared'
import * as vscode from 'vscode'
import type { ChatSession } from '../../chat/chat-view/ChatController'
import type { ChatSubmitType, WebviewSubmitMessage } from '../../chat/protocol'
import type { WebviewSubmitMessage } from '../../chat/protocol'
import { isUriIgnoredByContextFilterWithNotification } from '../../cody-ignore/context-filter'
import { getEditor } from '../../editor/active-editor'

export interface ExecuteChatArguments
extends Omit<WebviewSubmitMessage, 'text' | 'editorState' | 'submitType'> {
export interface ExecuteChatArguments extends Omit<WebviewSubmitMessage, 'text' | 'editorState'> {
source?: EventSource
command?: DefaultChatCommands
text: PromptString
submitType: Extract<ChatSubmitType, 'user-newchat'>
}

/**
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ async function docChatCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
command: DefaultChatCommands.Doc,
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/explain-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ async function explainHistoryCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
}
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export async function explainCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
command: DefaultChatCommands.Explain,
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/smell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ async function smellCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
command: DefaultChatCommands.Smell,
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export async function executeExplainOutput(
type: 'chat',
session: await executeChat({
text: prompt,
submitType: 'user-newchat',
contextItems: [],
source,
}),
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/test-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async function unitTestCommand(
text: prompt,
contextItems,
source: args?.source,
submitType: 'user-newchat',
command: DefaultChatCommands.Test,
}
}
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/menus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export async function showCommandMenu(
} else {
void executeChat({
text: value.trim(),
submitType: 'user-newchat',
source,
})
}
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/services/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class CommandRunner implements vscode.Disposable {
type: 'chat',
session: await executeChat({
text: prompt,
submitType: 'user-newchat',
contextItems,
source: 'custom-commands',
command: DefaultChatCommands.Custom,
Expand Down
1 change: 0 additions & 1 deletion vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ function submitHumanMessage({
}): void {
getVSCodeAPI().postMessage({
command: 'submit',
submitType: 'user-newchat',
text: editorValue.text,
editorState: editorValue.editorState,
contextItems: editorValue.contextItems.map(deserializeContextItem),
Expand Down

0 comments on commit d95e593

Please sign in to comment.