From a3cfd0d0239569c64fdcbf4e0ed7cf3469be608f Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Sun, 16 Mar 2025 22:29:17 -0700 Subject: [PATCH] fix codespan links --- .../contrib/void/browser/chatThreadService.ts | 27 +++++++++++++++---- .../react/src/markdown/ChatMarkdownRender.tsx | 6 ++--- .../void/common/chatThreadServiceTypes.ts | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/chatThreadService.ts b/src/vs/workbench/contrib/void/browser/chatThreadService.ts index 1447b7ff..3b6104c8 100644 --- a/src/vs/workbench/contrib/void/browser/chatThreadService.ts +++ b/src/vs/workbench/contrib/void/browser/chatThreadService.ts @@ -27,6 +27,7 @@ import { ChatMessage, CodespanLocationLink, StagingSelectionItem, ToolMessage, T import { Position } from '../../../../editor/common/core/position.js'; import { ITerminalToolService } from './terminalToolService.js'; import { IMetricsService } from '../common/metricsService.js'; +import { shorten } from '../../../../base/common/labels.js'; const findLastIndex = (arr: T[], condition: (t: T) => boolean): number => { for (let i = arr.length - 1; i >= 0; i--) { @@ -910,15 +911,30 @@ class ChatThreadService extends Disposable implements IChatThreadService { const doesUriMatchTarget = (uri: URI) => uri.path.includes(target) // check if any prevFiles are the `codespanSearch` - for (const uri of prevUris) { - if (doesUriMatchTarget(uri)) return { uri } + for (const [idx, uri] of prevUris.entries()) { + if (doesUriMatchTarget(uri)) { + + // shorten it + const prevUriStrs = prevUris.map(uri => uri.toString()) + const shortenedUriStrs = shorten(prevUriStrs) + const displayText = shortenedUriStrs[idx] + + return { uri, displayText } + } } // else search codebase for file const { uris } = await this._toolsService.callTool['pathname_search']({ queryStr: target, pageNumber: 0 }) - for (const uri of uris) { - if (doesUriMatchTarget(uri)) return { uri } + for (const [idx, uri] of uris.entries()) { + if (doesUriMatchTarget(uri)) { + + const prevUriStrs = prevUris.map(uri => uri.toString()) + const shortenedUriStrs = shorten(prevUriStrs) + const displayText = shortenedUriStrs[idx] + + return { uri, displayText } + } } } @@ -967,7 +983,8 @@ class ChatThreadService extends Disposable implements IChatThreadService { startColumn: definition.range.startColumn, endLineNumber: definition.range.endLineNumber, endColumn: definition.range.endColumn, - } + }, + displayText: _codespanStr, }; // const defModelRef = await this._textModelService.createModelReference(definition.uri); 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 040f01d0..09078700 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 @@ -34,13 +34,11 @@ const Codespan = ({ text, className, onClick }: { text: string, className?: stri // TODO compute this once for efficiency. we should use `labels.ts/shorten` to display duplicates properly - const filename = useMemo(() => getBasename(text), [text]) - return - {filename} + {text} } @@ -101,7 +99,7 @@ const CodespanWithLink = ({ text, rawText, chatMessageLocation }: { text: string } return diff --git a/src/vs/workbench/contrib/void/common/chatThreadServiceTypes.ts b/src/vs/workbench/contrib/void/common/chatThreadServiceTypes.ts index 4667b62e..bbdc6cf0 100644 --- a/src/vs/workbench/contrib/void/common/chatThreadServiceTypes.ts +++ b/src/vs/workbench/contrib/void/common/chatThreadServiceTypes.ts @@ -75,6 +75,7 @@ export type StagingSelectionItem = CodeSelection | FileSelection export type CodespanLocationLink = { uri: URI, // we handle serialization for this + displayText: string, selection?: { // store as JSON so dont have to worry about serialization startLineNumber: number startColumn: number,