From b3cf5cc3c0cacdb2baef298716eaca4143574c61 Mon Sep 17 00:00:00 2001 From: wwayne Date: Thu, 30 May 2024 19:41:47 +0800 Subject: [PATCH 1/3] fix(vscode): chat panel reference opening local code browser --- clients/vscode/src/chat/ChatViewProvider.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clients/vscode/src/chat/ChatViewProvider.ts b/clients/vscode/src/chat/ChatViewProvider.ts index fdf4949c9a13..d03252fd0d44 100644 --- a/clients/vscode/src/chat/ChatViewProvider.ts +++ b/clients/vscode/src/chat/ChatViewProvider.ts @@ -37,7 +37,12 @@ export class ChatViewProvider implements WebviewViewProvider { this.client = createClient(webviewView, { navigate: async (context: Context) => { if (context?.filepath && context?.git_url) { - const url = `${context.git_url}/blob/main/${context.filepath}#L${context.range.start}-L${context.range.end}`; + const serverInfo = await this.agent.fetchServerInfo(); + const endpoint = serverInfo.config.endpoint; + + const project = context.git_url.split("/").slice(-1)[0]; + const line = `&line=${context.range.start}`; + const url = `${endpoint}/files?path=git/${project}/${context.filepath}${line}`; await env.openExternal(Uri.parse(url)); } }, From 583c163e111ad62c588709c0ecf1c745e47d6c11 Mon Sep 17 00:00:00 2001 From: wwayne Date: Thu, 30 May 2024 20:53:49 +0800 Subject: [PATCH 2/3] clean --- clients/vscode/src/chat/ChatViewProvider.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/clients/vscode/src/chat/ChatViewProvider.ts b/clients/vscode/src/chat/ChatViewProvider.ts index d03252fd0d44..97eda5a9719e 100644 --- a/clients/vscode/src/chat/ChatViewProvider.ts +++ b/clients/vscode/src/chat/ChatViewProvider.ts @@ -35,17 +35,7 @@ export class ChatViewProvider implements WebviewViewProvider { } this.client = createClient(webviewView, { - navigate: async (context: Context) => { - if (context?.filepath && context?.git_url) { - const serverInfo = await this.agent.fetchServerInfo(); - const endpoint = serverInfo.config.endpoint; - - const project = context.git_url.split("/").slice(-1)[0]; - const line = `&line=${context.range.start}`; - const url = `${endpoint}/files?path=git/${project}/${context.filepath}${line}`; - await env.openExternal(Uri.parse(url)); - } - }, + navigate: async () => {}, }); this.agent.on("didChangeStatus", async (status) => { From 74e8f8a49fd5452930c39ddc547c7d5838cf346f Mon Sep 17 00:00:00 2001 From: wwayne Date: Thu, 30 May 2024 21:08:33 +0800 Subject: [PATCH 3/3] update --- clients/vscode/src/chat/ChatViewProvider.ts | 7 ++++++- ee/tabby-ui/app/chat/page.tsx | 1 + ee/tabby-ui/components/chat/chat.tsx | 8 ++++++-- ee/tabby-ui/components/chat/question-answer.tsx | 12 +++++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/clients/vscode/src/chat/ChatViewProvider.ts b/clients/vscode/src/chat/ChatViewProvider.ts index 97eda5a9719e..fdf4949c9a13 100644 --- a/clients/vscode/src/chat/ChatViewProvider.ts +++ b/clients/vscode/src/chat/ChatViewProvider.ts @@ -35,7 +35,12 @@ export class ChatViewProvider implements WebviewViewProvider { } this.client = createClient(webviewView, { - navigate: async () => {}, + navigate: async (context: Context) => { + if (context?.filepath && context?.git_url) { + const url = `${context.git_url}/blob/main/${context.filepath}#L${context.range.start}-L${context.range.end}`; + await env.openExternal(Uri.parse(url)); + } + }, }); this.agent.on("didChangeStatus", async (status) => { diff --git a/ee/tabby-ui/app/chat/page.tsx b/ee/tabby-ui/app/chat/page.tsx index 70eda8475654..dca6cad06115 100644 --- a/ee/tabby-ui/app/chat/page.tsx +++ b/ee/tabby-ui/app/chat/page.tsx @@ -159,6 +159,7 @@ export default function ChatPage() { onLoaded={onChatLoaded} maxWidth={maxWidth} onCopyContent={from === 'vscode' ? onCopyContent : undefined} + isReferenceClickable={from !== 'vscode'} /> ) } diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index 53df5fb22033..68ed4cc9e912 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -34,6 +34,7 @@ type ChatContextValue = { onClearMessages: () => void container?: HTMLDivElement onCopyContent?: (value: string) => void + isReferenceClickable: boolean } export const ChatContext = React.createContext( @@ -118,6 +119,7 @@ interface ChatProps extends React.ComponentProps<'div'> { welcomeMessage?: string promptFormClassname?: string onCopyContent?: (value: string) => void + isReferenceClickable?: boolean } function ChatRenderer( @@ -137,7 +139,8 @@ function ChatRenderer( maxWidth, welcomeMessage, promptFormClassname, - onCopyContent + onCopyContent, + isReferenceClickable = true }: ChatProps, ref: React.ForwardedRef ) { @@ -384,7 +387,8 @@ function ChatRenderer( handleMessageAction, onClearMessages, container, - onCopyContent + onCopyContent, + isReferenceClickable }} >
diff --git a/ee/tabby-ui/components/chat/question-answer.tsx b/ee/tabby-ui/components/chat/question-answer.tsx index cbdc2051eb16..675b43d4a698 100644 --- a/ee/tabby-ui/components/chat/question-answer.tsx +++ b/ee/tabby-ui/components/chat/question-answer.tsx @@ -391,7 +391,8 @@ interface ContextReferencesProps { contexts: Context[] } const CodeReferences = ({ contexts }: ContextReferencesProps) => { - const { onNavigateToContext } = React.useContext(ChatContext) + const { onNavigateToContext, isReferenceClickable } = + React.useContext(ChatContext) const isMultipleReferences = contexts?.length > 1 if (!contexts?.length) return null @@ -421,9 +422,14 @@ const CodeReferences = ({ contexts }: ContextReferencesProps) => { .join('/') return (
onNavigateToContext?.(item)} + onClick={e => + isReferenceClickable && onNavigateToContext?.(item) + } >