Skip to content

Commit

Permalink
fix: remove sparkle from context list without enhanced context (#3006)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeatrix committed Feb 2, 2024
1 parent 295a6e9 commit 119bed2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/ui/src/chat/TranscriptItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const TranscriptItem: React.FunctionComponent<
// TODO (bee) can be removed once we support editing command prompts.
// A boolean indicating whether the current message is a known command input.
const isCommandInput =
message?.displayText?.startsWith('/') || isDefaultCommandPrompts(message?.displayText || '')
message?.displayText?.startsWith('/') || isDefaultCommandPrompts(message?.displayText)

return (
<div
Expand Down Expand Up @@ -183,6 +183,7 @@ export const TranscriptItem: React.FunctionComponent<
contextFiles={message.contextFiles}
fileLinkComponent={fileLinkComponent}
className={transcriptActionClassName}
isCommand={isCommandInput}
/>
) : (
inProgress && <LoadingContext />
Expand Down Expand Up @@ -219,6 +220,9 @@ const commandPrompts = {
smell: `Please review and analyze the selected code and identify potential areas for improvement related to code smells, readability, maintainability, performance, security, etc. Do not list issues already addressed in the given code. Focus on providing up to 5 constructive suggestions that could make the code more robust, efficient, or align with best practices. For each suggestion, provide a brief explanation of the potential benefits. After listing any recommendations, summarize if you found notable opportunities to enhance the code quality overall or if the code generally follows sound design principles. If no issues found, reply 'There are no errors'`,
}

export function isDefaultCommandPrompts(text: string): boolean {
export function isDefaultCommandPrompts(text?: string): boolean {
if (!text) {
return false
}
return Object.values(commandPrompts).includes(text)
}
17 changes: 15 additions & 2 deletions lib/ui/src/chat/components/EnhancedContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ export const EnhancedContext: React.FunctionComponent<{
contextFiles: ContextFile[]
fileLinkComponent: React.FunctionComponent<FileLinkProps>
className?: string
}> = React.memo(function ContextFilesContent({ contextFiles, fileLinkComponent: FileLink, className }) {
isCommand: boolean
}> = React.memo(function ContextFilesContent({
contextFiles,
fileLinkComponent: FileLink,
className,
isCommand,
}) {
if (!contextFiles.length) {
return
}
Expand All @@ -44,7 +50,14 @@ export const EnhancedContext: React.FunctionComponent<{
return
}

const prefix = '✨ Context: '
// Enhanced Context are context added by one of Cody's context fetchers.
// NOTE: sparkle should only be added to messages that use enhanced context.
// NOTE: Core chat commands (e.g. /explain and /smell) use local context only.
// Check if the filteredFiles only contain local context (non-enhanced context).
const localContextType = ['user', 'selection', 'terminal', 'editor']
const localContextOnly = filteredFiles.every(file => localContextType.includes(file.type))
const sparkle = localContextOnly || isCommand ? '' : '✨ '
const prefix = sparkle + 'Context: '
// It checks if file.range exists first before accessing start and end.
// If range doesn't exist, it adds 0 lines for that file.
const lineCount = filteredFiles.reduce(
Expand Down
3 changes: 3 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a
- Autocomplete: Add a new experimental fast-path mode for Cody community users that directly connections to our inference services. [pull/2927](https://github.com/sourcegraph/cody/pull/2927)
- Command: The `Generate Unit Tests` command now functions as an inline edit command. When executed, the new tests will be automatically appended to the test file. If no existing test file is found, a temporary one will be created. [pull/2959](https://github.com/sourcegraph/cody/pull/2959)
- [Internal] Command: Added new code lenses for generating additional unit tests. [pull/2959](https://github.com/sourcegraph/cody/pull/2959)

### Fixed

- Chat: Messages without enhanced context should not include the sparkle emoji in context list.

### Changed

- Autocomplete: Improved the new jaccard similarity retriever and context mixing experiments. [pull/2898](https://github.com/sourcegraph/cody/pull/2898)
Expand Down
8 changes: 5 additions & 3 deletions vscode/test/e2e/core-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ test('Explain Command & Smell Command & Chat from Command Menu', async ({ page,
// Check if the command shows the current file as context with the correct number of lines
// When no selection is made, we will try to create smart selection from the cursor position
// If there is no cursor position, we will use the visible content of the editor
await chatPanel.getByText('✨ Context: 12 lines from 1 file').click()
// NOTE: Core commands context should not start with ✨
await chatPanel.getByText('Context: 12 lines from 1 file').click()

// Check if assistant responsed
await expect(chatPanel.getByText('hello from the assistant')).toBeVisible()
Expand All @@ -44,7 +45,7 @@ test('Explain Command & Smell Command & Chat from Command Menu', async ({ page,
await page.getByText('<title>Hello Cody</title>').click()
await expect(page.getByText('Explain code')).toBeVisible()
await page.getByText('Explain code').click()
await chatPanel.getByText('Context: 9 lines from 1 file').click()
await chatPanel.getByText('Context: 9 lines from 1 file').click()
const disabledEditButtons = chatPanel.getByTitle('Cannot Edit Command').locator('i')
const editLastMessageButton = chatPanel.getByRole('button', { name: /^Edit Last Message / })
// Edit button should shows as disabled for all command messages.
Expand All @@ -56,7 +57,8 @@ test('Explain Command & Smell Command & Chat from Command Menu', async ({ page,
// Running a command again should reuse the current cursor position
await expect(page.getByText('Identify code smells')).toBeVisible()
await page.getByText('Identify code smells').click()
await chatPanel.getByText('✨ Context: 9 lines from 1 file').click()
await chatPanel.getByText('Context: 9 lines from 1 file').hover()
await chatPanel.getByText('Context: 9 lines from 1 file').click()
await expect(disabledEditButtons).toHaveCount(1)
await expect(editLastMessageButton).not.toBeVisible()

Expand Down

0 comments on commit 119bed2

Please sign in to comment.