Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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<string, string> = {};

let previewAnalysisTimer: NodeJS.Timeout | undefined;
let previewedDocument: vscode.TextDocument | undefined;
let cppcheckProgressIndicator: vscode.StatusBarItem;
let checksRunning = false;

Expand Down Expand Up @@ -192,6 +194,39 @@ export async function activate(context: vscode.ExtensionContext) {
// Run cppcheck when a file is opened
vscode.workspace.onDidOpenTextDocument(handleDocument, null, context.subscriptions);

// Run cppcheck when changing files viewed in text editor
vscode.window.tabGroups.onDidChangeTabs(async e => {
clearTimeout(previewAnalysisTimer);
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);

// Clear diagnostics of previewed files when no longer viewed
vscode.window.onDidChangeActiveTextEditor(() => {
if (previewedDocument) {
diagnosticCollection.delete(previewedDocument.uri);
documentHashMemory[previewedDocument.fileName] = '';
previewedDocument = undefined;
}
});

// Run cppcheck for all open files when the workspace is opened
vscode.workspace.onDidChangeWorkspaceFolders(() => {
vscode.workspace.textDocuments.forEach(handleDocument);
Expand Down
Loading