Skip to content

Commit 1456f23

Browse files
committed
fixed streaming traces download
1 parent f516661 commit 1456f23

4 files changed

Lines changed: 32 additions & 18 deletions

File tree

extensions/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ariana",
33
"displayName": "Ariana - Debugging with AI",
44
"description": "Debug your JS/TS/Python code effortlessly just by hovering it, or by asking AI.",
5-
"version": "0.8.5",
5+
"version": "0.8.7",
66
"icon": "resources/logo.png",
77
"engines": {
88
"vscode": "^1.94.0"

extensions/vscode/src/extension.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export async function activate(context: vscode.ExtensionContext) {
6262
// Function to manage WebSocket connection
6363
async function connectToTraceWebSocket(vaultSecretKey: string) {
6464
// Close existing connection if any
65-
closeWebSocketConnection();
65+
if (wsConnection) {
66+
wsConnection.close();
67+
wsConnection = null;
68+
}
6669

6770
const wsUrl = apiUrl.replace(/^http/, 'ws');
6871
const fullWsUrl = `${wsUrl}/vaults/traces/${vaultSecretKey}/stream`;
@@ -74,19 +77,26 @@ export async function activate(context: vscode.ExtensionContext) {
7477
console.log('WebSocket connection established');
7578
});
7679

80+
let isFirst = true;
81+
7782
wsConnection.on('message', (data: Buffer) => {
7883
try {
7984
const parsedData = JSON.parse(data.toString());
8085
if (Array.isArray(parsedData)) {
8186
// Initial batch of traces
82-
console.log(`Received ${parsedData.length} traces from WebSocket`);
83-
tracesData = parsedData;
87+
if (isFirst) {
88+
console.log(`Received ${parsedData.length} initial traces from WebSocket`);
89+
tracesData = parsedData;
90+
} else {
91+
console.log(`Received ${parsedData.length} new traces from WebSocket`);
92+
parsedData.forEach(pd => tracesData.push(pd))
93+
}
8494
if (showTraces && vscode.window.activeTextEditor) {
8595
declareTracesUpdate(vscode.window.activeTextEditor);
8696
}
8797
} else {
8898
// Single new trace
89-
console.log('Received new trace from WebSocket');
99+
console.log('Received exactly one new trace from WebSocket');
90100
tracesData.push(parsedData);
91101

92102
// If the file this trace belongs to is currently focused, update highlights
@@ -97,6 +107,7 @@ export async function activate(context: vscode.ExtensionContext) {
97107
}
98108
}
99109
}
110+
isFirst = false;
100111
} catch (error) {
101112
console.error('Error processing WebSocket message:', error);
102113
}
@@ -121,13 +132,6 @@ export async function activate(context: vscode.ExtensionContext) {
121132
});
122133
}
123134

124-
function closeWebSocketConnection() {
125-
if (wsConnection) {
126-
wsConnection.close();
127-
wsConnection = null;
128-
}
129-
}
130-
131135
// Function to start monitoring vault key changes
132136
function startVaultKeyMonitoring() {
133137
// Stop existing monitoring if any
@@ -158,8 +162,6 @@ export async function activate(context: vscode.ExtensionContext) {
158162
const vaultSecretKey = await vaultManager.getVaultKey(vscode.window.activeTextEditor.document.uri.fsPath);
159163

160164
if (!vaultSecretKey) {
161-
closeWebSocketConnection();
162-
currentVaultSecretKey = null;
163165
return;
164166
}
165167

@@ -225,10 +227,14 @@ export async function activate(context: vscode.ExtensionContext) {
225227
showTraces = !showTraces;
226228

227229
if (showTraces) {
230+
console.log("showing traces now");
228231
startVaultKeyMonitoring();
229232
} else {
233+
console.log("hiding traces now");
230234
stopVaultKeyMonitoring();
231-
closeWebSocketConnection();
235+
wsConnection?.close();
236+
wsConnection = null;
237+
tracesData = []
232238
unhighlightTraces();
233239
clearHoverTraces();
234240
}
@@ -268,6 +274,7 @@ export async function activate(context: vscode.ExtensionContext) {
268274
if (!editor) {
269275
return;
270276
}
277+
console.log("highlight requested of " + tracesData.length + " traces");
271278
const regions = tracesToRegions(tracesData.filter(trace =>
272279
formatUriForDB(editor.document.uri) === trace.start_pos.filepath
273280
));
@@ -282,7 +289,11 @@ export async function activate(context: vscode.ExtensionContext) {
282289
tracesUpdates.pop();
283290
}
284291
if (tracesUpdates.length > 0 && tracesUpdates[tracesUpdates.length - 1] === currentEditor) {
285-
highlightTraces(currentEditor);
292+
console.log(tracesUpdates.length + " relevant trace update received now");
293+
if (showTraces) {
294+
console.log("update triggers highlight because we show traces");
295+
highlightTraces(currentEditor);
296+
}
286297
tracesUpdates.pop();
287298
}
288299
}
@@ -295,6 +306,7 @@ export async function activate(context: vscode.ExtensionContext) {
295306
if (!editor) {
296307
return;
297308
}
309+
console.log("unhighlighting traces now");
298310
clearDecorations(editor, decoratedRanges);
299311
}
300312

@@ -304,6 +316,7 @@ export async function activate(context: vscode.ExtensionContext) {
304316
return;
305317
}
306318
if (tracesHoverDisposable) {
319+
console.log("clearing hovers")
307320
tracesHoverDisposable.dispose();
308321
tracesHoverDisposable = undefined;
309322
}
@@ -335,11 +348,10 @@ export async function activate(context: vscode.ExtensionContext) {
335348

336349
context.subscriptions.push(disposable);
337350

338-
// Make sure to clean up resources when deactivated
339351
context.subscriptions.push({
340352
dispose: () => {
341353
stopVaultKeyMonitoring();
342-
closeWebSocketConnection();
354+
wsConnection?.close()
343355
}
344356
});
345357
}

extensions/vscode/src/highlighting/decorations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const hoverErrorRightDecorationType = vscode.window.createTextEditorDecor
107107
});
108108

109109
export function clearDecorations(editor: vscode.TextEditor, decoratedRanges: Map<vscode.Range, vscode.TextEditorDecorationType>) {
110+
console.log("clearing decorations now")
110111
decoratedRanges.clear();
111112
editor.setDecorations(highlightDecorationType, []);
112113
editor.setDecorations(highlightInBetweenDecorationType, []);

extensions/vscode/src/highlighting/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export function highlightRegions(
178178

179179
// Apply all decorations
180180
for (const [decorationType, ranges] of finalDecorations) {
181+
console.log("setting " + ranges.length + " highlighted ranges of type " + decorationType.key);
181182
editor.setDecorations(decorationType, ranges);
182183
}
183184

0 commit comments

Comments
 (0)