From 272aa4c50b03386618aacad7ffbad9d85cf1e22d Mon Sep 17 00:00:00 2001 From: davidramnero Date: Wed, 17 Jun 2026 17:54:41 +0200 Subject: [PATCH] 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.