From de6633aa0f8c87e5b1b5d491d282191a9a693e9e Mon Sep 17 00:00:00 2001 From: liangfung Date: Fri, 20 Dec 2024 19:07:46 +0700 Subject: [PATCH] feat(ui): optimize entire file context in sidepanel display --- clients/tabby-chat-panel/src/index.ts | 1 + clients/vscode/src/chat/fileContext.ts | 8 ++++--- .../app/files/components/chat-side-bar.tsx | 7 ++++-- .../components/assistant-message-section.tsx | 6 +++-- ee/tabby-ui/components/chat/chat-panel.tsx | 4 +++- .../components/chat/code-references.tsx | 22 +++++++++++-------- .../components/chat/question-answer.tsx | 8 +++++-- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/clients/tabby-chat-panel/src/index.ts b/clients/tabby-chat-panel/src/index.ts index 08f419e295f7..2b7462226ab0 100644 --- a/clients/tabby-chat-panel/src/index.ts +++ b/clients/tabby-chat-panel/src/index.ts @@ -57,6 +57,7 @@ export interface FileContext { filepath: string content: string git_url: string + is_entire_file: boolean } export type Context = FileContext diff --git a/clients/vscode/src/chat/fileContext.ts b/clients/vscode/src/chat/fileContext.ts index 8cf6dbb50fce..3af5304f728a 100644 --- a/clients/vscode/src/chat/fileContext.ts +++ b/clients/vscode/src/chat/fileContext.ts @@ -47,6 +47,7 @@ export async function getFileContext( range, filepath: filePathParams.filePath, git_url: filePathParams.gitRemoteUrl ?? "", + is_entire_file: !useSelection }; } @@ -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); } diff --git a/ee/tabby-ui/app/files/components/chat-side-bar.tsx b/ee/tabby-ui/app/files/components/chat-side-bar.tsx index f8f673dfae95..d901b2189f5e 100644 --- a/ee/tabby-ui/app/files/components/chat-side-bar.tsx +++ b/ee/tabby-ui/app/files/components/chat-side-bar.tsx @@ -30,7 +30,9 @@ export const ChatSideBar: React.FC = ({ 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), @@ -127,7 +129,8 @@ export const ChatSideBar: React.FC = ({ end: lineTo ?? lineFrom }, filepath: path, - git_url: gitUrl + git_url: gitUrl, + is_entire_file: false } }) } diff --git a/ee/tabby-ui/app/search/components/assistant-message-section.tsx b/ee/tabby-ui/app/search/components/assistant-message-section.tsx index d4af5ab3a092..d9efe3040c8e 100644 --- a/ee/tabby-ui/app/search/components/assistant-message-section.tsx +++ b/ee/tabby-ui/app/search/components/assistant-message-section.tsx @@ -163,7 +163,8 @@ export function AssistantMessageSection({ }, filepath: code.filepath || '', content: code.content, - git_url: relevantCodeGitURL + git_url: relevantCodeGitURL, + is_entire_file: false } }) ?? [] ) @@ -185,7 +186,8 @@ export function AssistantMessageSection({ git_url: code.gitUrl, extra: { scores: code?.extra?.scores - } + }, + is_entire_file: false } }) ?? [] ) diff --git a/ee/tabby-ui/components/chat/chat-panel.tsx b/ee/tabby-ui/components/chat/chat-panel.tsx index 92d5a7746e7e..5ae0a2573866 100644 --- a/ee/tabby-ui/components/chat/chat-panel.tsx +++ b/ee/tabby-ui/components/chat/chat-panel.tsx @@ -352,7 +352,9 @@ function ContextLabel({ return ( {fileName} - {line} + {!context.is_entire_file && ( + {line} + )} ) } diff --git a/ee/tabby-ui/components/chat/code-references.tsx b/ee/tabby-ui/components/chat/code-references.tsx index b9171f61b18e..e1ebc7b097a9 100644 --- a/ee/tabby-ui/components/chat/code-references.tsx +++ b/ee/tabby-ui/components/chat/code-references.tsx @@ -178,15 +178,19 @@ function ContextItem({
{fileName} - {context.range?.start && ( - - :{context.range.start} - - )} - {isMultiLine && ( - - -{context.range.end} - + {!context.is_entire_file && ( + <> + {context.range?.start && ( + + :{context.range.start} + + )} + {isMultiLine && ( + + -{context.range.end} + + )} + )} {path}
diff --git a/ee/tabby-ui/components/chat/question-answer.tsx b/ee/tabby-ui/components/chat/question-answer.tsx index f9dd02821ae9..da6e538fd46e 100644 --- a/ee/tabby-ui/components/chat/question-answer.tsx +++ b/ee/tabby-ui/components/chat/question-answer.tsx @@ -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 } }) ?? [] ) @@ -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