From e97062ae0324d739faca34ddcbb26b72c78fa14f Mon Sep 17 00:00:00 2001 From: andrepimenta Date: Tue, 24 Jun 2025 02:53:54 +0100 Subject: [PATCH] File name better --- src/extension.ts | 14 ++++++++++++++ src/ui-styles.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++-- src/ui.ts | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 855a4e4..3e7011e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -231,6 +231,9 @@ class ClaudeChatProvider { case 'dismissWSLAlert': this._dismissWSLAlert(); return; + case 'openFile': + this._openFileInEditor(message.filePath); + return; } }, null, @@ -1371,6 +1374,17 @@ class ClaudeChatProvider { this._context.globalState.update('wslAlertDismissed', true); } + private async _openFileInEditor(filePath: string) { + try { + const uri = vscode.Uri.file(filePath); + const document = await vscode.workspace.openTextDocument(uri); + await vscode.window.showTextDocument(document, vscode.ViewColumn.One); + } catch (error) { + vscode.window.showErrorMessage(`Failed to open file: ${filePath}`); + console.error('Error opening file:', error); + } + } + public dispose() { if (this._panel) { this._panel.dispose(); diff --git a/src/ui-styles.ts b/src/ui-styles.ts index 82dbb02..09bcf48 100644 --- a/src/ui-styles.ts +++ b/src/ui-styles.ts @@ -429,7 +429,6 @@ const styles = ` } .tool-input { - margin-top: 4px; padding: 12px; font-family: var(--vscode-editor-font-family); font-size: 12px; @@ -453,7 +452,6 @@ const styles = ` /* Diff display styles for Edit tool */ .diff-container { - margin-top: 8px; border: 1px solid var(--vscode-panel-border); border-radius: 4px; overflow: hidden; @@ -535,6 +533,50 @@ const styles = ` transform: translateY(1px); } + /* File path display styles */ + .diff-file-path { + padding: 8px 12px; + border: 1px solid var(--vscode-panel-border); + border-radius: 4px; + font-size: 12px; + } + + .file-path-short, + .file-path-truncated { + font-family: var(--vscode-editor-font-family); + color: var(--vscode-foreground); + font-weight: 500; + } + + .file-path-truncated { + display: inline-flex; + align-items: center; + gap: 6px; + cursor: pointer; + transition: all 0.2s ease; + padding: 2px 4px; + border-radius: 3px; + } + + .file-path-truncated .file-icon { + font-size: 14px; + opacity: 0.7; + transition: opacity 0.2s ease; + } + + .file-path-truncated:hover { + color: var(--vscode-textLink-foreground); + background-color: var(--vscode-list-hoverBackground); + } + + .file-path-truncated:hover .file-icon { + opacity: 1; + } + + .file-path-truncated:active { + transform: translateY(1px); + } + .expand-btn { background: linear-gradient(135deg, rgba(64, 165, 255, 0.15) 0%, rgba(64, 165, 255, 0.1) 100%); border: 1px solid rgba(64, 165, 255, 0.3); diff --git a/src/ui.ts b/src/ui.ts index bdae887..1e256ca 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -776,6 +776,12 @@ const html = ` return str; } + // Special handling for Read tool with file_path + if (input.file_path && Object.keys(input).length === 1) { + const formattedPath = formatFilePath(input.file_path); + return '
' + formattedPath + '
'; + } + let result = ''; let isFirst = true; for (const [key, value] of Object.entries(input)) { @@ -784,7 +790,11 @@ const html = ` if (!isFirst) result += '\\n'; isFirst = false; - if (valueStr.length > 100) { + // Special formatting for file_path in Read tool context + if (key === 'file_path') { + const formattedPath = formatFilePath(valueStr); + result += '
' + formattedPath + '
'; + } else if (valueStr.length > 100) { const truncated = valueStr.substring(0, 97) + '...'; const escapedValue = valueStr.replace(/"/g, '"').replace(/'/g, '''); result += '' + key + ': ' + truncated + ' expand'; @@ -805,7 +815,9 @@ const html = ` return formatToolInputUI(input); } - let result = 'file_path: ' + input.file_path + '\\n\\n'; + // Format file path with better display + const formattedPath = formatFilePath(input.file_path); + let result = '
' + formattedPath + '
\\n'; // Create diff view const oldLines = input.old_string.split('\\n'); @@ -868,6 +880,24 @@ const html = ` return div.innerHTML; } + function openFileInEditor(filePath) { + vscode.postMessage({ + type: 'openFile', + filePath: filePath + }); + } + + function formatFilePath(filePath) { + if (!filePath) return ''; + + // Extract just the filename + const parts = filePath.split('/'); + const fileName = parts[parts.length - 1]; + + return '' + + '📄' + escapeHtml(fileName) + ''; + } + function toggleDiffExpansion(diffId) { const hiddenDiv = document.getElementById(diffId + '_hidden'); const button = document.querySelector('[onclick*="' + diffId + '"]');