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

feat: code smell command, display commands error in chat #602

Merged
merged 40 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
02cd6b9
add tab-to-complete
abeatrix Aug 8, 2023
4eacb3d
replace selection with SelectionOrEntireFile
abeatrix Aug 8, 2023
7b2633b
add interaction with error message on error
abeatrix Aug 8, 2023
523f86c
add preventDefault
abeatrix Aug 8, 2023
bcacfd3
add commands to walkthrough and update old ones
abeatrix Aug 8, 2023
b287c13
revert chat
abeatrix Aug 8, 2023
45100e8
add getActiveTextEditorSelectionOrVisibleContent
abeatrix Aug 8, 2023
16414a8
add getActiveTextEditorSelectionOrVisibleContent
abeatrix Aug 8, 2023
1191ff1
Add annoucement
abeatrix Aug 8, 2023
add8162
update Explain Code and custom prompt
abeatrix Aug 8, 2023
2f4eb8c
Merge branch 'main' into bee/commands-update
abeatrix Aug 8, 2023
28c9698
update error style, add telemetryService
abeatrix Aug 9, 2023
68964b5
feat: add code smell detection
abeatrix Aug 9, 2023
4a8cd77
enhance custom prompt creation, add slashCommand
abeatrix Aug 9, 2023
9091da5
navigation of command suggestions w/ arrow keys
abeatrix Aug 9, 2023
97b0a55
show error on non-existing / command, add logs
abeatrix Aug 9, 2023
b7f76a5
display file path w/ link & selection range
abeatrix Aug 9, 2023
ed19604
clean up CustomPrompt recipe
abeatrix Aug 9, 2023
66a1e32
fix file range formatting in prompts
abeatrix Aug 9, 2023
10a4b67
fix test
abeatrix Aug 9, 2023
dd38fbf
simplify promise handling in menus
abeatrix Aug 9, 2023
14be3bb
update error text
abeatrix Aug 9, 2023
15a5d25
update changelog
abeatrix Aug 9, 2023
1063253
Merge branch 'main' into bee/commands-update
abeatrix Aug 9, 2023
2f3681b
remove editorSelectionOrVisibleContent from agent
abeatrix Aug 10, 2023
0007f18
Merge branch 'bee/commands-update' of https://github.com/sourcegraph/…
abeatrix Aug 10, 2023
fab0c12
Apply suggestions from code review
abeatrix Aug 10, 2023
d42c501
Remove toJSON() and use path lib
abeatrix Aug 10, 2023
49edcd0
Merge branch 'main' into bee/commands-update
abeatrix Aug 10, 2023
90a923d
fix conflicts
abeatrix Aug 10, 2023
bf20c22
update smell code prompt, add util, use XML tags
abeatrix Aug 10, 2023
a0dd969
fix command names and inline chat selection
abeatrix Aug 10, 2023
eda1e2d
remove selection requirement for code smell
abeatrix Aug 10, 2023
c2160fc
Update lib/shared/src/chat/recipes/custom-prompt.ts
abeatrix Aug 10, 2023
2d2b3a1
Update lib/shared/src/chat/recipes/custom-prompt.ts
abeatrix Aug 10, 2023
ba6a9a6
refactor: simplify interaction and context utilities
abeatrix Aug 10, 2023
82f5b45
show error for command when no file is opened
abeatrix Aug 11, 2023
33b5aa5
update error message
abeatrix Aug 11, 2023
543aaad
fix: use InlineController for active selection
abeatrix Aug 11, 2023
f620408
update editor classes
abeatrix Aug 11, 2023
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
34 changes: 24 additions & 10 deletions lib/shared/src/chat/recipes/custom-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ export class CustomPrompt implements Recipe {
? (JSON.parse(contextConfig) as CodyPromptContext)
: defaultCodyPromptContext

// Check if selection is required
const selection = context.editor.getActiveTextEditorSelection() || context.editor.controllers?.inline?.selection
if (isContextRequired?.selection && !selection?.selectedText) {
await vscode.window.showErrorMessage('This command requires text to be selected in the editor.')
return null
}

// Get prompt text from the editor command or from the human input
const promptText = humanChatInput.trim() || (await context.editor.controllers?.command?.get()) || null
if (!promptText) {
await vscode.window.showErrorMessage('Please enter a valid prompt for the custom command.')
return null
const errorMsg = 'Please enter a valid prompt for the custom command.'
return this.getInteractionWithAssistantError(errorMsg)
}
const promptName = await context.editor.controllers?.command?.get('current')
const displayPromptText = promptName ? `Command: ${promptName}` : promptText

// Check if selection is required
const selection =
context.editor.getActiveTextEditorSelectionOrEntireFile() || context.editor.controllers?.inline?.selection
if ((isContextRequired?.selection || isContextRequired?.currentFile) && !selection?.selectedText) {
const errorMsg = 'This command requires text to be selected in the editor.'
return this.getInteractionWithAssistantError(errorMsg, displayPromptText)
}

// Get output from the command if any
const commandOutput = await context.editor.controllers?.command?.get('output')

Expand Down Expand Up @@ -103,6 +104,17 @@ export class CustomPrompt implements Recipe {
)
}

private async getInteractionWithAssistantError(errorMsg: string, displayText = ''): Promise<Interaction> {
return Promise.resolve(
new Interaction(
{ speaker: 'human', displayText },
{ speaker: 'assistant', error: errorMsg },
Promise.resolve([]),
[]
)
)
}

// Get display text for human
private getHumanDisplayText(humanChatInput: string, fileName: string): string {
return humanChatInput + InlineTouch.displayPrompt + fileName
Expand Down Expand Up @@ -154,7 +166,9 @@ export class CustomPrompt implements Recipe {
}

const currentFileContextStack = []
if (isContextRequired.currentFile) {
// If currentFile is true, or when selection is true but there is no selected text
// then we want to include the current file context
if (isContextRequired.currentFile || (isContextRequired.selection && !selection?.selectedText)) {
currentFileContextStack.push(...ChatQuestion.getEditorContext(editor))
}

Expand Down
1 change: 1 addition & 0 deletions lib/shared/src/chat/transcript/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ChatMessage extends Message {
export interface InteractionMessage extends Message {
displayText?: string
prefix?: string
error?: string
}

export interface UserLocalHistory {
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
setSelectedChatCommand(-1)
setFormInput('')
}
if (event.key === 'Tab' && selectedChatCommand > -1) {
const newInput = displayCommands?.[selectedChatCommand]?.[1]?.slashCommand
setFormInput(newInput || formInput)
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Loop through input history on up arrow press
Expand Down
8 changes: 8 additions & 0 deletions vscode/src/chat/MessageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
if (!interaction) {
return
}
const errorMsg = interaction?.getAssistantMessage()?.error
if (errorMsg !== undefined) {
this.transcript.addInteraction(interaction)
this.transcript.addErrorAsAssistantResponse(errorMsg)
this.sendTranscript()
await this.saveTranscriptToChatHistory()
return
}
this.isMessageInProgress = true
this.transcript.addInteraction(interaction)

Expand Down
Loading