From 272aa4c50b03386618aacad7ffbad9d85cf1e22d Mon Sep 17 00:00:00 2001 From: davidramnero Date: Wed, 17 Jun 2026 17:54:41 +0200 Subject: [PATCH 1/3] feature / #68 skip running checks if file content has not changed --- src/extension.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 4387e4a..a872da4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,11 +1,15 @@ import * as vscode from 'vscode'; import * as cp from 'child_process'; import * as xml2js from 'xml2js'; +import * as crypto from 'crypto'; import { documentationLinkMap, getPremiumCertLink } from './util/documentation'; import { runCommand } from './util/scripts'; 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 = {}; + enum SeverityNumber { Info = 0, Warning = 1, @@ -64,6 +68,13 @@ function parseMinSeverity(str: string): SeverityNumber { } } +function getDocumentSha1(document: vscode.TextDocument): string { + return crypto + .createHash('sha1') + .update(document.getText(), 'utf8') + .digest('hex'); +} + // This method is called when your extension is activated. // Your extension is activated the very first time the command is executed. export async function activate(context: vscode.ExtensionContext) { @@ -92,6 +103,15 @@ export async function activate(context: vscode.ExtensionContext) { return; } + if ((Object.keys(documentHashMemory) as Array).includes(document.fileName)) { + // Check file content against memory, if it has not changed since last check do early return + const newHash = getDocumentSha1(document); + const oldHash = documentHashMemory[document.fileName]; + if (newHash === oldHash) { + return; + } + } + // Check if the document is visible in any editor const isVisible = vscode.window.visibleTextEditors.some(editor => editor.document.uri.toString().replaceAll('\\', '/') === document.uri.toString().replaceAll('\\', '/')); @@ -148,6 +168,10 @@ export async function activate(context: vscode.ExtensionContext) { minSevString, diagnosticCollection ); + + // Save hashed document content to memory + const hashedContentOfFile = getDocumentSha1(document); + documentHashMemory[document.fileName] = hashedContentOfFile; } // Listen for file saves. From be709ca3b4f8b81c519f9e9319401bfa9be39589 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Thu, 18 Jun 2026 14:00:12 +0200 Subject: [PATCH 2/3] only save hashed file if checks ran without error --- src/extension.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index bf02cb4..9f0613d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -123,7 +123,9 @@ export async function activate(context: vscode.ExtensionContext) { // Check file content against memory, if it has not changed since last check do early return const newHash = getDocumentSha1(document); const oldHash = documentHashMemory[document.fileName]; + console.log('documentHashMemory keys', Object.keys(documentHashMemory).join(', ')); if (newHash === oldHash) { + console.log('hash matched, skipping run', newHash); return; } } @@ -184,10 +186,6 @@ export async function activate(context: vscode.ExtensionContext) { minSevString, diagnosticCollection ); - - // Save hashed document content to memory - const hashedContentOfFile = getDocumentSha1(document); - documentHashMemory[document.fileName] = hashedContentOfFile; } // Listen for file saves. @@ -368,6 +366,13 @@ async function runCppcheckOnFileXML( } diagnosticCollection.set(document.uri, diagnostics); }); + + // If checks have run without error, save hashed document content to memory + if (!code) { + const hashedContentOfFile = getDocumentSha1(document); + console.log('checks ran succesfully, saving hashed file', document.fileName, hashedContentOfFile); + documentHashMemory[document.fileName] = hashedContentOfFile; + } }); checksRunning = false; From e9a06aef31f85ac0a8b5934615e6ea59cbb14055 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Mon, 22 Jun 2026 14:03:12 +0200 Subject: [PATCH 3/3] removed console ligs --- src/extension.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9f0613d..7e75948 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -123,9 +123,7 @@ export async function activate(context: vscode.ExtensionContext) { // Check file content against memory, if it has not changed since last check do early return const newHash = getDocumentSha1(document); const oldHash = documentHashMemory[document.fileName]; - console.log('documentHashMemory keys', Object.keys(documentHashMemory).join(', ')); if (newHash === oldHash) { - console.log('hash matched, skipping run', newHash); return; } } @@ -370,7 +368,6 @@ async function runCppcheckOnFileXML( // If checks have run without error, save hashed document content to memory if (!code) { const hashedContentOfFile = getDocumentSha1(document); - console.log('checks ran succesfully, saving hashed file', document.fileName, hashedContentOfFile); documentHashMemory[document.fileName] = hashedContentOfFile; } });