diff --git a/src/vs/workbench/contrib/void/browser/react/src/markdown/ChatMarkdownRender.tsx b/src/vs/workbench/contrib/void/browser/react/src/markdown/ChatMarkdownRender.tsx index d2714d08..be7d1de1 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/markdown/ChatMarkdownRender.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/markdown/ChatMarkdownRender.tsx @@ -14,7 +14,7 @@ import { isAbsolute } from '../../../../../../../base/common/path.js' import { separateOutFirstLine } from '../../../../common/helpers/util.js' import { BlockCode } from '../util/inputs.js' import { CodespanLocationLink } from '../../../../common/chatThreadServiceTypes.js' -import { voidOpenFileFn } from '../sidebar-tsx/SidebarChat.js' +import { getBasename, getRelative, voidOpenFileFn } from '../sidebar-tsx/SidebarChat.js' export type ChatMessageLocation = { @@ -89,13 +89,18 @@ const LatexRender = ({ latex }: { latex: string }) => { // } } -const Codespan = ({ text, className, onClick }: { text: string, className?: string, onClick?: () => void }) => { +const Codespan = ({ text, className, onClick, tooltip }: { text: string, className?: string, onClick?: () => void, tooltip?: string }) => { // TODO compute this once for efficiency. we should use `labels.ts/shorten` to display duplicates properly return {text} @@ -115,23 +120,31 @@ const CodespanWithLink = ({ text, rawText, chatMessageLocation }: { text: string const [didComputeCodespanLink, setDidComputeCodespanLink] = useState(false) let link: CodespanLocationLink | undefined = undefined - if (rawText.endsWith('`')) { // if codespan was completed - // get link from cache - link = chatThreadService.getCodespanLink({ codespanStr: text, messageIdx, threadId }) + if (!rawText.endsWith('`')) return null - if (link === undefined) { - // if no link, generate link and add to cache - chatThreadService.generateCodespanLink({ codespanStr: text, threadId }) - .then(link => { - chatThreadService.addCodespanLink({ newLinkText: text, newLinkLocation: link, messageIdx, threadId }) - setDidComputeCodespanLink(true) // rerender - }) - } + // get link from cache + link = chatThreadService.getCodespanLink({ codespanStr: text, messageIdx, threadId }) + + if (link === undefined) { + // if no link, generate link and add to cache + chatThreadService.generateCodespanLink({ codespanStr: text, threadId }) + .then(link => { + chatThreadService.addCodespanLink({ newLinkText: text, newLinkLocation: link, messageIdx, threadId }) + setDidComputeCodespanLink(true) // rerender + }) } + // If it's a file path, shorten it and add tooltip + let displayText = link?.displayText || text + let tooltip: string | undefined = undefined + + if (link?.uri && isValidUri(displayText)) { + tooltip = getRelative(URI.file(displayText), accessor) // Full path as tooltip + displayText = getBasename(displayText) + } const onClick = () => { if (!link || !link.selection) return; @@ -141,9 +154,10 @@ const CodespanWithLink = ({ text, rawText, chatMessageLocation }: { text: string } return } diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index fe6de590..52480137 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -495,7 +495,7 @@ const ScrollToBottomContainer = ({ children, className, style, scrollContainerRe ); }; -const getRelative = (uri: URI, accessor: ReturnType) => { +export const getRelative = (uri: URI, accessor: ReturnType) => { const workspaceContextService = accessor.get('IWorkspaceContextService') let path: string const isInside = workspaceContextService.isInsideWorkspace(uri) diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx index 937bf99e..d2b838e1 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx @@ -132,7 +132,7 @@ const scoreSubsequence = (text: string, pattern: string): number => { } -export function getRelativeWorkspacePath(accessor: ReturnType, uri: URI): string { +function getRelativeWorkspacePath(accessor: ReturnType, uri: URI): string { const workspaceService = accessor.get('IWorkspaceContextService'); const workspaceFolders = workspaceService.getWorkspace().folders;