Skip to content

Commit 0977182

Browse files
authored
refactor(mention-tag): enhance file path handling in mentions by integrating chat panel utilities (#4116)
1 parent 25fc1dc commit 0977182

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ee/tabby-ui/components/mention-tag.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import React, { useMemo } from 'react'
44
import { NodeViewProps, NodeViewWrapper } from '@tiptap/react'
5+
import { Filepath } from 'tabby-chat-panel/index'
56

67
import {
78
MARKDOWN_COMMAND_REGEX,
@@ -21,6 +22,8 @@ import {
2122
IconGitLab
2223
} from '@/components/ui/icons'
2324

25+
import { getFilepathStringByChatPanelFilePath } from './chat/form-editor/utils'
26+
2427
export function Mention({
2528
kind,
2629
label,
@@ -108,8 +111,10 @@ export function ThreadTitleWithMentions({
108111
textPart = textPart.replace(MARKDOWN_FILE_REGEX, (match, content) => {
109112
try {
110113
if (content.startsWith('{') && content.endsWith('}')) {
111-
const fileInfo = JSON.parse(content)
112-
const filename = resolveFileNameForDisplay(fileInfo.filepath)
114+
const fileInfo = JSON.parse(content) as Filepath
115+
const filepathString =
116+
getFilepathStringByChatPanelFilePath(fileInfo)
117+
const filename = resolveFileNameForDisplay(filepathString)
113118
return `@${filename}`
114119
}
115120
// Otherwise just use the content as is
@@ -127,7 +132,10 @@ export function ThreadTitleWithMentions({
127132
if (symbolInfo.label) {
128133
return `@${symbolInfo.label}`
129134
}
130-
const filename = resolveFileNameForDisplay(symbolInfo.filepath)
135+
const filepathString = getFilepathStringByChatPanelFilePath(
136+
symbolInfo.filepath
137+
)
138+
const filename = resolveFileNameForDisplay(filepathString)
131139
const range = symbolInfo.range
132140
? `:${symbolInfo.range.start}-${symbolInfo.range.end}`
133141
: ''
@@ -143,6 +151,7 @@ export function ThreadTitleWithMentions({
143151
return `@${cmdPart.replace(/"/g, '')}`
144152
})
145153
})
154+
146155
return finalContent
147156
}, [sources, message])
148157
return <div className={cn(className)}>{contentWithTags}</div>

0 commit comments

Comments
 (0)