Skip to content

Commit

Permalink
fix(tabby-ui): update tabby-ui side filepath convert.
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes committed Jan 16, 2025
1 parent 9757e74 commit 7d63327
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
23 changes: 2 additions & 21 deletions ee/tabby-ui/components/message-markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MessageAttachmentClientCode
} from '@/lib/gql/generates/graphql'
import { AttachmentCodeItem, AttachmentDocItem, FileContext } from '@/lib/types'
import { cn } from '@/lib/utils'
import { cn, getFilepathFromContext } from '@/lib/utils'
import {
HoverCard,
HoverCardContent,
Expand All @@ -21,7 +21,6 @@ import './style.css'

import {
FileLocation,
Filepath,
LookupSymbolHint,
SymbolInfo
} from 'tabby-chat-panel/index'
Expand Down Expand Up @@ -175,26 +174,8 @@ export function MessageMarkdown({
setSymbolLocationMap(map => new Map(map.set(keyword, undefined)))
const hints: LookupSymbolHint[] = []
if (activeSelection && activeSelection?.range) {
// FIXME(@icycodes): this is intended to convert the filepath to Filepath type
// We should remove this after FileContext.filepath use type Filepath instead of string
let filepath: Filepath
if (
activeSelection.git_url.length > 1 &&
!activeSelection.filepath.includes(':')
) {
filepath = {
kind: 'git',
filepath: activeSelection.filepath,
gitUrl: activeSelection.git_url
}
} else {
filepath = {
kind: 'uri',
uri: activeSelection.filepath
}
}
hints.push({
filepath,
filepath: getFilepathFromContext(activeSelection),
location: {
start: activeSelection.range.start,
end: activeSelection.range.end
Expand Down
41 changes: 25 additions & 16 deletions ee/tabby-ui/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ export function getPromptForChatCommand(command: ChatCommand) {
}
}

// FIXME: improve this conversion
export function fromChatPanelFilepath(filepath: Filepath) {
if (filepath.kind === 'absolute-uri') {
return {
filepath: filepath.uri,
git_url: ''
}
}

if (filepath.kind === 'uri') {
return {
filepath: filepath.filepath,
git_url: ''
}
}

return {
filepath: filepath.filepath,
git_url: filepath.gitUrl
}
}

export function convertEditorContext(
editorContext: EditorContext
): FileContext {
Expand All @@ -215,28 +237,15 @@ export function convertEditorContext(
}
}

const convertFilepath = (filepath: Filepath) => {
if (filepath.kind === 'uri') {
return {
filepath: filepath.uri,
git_url: ''
}
}

return {
filepath: filepath.filepath,
git_url: filepath.gitUrl
}
}

return {
kind: 'file',
content: editorContext.content,
range: convertRange(editorContext.range),
...convertFilepath(editorContext.filepath)
...fromChatPanelFilepath(editorContext.filepath)
}
}

// FIXME: improve this conversion
export function getFilepathFromContext(context: FileContext): Filepath {
if (context.git_url.length > 1 && !context.filepath.includes(':')) {
return {
Expand All @@ -246,7 +255,7 @@ export function getFilepathFromContext(context: FileContext): Filepath {
}
} else {
return {
kind: 'uri',
kind: 'absolute-uri',
uri: context.filepath
}
}
Expand Down

0 comments on commit 7d63327

Please sign in to comment.