From 92be7b58304211abd5fe5c0dc2c1373b6b6073a4 Mon Sep 17 00:00:00 2001 From: liangfung Date: Tue, 24 Dec 2024 12:03:57 +0800 Subject: [PATCH] update --- clients/tabby-chat-panel/src/index.ts | 2 +- clients/vscode/src/chat/WebviewHelper.ts | 2 +- ee/tabby-ui/lib/types/chat.ts | 6 +++++- ee/tabby-ui/lib/utils/index.ts | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clients/tabby-chat-panel/src/index.ts b/clients/tabby-chat-panel/src/index.ts index cfab2ece63f4..23795b7ef3a5 100644 --- a/clients/tabby-chat-panel/src/index.ts +++ b/clients/tabby-chat-panel/src/index.ts @@ -161,7 +161,7 @@ export interface FileLocation { * The location in the file. * It could be a 1-based line number, a line range, a position or a position range. */ - location: Location + location?: Location } /** diff --git a/clients/vscode/src/chat/WebviewHelper.ts b/clients/vscode/src/chat/WebviewHelper.ts index dd98d2105cd6..b80c2c8b371f 100644 --- a/clients/vscode/src/chat/WebviewHelper.ts +++ b/clients/vscode/src/chat/WebviewHelper.ts @@ -640,7 +640,7 @@ export class WebviewHelper { } } - const targetRange = chatPanelLocationToVSCodeRange(fileLocation.location) ?? new Range(0, 0, 0, 0); + const targetRange = fileLocation.location ? chatPanelLocationToVSCodeRange(fileLocation.location) ?? new Range(0, 0, 0, 0) : new Range(0, 0, 0, 0); try { await commands.executeCommand( "editor.action.goToLocations", diff --git a/ee/tabby-ui/lib/types/chat.ts b/ee/tabby-ui/lib/types/chat.ts index 645b0246be85..515c923da74c 100644 --- a/ee/tabby-ui/lib/types/chat.ts +++ b/ee/tabby-ui/lib/types/chat.ts @@ -12,7 +12,11 @@ import { ArrayElementType } from './common' export interface FileContext { kind: 'file' filepath: string - range: { start: number; end: number } + /** + * The range of the selected content in the file. + * If the range is not provided, the whole file is considered. + */ + range?: { start: number; end: number } content: string git_url: string } diff --git a/ee/tabby-ui/lib/utils/index.ts b/ee/tabby-ui/lib/utils/index.ts index f5aec654373f..27b850442794 100644 --- a/ee/tabby-ui/lib/utils/index.ts +++ b/ee/tabby-ui/lib/utils/index.ts @@ -135,7 +135,7 @@ export function formatLineHashForLocation(location: Location | undefined) { const start = location.start if (typeof start === 'number') { const end = location.end as number - return `L${start}-${end}` + return `L${start}-L${end}` } if ( typeof start === 'object' && @@ -143,7 +143,7 @@ export function formatLineHashForLocation(location: Location | undefined) { typeof start.line === 'number' ) { const end = location.end as Position - return `L${start.line}-${end.line}` + return `L${start.line}-L${end.line}` } } return '' @@ -199,9 +199,9 @@ export function convertEditorContext( editorContext: EditorContext ): FileContext { const convertRange = (range: LineRange | PositionRange | undefined) => { - // FIXME: If the range is not provided, the whole file is considered. + // If the range is not provided, the whole file is considered. if (!range) { - return { start: 0, end: 0 } + return undefined } if (typeof range.start === 'number') {