From 89dd4d3a92a22d4bd313b491deb4b1fefa0e775a Mon Sep 17 00:00:00 2001 From: davidramnero Date: Thu, 18 Jun 2026 14:07:34 +0200 Subject: [PATCH 1/6] fix / #75 run checks when changing file open in active text editor --- src/extension.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 1348329..845c82e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -172,6 +172,13 @@ export async function activate(context: vscode.ExtensionContext) { // Run cppcheck when a file is opened vscode.workspace.onDidOpenTextDocument(handleDocument, null, context.subscriptions); + // Run cppcheck when opening files in text editor + vscode.window.onDidChangeActiveTextEditor(editor => { + if (editor) { + handleDocument(editor.document); + } + }, null, context.subscriptions); + // Run cppcheck for all open files when the workspace is opened vscode.workspace.onDidChangeWorkspaceFolders(() => { vscode.workspace.textDocuments.forEach(handleDocument); From 8f5393aa8edb51612b61212d11463d40d518c1d6 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Mon, 22 Jun 2026 13:57:05 +0200 Subject: [PATCH 2/6] wip --- src/extension.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 845c82e..4cbd011 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -174,9 +174,25 @@ export async function activate(context: vscode.ExtensionContext) { // Run cppcheck when opening files in text editor vscode.window.onDidChangeActiveTextEditor(editor => { - if (editor) { - handleDocument(editor.document); + if (!editor) { + return; + } + const tabs = vscode.window.tabGroups.all.flatMap(g => g.tabs); + const tab = tabs.find(t => { + return t.input instanceof vscode.TabInputText && + t.input.uri.toString() === editor.document.uri.toString(); + } + ); + + if (!tab) { + return; + } + console.log('tab', tab, 'isPinned', tab.isPinned); + // Ignore preview tabs + if (!tab.isPinned) { + return; } + handleDocument(editor.document); }, null, context.subscriptions); // Run cppcheck for all open files when the workspace is opened From 668926cea2308aac5fe3544b4e2d73e9a5924898 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 23 Jun 2026 09:29:15 +0200 Subject: [PATCH 3/6] fix timer for preview file auto analysis on open --- src/extension.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 24d400a..435a8d1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,6 +10,7 @@ import { looksLikePath, resolvePath, findWorkspaceRoot } from './util/path'; // To keep track of document changes we save hashed versions of their content to this record let documentHashMemory : Record = {}; +let previewAnalysisTimer: NodeJS.Timeout | undefined; let cppcheckProgressIndicator: vscode.StatusBarItem; let checksRunning = false; @@ -194,6 +195,7 @@ export async function activate(context: vscode.ExtensionContext) { // Run cppcheck when opening files in text editor vscode.window.onDidChangeActiveTextEditor(editor => { + clearTimeout(previewAnalysisTimer); if (!editor) { return; } @@ -203,15 +205,16 @@ export async function activate(context: vscode.ExtensionContext) { t.input.uri.toString() === editor.document.uri.toString(); } ); - - if (!tab) { - return; - } - console.log('tab', tab, 'isPinned', tab.isPinned); - // Ignore preview tabs - if (!tab.isPinned) { - return; + + // Only analyze previewed files if user stays on them for 10 seconds + if (tab && tab.isPreview) { + console.log('timer started'); + previewAnalysisTimer = setTimeout(() => { + console.log('analysis run'); + handleDocument(editor.document); + }, 10000); } + handleDocument(editor.document); }, null, context.subscriptions); From 0678bc4126da6c12cd1d120f56bc0c20412e8ab4 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 23 Jun 2026 09:35:14 +0200 Subject: [PATCH 4/6] removed console logs --- src/extension.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 435a8d1..ed402e5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -208,9 +208,7 @@ export async function activate(context: vscode.ExtensionContext) { // Only analyze previewed files if user stays on them for 10 seconds if (tab && tab.isPreview) { - console.log('timer started'); previewAnalysisTimer = setTimeout(() => { - console.log('analysis run'); handleDocument(editor.document); }, 10000); } From 414b6b9fc75a3bfaed6972cd075c090d70c4105f Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 23 Jun 2026 10:39:15 +0200 Subject: [PATCH 5/6] fix preview analysis running --- src/extension.ts | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index ed402e5..d744a77 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,6 +11,7 @@ import { looksLikePath, resolvePath, findWorkspaceRoot } from './util/path'; let documentHashMemory : Record = {}; let previewAnalysisTimer: NodeJS.Timeout | undefined; +let previewedDocument: vscode.TextDocument | undefined; let cppcheckProgressIndicator: vscode.StatusBarItem; let checksRunning = false; @@ -193,28 +194,38 @@ export async function activate(context: vscode.ExtensionContext) { // Run cppcheck when a file is opened vscode.workspace.onDidOpenTextDocument(handleDocument, null, context.subscriptions); - // Run cppcheck when opening files in text editor - vscode.window.onDidChangeActiveTextEditor(editor => { + // Run cppcheck when changing files viewed in text editor + vscode.window.tabGroups.onDidChangeTabs(async e => { clearTimeout(previewAnalysisTimer); - if (!editor) { - return; - } - const tabs = vscode.window.tabGroups.all.flatMap(g => g.tabs); - const tab = tabs.find(t => { - return t.input instanceof vscode.TabInputText && - t.input.uri.toString() === editor.document.uri.toString(); + for (const tab of e.changed) { + if (tab.input instanceof vscode.TabInputText) { + const uri = tab.input.uri; + const document = + vscode.workspace.textDocuments.find( + doc => doc.uri.toString() === uri.toString() + ) ?? await vscode.workspace.openTextDocument(uri); + // Only analyze previewed files if user stays on them for 10 seconds + if (tab && tab.isPreview) { + previewAnalysisTimer = setTimeout(() => { + handleDocument(document); + previewedDocument = document; + }, 10000); + } else { + // If file is properly opened we run analysis right away + handleDocument(document); + } + } } - ); + }, null, context.subscriptions); - // Only analyze previewed files if user stays on them for 10 seconds - if (tab && tab.isPreview) { - previewAnalysisTimer = setTimeout(() => { - handleDocument(editor.document); - }, 10000); + // Clear diagnostics of previewed files when no longer viewed + vscode.window.onDidChangeActiveTextEditor(() => { + if (previewedDocument) { + diagnosticCollection.delete(previewedDocument.uri); + documentHashMemory[previewedDocument.fileName] = ''; + previewedDocument = undefined; } - - handleDocument(editor.document); - }, null, context.subscriptions); + }); // Run cppcheck for all open files when the workspace is opened vscode.workspace.onDidChangeWorkspaceFolders(() => { @@ -227,6 +238,7 @@ export async function activate(context: vscode.ExtensionContext) { // Clean up diagnostics when a file is closed vscode.workspace.onDidCloseTextDocument((document: vscode.TextDocument) => { diagnosticCollection.delete(document.uri); + documentHashMemory[document.fileName] = ''; }, null, context.subscriptions); } From 9478aa683da4f18177c782ed6fdd67b27d5d25ab Mon Sep 17 00:00:00 2001 From: davidramnero Date: Tue, 23 Jun 2026 10:40:17 +0200 Subject: [PATCH 6/6] restored fix from other branch to avoid conflict --- src/extension.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index d744a77..feb3250 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -238,7 +238,6 @@ export async function activate(context: vscode.ExtensionContext) { // Clean up diagnostics when a file is closed vscode.workspace.onDidCloseTextDocument((document: vscode.TextDocument) => { diagnosticCollection.delete(document.uri); - documentHashMemory[document.fileName] = ''; }, null, context.subscriptions); }