Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit e36233b

Browse files
committed
Fix walkthrough webview JavaScript syntax error
- Remove TypeScript type annotations from embedded JavaScript - JavaScript webview can't parse ': any' and ': number' syntax - Replace with plain JavaScript parameter names - Add detailed logging with [WEBVIEW], [WALKTHROUGH] prefixes - Walkthrough system now renders properly
1 parent 2aec12a commit e36233b

File tree

1 file changed

+68
-47
lines changed

1 file changed

+68
-47
lines changed

extension/src/walkthroughWebview.ts

Lines changed: 68 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class WalkthroughDiffContentProvider implements vscode.TextDocumentContentProvid
5050
}
5151
}
5252

53-
type WalkthroughElement =
53+
type WalkthroughElement =
5454
| { content: string } // ResolvedMarkdownElement with processed dialectic: URLs
5555
| { comment: any } // Simplified for now
5656
| { files: FileChange[] } // GitDiffElement - named field serializes as {"files": [...]}
@@ -81,7 +81,7 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
8181
) {
8282
this.md = this.setupMarkdownRenderer();
8383
this.diffContentProvider = new WalkthroughDiffContentProvider();
84-
84+
8585
// Register diff content provider if context is available
8686
if (this.context) {
8787
this.context.subscriptions.push(
@@ -98,20 +98,20 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
9898
});
9999

100100
// Custom renderer rule for file reference links
101-
const defaultRender = md.renderer.rules.link_open || function(tokens: any, idx: any, options: any, env: any, self: any) {
101+
const defaultRender = md.renderer.rules.link_open || function (tokens: any, idx: any, options: any, env: any, self: any) {
102102
return self.renderToken(tokens, idx, options);
103103
};
104104

105105
md.renderer.rules.link_open = (tokens: any, idx: any, options: any, env: any, self: any) => {
106106
const token = tokens[idx];
107107
const href = token.attrGet('href');
108-
108+
109109
if (href && href.startsWith('dialectic:')) {
110110
token.attrSet('href', 'javascript:void(0)');
111111
token.attrSet('data-dialectic-url', href);
112112
token.attrSet('class', 'file-ref');
113113
}
114-
114+
115115
return defaultRender(tokens, idx, options, env, self);
116116
};
117117

@@ -122,8 +122,8 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
122122
// Basic HTML sanitization for VSCode webview context
123123
// Remove potentially dangerous content while preserving markdown-generated HTML
124124
return html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
125-
.replace(/javascript:/gi, '')
126-
.replace(/on\w+="[^"]*"/gi, '');
125+
.replace(/javascript:/gi, '')
126+
.replace(/on\w+="[^"]*"/gi, '');
127127
}
128128

129129
private async handleWebviewMessage(message: any): Promise<void> {
@@ -135,7 +135,7 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
135135
case 'action':
136136
console.log('Walkthrough: action received:', message.message);
137137
this.outputChannel.appendLine(`Action button clicked: ${message.message}`);
138-
138+
139139
// Send message to active AI terminal
140140
await this.sendToActiveShell(message.message);
141141
break;
@@ -158,19 +158,19 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
158158
*/
159159
private async showComment(comment: any): Promise<void> {
160160
console.log(`[WALKTHROUGH COMMENT] Starting showComment:`, comment);
161-
161+
162162
if (!comment.locations || comment.locations.length === 0) {
163163
vscode.window.showErrorMessage('Comment has no locations');
164164
return;
165165
}
166166

167167
// Check if any files in the comment appear in gitdiff sections
168168
const filesInDiff = this.getFilesInCurrentGitDiff();
169-
169+
170170
for (const location of comment.locations) {
171171
const filePath = location.path;
172172
const line = location.start.line - 1; // Convert to 0-based
173-
173+
174174
// Context-aware file opening
175175
if (filesInDiff.has(filePath)) {
176176
console.log(`[WALKTHROUGH COMMENT] File ${filePath} appears in gitdiff, opening diff view`);
@@ -181,13 +181,13 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
181181
const uri = vscode.Uri.file(path.join(baseUriPath, filePath));
182182
const document = await vscode.workspace.openTextDocument(uri);
183183
const editor = await vscode.window.showTextDocument(document);
184-
184+
185185
// Navigate to the specific line
186186
const position = new vscode.Position(line, location.start.column || 0);
187187
editor.selection = new vscode.Selection(position, position);
188188
editor.revealRange(new vscode.Range(position, position));
189189
}
190-
190+
191191
// Create comment thread using simplified CommentController
192192
await this.createCommentThread(filePath, location, comment);
193193
}
@@ -198,16 +198,16 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
198198
*/
199199
private getFilesInCurrentGitDiff(): Set<string> {
200200
const filesInDiff = new Set<string>();
201-
201+
202202
if (!this.currentWalkthrough) return filesInDiff;
203-
203+
204204
const allSections = [
205205
...(this.currentWalkthrough.introduction || []),
206206
...(this.currentWalkthrough.highlights || []),
207207
...(this.currentWalkthrough.changes || []),
208208
...(this.currentWalkthrough.actions || [])
209209
];
210-
210+
211211
for (const item of allSections) {
212212
if (typeof item === 'object' && 'files' in item) {
213213
// This is a GitDiffElement
@@ -216,7 +216,7 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
216216
});
217217
}
218218
}
219-
219+
220220
return filesInDiff;
221221
}
222222

@@ -278,7 +278,7 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
278278
}
279279
private async showFileDiff(filePath: string): Promise<void> {
280280
console.log(`[WALKTHROUGH DIFF] Starting showFileDiff for: ${filePath}`);
281-
281+
282282
if (!this.currentWalkthrough) {
283283
console.log('[WALKTHROUGH DIFF] ERROR: No current walkthrough data');
284284
vscode.window.showErrorMessage('No walkthrough data available');
@@ -287,29 +287,29 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
287287

288288
// Find the file change in the walkthrough data
289289
let fileChange: FileChange | undefined;
290-
290+
291291
// Search through all sections for gitdiff elements
292292
const allSections = [
293293
...(this.currentWalkthrough.introduction || []),
294294
...(this.currentWalkthrough.highlights || []),
295295
...(this.currentWalkthrough.changes || []),
296296
...(this.currentWalkthrough.actions || [])
297297
];
298-
298+
299299
for (const item of allSections) {
300300
if (typeof item === 'object' && 'files' in item) {
301301
// This is a GitDiffElement named field - {"files": FileChange[]}
302302
fileChange = item.files.find((fc: FileChange) => fc.path === filePath);
303303
if (fileChange) break;
304304
}
305305
}
306-
306+
307307
if (!fileChange) {
308308
console.log(`[WALKTHROUGH DIFF] ERROR: File not found in walkthrough: ${filePath}`);
309309
vscode.window.showErrorMessage(`File not found in walkthrough: ${filePath}`);
310310
return;
311311
}
312-
312+
313313
console.log(`[WALKTHROUGH DIFF] Found file change: ${fileChange.status}, ${fileChange.additions}+/${fileChange.deletions}-, ${fileChange.hunks.length} hunks`);
314314

315315
try {
@@ -319,10 +319,10 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
319319
vscode.window.showErrorMessage('No workspace folder found');
320320
return;
321321
}
322-
322+
323323
const absolutePath = vscode.Uri.joinPath(workspaceFolder.uri, filePath);
324324
console.log(`[WALKTHROUGH DIFF] Resolved absolute path: ${absolutePath.toString()}`);
325-
325+
326326
// Get "after" content from current file
327327
const currentDocument = await vscode.workspace.openTextDocument(absolutePath);
328328
const modifiedContent = currentDocument.getText();
@@ -344,9 +344,9 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
344344

345345
// Show diff using VSCode's native diff viewer with automatic highlighting
346346
console.log('[WALKTHROUGH DIFF] Calling vscode.diff command...');
347-
await vscode.commands.executeCommand('vscode.diff',
348-
originalUri,
349-
modifiedUri,
347+
await vscode.commands.executeCommand('vscode.diff',
348+
originalUri,
349+
modifiedUri,
350350
`${filePath} (Walkthrough Diff)`
351351
);
352352
console.log('[WALKTHROUGH DIFF] vscode.diff command completed successfully');
@@ -365,17 +365,17 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
365365
try {
366366
const modifiedLines = modifiedContent.split('\n');
367367
const originalLines: string[] = [];
368-
368+
369369
let modifiedIndex = 0;
370-
370+
371371
for (const hunk of fileChange.hunks) {
372372
// Add lines before this hunk (unchanged context)
373373
const contextStart = hunk.new_start - 1; // Convert to 0-based
374374
while (modifiedIndex < contextStart && modifiedIndex < modifiedLines.length) {
375375
originalLines.push(modifiedLines[modifiedIndex]);
376376
modifiedIndex++;
377377
}
378-
378+
379379
// Process hunk lines
380380
for (const line of hunk.lines) {
381381
switch (line.line_type) {
@@ -397,13 +397,13 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
397397
}
398398
}
399399
}
400-
400+
401401
// Add any remaining lines after all hunks
402402
while (modifiedIndex < modifiedLines.length) {
403403
originalLines.push(modifiedLines[modifiedIndex]);
404404
modifiedIndex++;
405405
}
406-
406+
407407
return originalLines.join('\n');
408408
} catch (error) {
409409
console.error('[WALKTHROUGH DIFF] Failed to generate original content:', error);
@@ -518,20 +518,20 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
518518

519519
public showWalkthrough(walkthrough: WalkthroughData) {
520520
console.log('WalkthroughWebviewProvider.showWalkthrough called with:', walkthrough);
521-
521+
522522
// Store walkthrough data for diff functionality
523523
this.currentWalkthrough = walkthrough;
524-
524+
525525
// Clear placement memory for new walkthrough
526526
this.clearPlacementMemory();
527-
527+
528528
if (this._view) {
529529
console.log('Webview exists, showing and posting message');
530530
this._view.show?.(true);
531-
531+
532532
// Pre-render markdown content
533533
const processedWalkthrough = this.processWalkthroughMarkdown(walkthrough);
534-
534+
535535
this._view.webview.postMessage({
536536
type: 'walkthrough',
537537
data: processedWalkthrough
@@ -570,8 +570,8 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
570570

571571
private _getHtmlForWebview(webview: vscode.Webview) {
572572
const nonce = crypto.randomBytes(16).toString('base64');
573-
574-
return `<!DOCTYPE html>
573+
574+
let html = `<!DOCTYPE html>
575575
<html lang="en">
576576
<head>
577577
<meta charset="UTF-8">
@@ -763,7 +763,7 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
763763
html += '<div class="comment-icon">💬</div>';
764764
html += '<div class="comment-content">';
765765
html += '<div class="comment-locations">';
766-
item.comment.locations.forEach((location: any, index: number) => {
766+
item.comment.locations.forEach((location, index) => {
767767
if (index > 0) html += ', ';
768768
html += '<span class="comment-location">' + location.path + ':' + location.start.line + '</span>';
769769
});
@@ -847,25 +847,39 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
847847
});
848848
849849
window.addEventListener('message', event => {
850-
console.log('Webview received message:', event.data);
850+
console.log('[WEBVIEW] Received message:', event.data);
851851
const message = event.data;
852852
if (message.type === 'walkthrough') {
853-
console.log('Processing walkthrough message with data:', message.data);
853+
console.log('[WALKTHROUGH] Processing message with data:', message.data);
854854
const data = message.data;
855+
856+
console.log('[SECTIONS] Walkthrough sections:', {
857+
introduction: data.introduction?.length || 0,
858+
highlights: data.highlights?.length || 0,
859+
changes: data.changes?.length || 0,
860+
actions: data.actions?.length || 0
861+
});
862+
855863
let html = '';
856864
857865
html += renderSection('Introduction', data.introduction);
858866
html += renderSection('Highlights', data.highlights);
859867
html += renderSection('Changes', data.changes);
860868
html += renderSection('Actions', data.actions);
861869
862-
console.log('Generated HTML:', html);
870+
console.log('[HTML] Generated HTML length:', html.length);
863871
const finalHtml = html || '<div class="empty-state">Empty walkthrough</div>';
864-
console.log('Setting innerHTML to:', finalHtml);
865-
document.getElementById('content').innerHTML = finalHtml;
866-
console.log('Content updated');
872+
console.log('[UPDATE] Setting innerHTML to content element');
873+
874+
const contentElement = document.getElementById('content');
875+
if (contentElement) {
876+
contentElement.innerHTML = finalHtml;
877+
console.log('[SUCCESS] Content updated successfully');
878+
} else {
879+
console.error('[ERROR] Content element not found!');
880+
}
867881
} else {
868-
console.log('Ignoring message type:', message.type);
882+
console.log('[IGNORE] Ignoring message type:', message.type);
869883
}
870884
});
871885
@@ -876,5 +890,12 @@ export class WalkthroughWebviewProvider implements vscode.WebviewViewProvider {
876890
</script>
877891
</body>
878892
</html>`;
893+
894+
this.outputChannel.appendLine(`-----------------------------------------`);
895+
this.outputChannel.appendLine(`WEBVIEW HTML FOLLOWS:`);
896+
this.outputChannel.appendLine(html);
897+
this.outputChannel.appendLine(`-----------------------------------------`);
898+
899+
return html;
879900
}
880901
}

0 commit comments

Comments
 (0)