Skip to content

Commit

Permalink
feat(ui): optimize entire file context in sidepanel display
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Dec 20, 2024
1 parent 4184a0e commit de6633a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions clients/tabby-chat-panel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface FileContext {
filepath: string
content: string
git_url: string
is_entire_file: boolean
}

export type Context = FileContext
Expand Down
8 changes: 5 additions & 3 deletions clients/vscode/src/chat/fileContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function getFileContext(
range,
filepath: filePathParams.filePath,
git_url: filePathParams.gitRemoteUrl ?? "",
is_entire_file: !useSelection
};
}

Expand Down Expand Up @@ -74,9 +75,10 @@ export async function showFileContext(fileContext: FileContext, gitProvider: Git
preserveFocus: true,
});

// Move the cursor to the specified line
const start = new Position(Math.max(0, fileContext.range.start - 1), 0);
const end = new Position(fileContext.range.end, 0);

// move the cursor to the specified line
const start = fileContext.is_entire_file ? new Position(0, 0) : new Position(Math.max(0, fileContext.range.start - 1), 0);
const end = fileContext.is_entire_file ? new Position(0, 0) : new Position(fileContext.range.end, 0);
editor.selection = new Selection(start, end);
editor.revealRange(new Range(start, end), TextEditorRevealType.InCenter);
}
Expand Down
7 changes: 5 additions & 2 deletions ee/tabby-ui/app/files/components/chat-side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const ChatSideBar: React.FC<ChatSideBarProps> = ({
const repoMapRef = useLatest(repoMap)
const onNavigate = async (context: Context) => {
if (context?.filepath && context?.git_url) {
const lineHash = formatLineHashForCodeBrowser(context?.range)
const lineHash = context.is_entire_file
? undefined
: formatLineHashForCodeBrowser(context?.range)
const repoMap = repoMapRef.current
const matchedRepositoryKey = find(
Object.keys(repoMap),
Expand Down Expand Up @@ -127,7 +129,8 @@ export const ChatSideBar: React.FC<ChatSideBarProps> = ({
end: lineTo ?? lineFrom
},
filepath: path,
git_url: gitUrl
git_url: gitUrl,
is_entire_file: false
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export function AssistantMessageSection({
},
filepath: code.filepath || '',
content: code.content,
git_url: relevantCodeGitURL
git_url: relevantCodeGitURL,
is_entire_file: false
}
}) ?? []
)
Expand All @@ -185,7 +186,8 @@ export function AssistantMessageSection({
git_url: code.gitUrl,
extra: {
scores: code?.extra?.scores
}
},
is_entire_file: false
}
}) ?? []
)
Expand Down
4 changes: 3 additions & 1 deletion ee/tabby-ui/components/chat/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ function ContextLabel({
return (
<span className={cn('truncate', className)}>
{fileName}
<span className="text-muted-foreground">{line}</span>
{!context.is_entire_file && (
<span className="text-muted-foreground">{line}</span>
)}
</span>
)
}
22 changes: 13 additions & 9 deletions ee/tabby-ui/components/chat/code-references.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,19 @@ function ContextItem({
<IconFile className="shrink-0" />
<div className="flex-1 truncate" title={context.filepath}>
<span>{fileName}</span>
{context.range?.start && (
<span className="text-muted-foreground">
:{context.range.start}
</span>
)}
{isMultiLine && (
<span className="text-muted-foreground">
-{context.range.end}
</span>
{!context.is_entire_file && (
<>
{context.range?.start && (
<span className="text-muted-foreground">
:{context.range.start}
</span>
)}
{isMultiLine && (
<span className="text-muted-foreground">
-{context.range.end}
</span>
)}
</>
)}
<span className="ml-2 text-xs text-muted-foreground">{path}</span>
</div>
Expand Down
8 changes: 6 additions & 2 deletions ee/tabby-ui/components/chat/question-answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ function AssistantMessageCard(props: AssistantMessageCardProps) {
},
filepath: code.filepath,
content: code.content,
git_url: code.gitUrl
git_url: code.gitUrl,
// FIXME(@jueliang) relevant code should include `is_entire_file`?
is_entire_file: false
}
}) ?? []
)
Expand Down Expand Up @@ -344,7 +346,9 @@ function AssistantMessageCard(props: AssistantMessageCardProps) {
range: {
start: startLine,
end: endLine
}
},
// FIXME(@jueliang) relevant code should include `is_entire_file`?
is_entire_file: false
}
onNavigateToContext?.(ctx, {
openInEditor: code.isClient
Expand Down

0 comments on commit de6633a

Please sign in to comment.