From 3a5dcfda1b0f77a44901a3b536d0f724c19aa7c1 Mon Sep 17 00:00:00 2001 From: Magyarimiki <249292183+Magyarimiki@users.noreply.github.com> Date: Thu, 18 Jun 2026 17:46:43 +0200 Subject: [PATCH 1/2] Do not analyze unsupported files on save Signed-off-by: Magyarimiki <249292183+Magyarimiki@users.noreply.github.com> --- src/backend/executor/bridge.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/bridge.ts b/src/backend/executor/bridge.ts index 9bbc236..3b0800f 100644 --- a/src/backend/executor/bridge.ts +++ b/src/backend/executor/bridge.ts @@ -387,7 +387,7 @@ export class ExecutorBridge implements Disposable { public async analyzeCurrentFile() { const currentFile = window.activeTextEditor?.document.uri; - if (currentFile !== undefined) { + if (currentFile !== undefined && this.isSupportedFile(currentFile)) { await this.analyzeFile(currentFile); } } @@ -928,4 +928,19 @@ export class ExecutorBridge implements Disposable { this._databaseLocationChanged.fire(); } + + private isSupportedFile(uri: Uri | undefined): boolean { + if (uri === undefined) { + return false; + } + + const extensions = [ + '.c', + '.cc', + '.cpp', + '.cxx' + ]; + + return extensions.find(ext => uri.path.endsWith(ext)) !== undefined; + } } \ No newline at end of file From f92fde4a20e66bd6144cf748c25a3a9da0e9b97b Mon Sep 17 00:00:00 2001 From: Magyarimiki <249292183+Magyarimiki@users.noreply.github.com> Date: Fri, 19 Jun 2026 13:15:08 +0200 Subject: [PATCH 2/2] Prevent actions when no supported files present Signed-off-by: Magyarimiki <249292183+Magyarimiki@users.noreply.github.com> --- package.json | 4 +--- src/backend/executor/bridge.ts | 38 ++++++++++++------------------ src/editor/initialize.ts | 3 ++- src/extension.ts | 3 +++ src/utils/files.ts | 42 ++++++++++++++++++++++++++++++++++ src/utils/state.ts | 5 ++++ 6 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 src/utils/files.ts create mode 100644 src/utils/state.ts diff --git a/package.json b/package.json index 8e8e5cb..c3f84b3 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,7 @@ "code analysis" ], "activationEvents": [ - "onCommand:codechecker.backend.reloadMetadata", - "onView:codechecker.views.overview", - "onFileSystem:file" + "onStartupFinished" ], "main": "./dist/extension.js", "contributes": { diff --git a/src/backend/executor/bridge.ts b/src/backend/executor/bridge.ts index 3b0800f..65ed938 100644 --- a/src/backend/executor/bridge.ts +++ b/src/backend/executor/bridge.ts @@ -25,6 +25,8 @@ import { NotificationType } from '../../editor/notifications'; import { Editor } from '../../editor'; import { SidebarContainer } from '../../sidebar'; import { ReportTreeItem } from '../../sidebar/views'; +import { isSupportedFile } from '../../utils/files'; +import { state } from '../../utils/state'; // Structure: // CodeChecker analyzer version: \n {"base_package_version": "M.m.p", ...} @@ -116,8 +118,10 @@ export class ExecutorBridge implements Disposable { ExtensionApi.executorManager )); - this.updateCompilationDatabasePaths(); - this.checkVersion(); + if (state.workspaceSupported) { + this.updateCompilationDatabasePaths(); + this.checkVersion(); + } } dispose() { @@ -387,13 +391,13 @@ export class ExecutorBridge implements Disposable { public async analyzeCurrentFile() { const currentFile = window.activeTextEditor?.document.uri; - if (currentFile !== undefined && this.isSupportedFile(currentFile)) { + if (currentFile !== undefined && isSupportedFile(currentFile)) { await this.analyzeFile(currentFile); } } public async analyzeFile(file: Uri) { - if (!await this.checkVersion()) { + if (!state.workspaceSupported || !await this.checkVersion()) { return; } @@ -411,7 +415,7 @@ export class ExecutorBridge implements Disposable { } public async analyzeProject() { - if (!await this.checkVersion()) { + if (!state.workspaceSupported || !await this.checkVersion()) { return; } @@ -431,9 +435,10 @@ export class ExecutorBridge implements Disposable { } public async getFileAnalysisStatus() { - if (!await this.checkVersion()) { + if (!state.workspaceSupported || !await this.checkVersion()) { return; } + if (this.checkedVersion < [ 6, 27, 0 ]) { const statusNode = SidebarContainer.reportsView.getNodeById('statusItem'); statusNode?.setLabelAndIcon('Status report requires CodeChecker 6.27.0 or higher.'); @@ -579,7 +584,7 @@ export class ExecutorBridge implements Disposable { } public async runLog(buildCommand?: string) { - if (!await this.checkVersion()) { + if (!state.workspaceSupported || !await this.checkVersion()) { return; } @@ -599,7 +604,7 @@ export class ExecutorBridge implements Disposable { } public async reloadCheckerData() { - if (!await this.checkVersion()) { + if (!state.workspaceSupported || !await this.checkVersion()) { return; } @@ -642,7 +647,7 @@ export class ExecutorBridge implements Disposable { } public async parseMetadata(...files: Uri[]) { - if (!await this.checkVersion()) { + if (!state.workspaceSupported || !await this.checkVersion()) { return; } @@ -928,19 +933,4 @@ export class ExecutorBridge implements Disposable { this._databaseLocationChanged.fire(); } - - private isSupportedFile(uri: Uri | undefined): boolean { - if (uri === undefined) { - return false; - } - - const extensions = [ - '.c', - '.cc', - '.cpp', - '.cxx' - ]; - - return extensions.find(ext => uri.path.endsWith(ext)) !== undefined; - } } \ No newline at end of file diff --git a/src/editor/initialize.ts b/src/editor/initialize.ts index 033563e..9e2de08 100644 --- a/src/editor/initialize.ts +++ b/src/editor/initialize.ts @@ -2,6 +2,7 @@ import { ExtensionContext, Uri, commands, window, workspace } from 'vscode'; import { ExtensionApi } from '../backend'; import { Editor } from './editor'; import { NotificationType } from './notifications'; +import { state } from '../utils/state'; export class FolderInitializer { constructor(_ctx: ExtensionContext) { @@ -27,7 +28,7 @@ export class FolderInitializer { async showDialog() { const workspaceFolder = workspace.workspaceFolders?.length && workspace.workspaceFolders[0].uri; - if (!workspaceFolder) { + if (!workspaceFolder || !state.workspaceSupported) { return; } diff --git a/src/extension.ts b/src/extension.ts index 1f92754..5e38cd0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import * as vscode from 'vscode'; import { ExtensionApi } from './backend'; import { Editor } from './editor'; import { SidebarContainer } from './sidebar'; +import { checkWorkspace } from './utils/files'; export interface CodeCheckerExtension { extensionApi: typeof ExtensionApi, @@ -15,6 +16,8 @@ export function activate(context: vscode.ExtensionContext): CodeCheckerExtension Editor.init(context); SidebarContainer.init(context); + checkWorkspace(); + console.log('Extension "codechecker" activated'); return { diff --git a/src/utils/files.ts b/src/utils/files.ts new file mode 100644 index 0000000..53e0920 --- /dev/null +++ b/src/utils/files.ts @@ -0,0 +1,42 @@ +import { Uri, workspace } from 'vscode'; +import { state } from './state'; + +const EXTENSIONS = [ + '.c', + '.cc', + '.cpp', + '.cxx' +]; + +export function isSupportedFile(uri: Uri | undefined): boolean { + if (uri === undefined) { + return false; + } + + return EXTENSIONS.find(ext => uri.path.endsWith(ext)) !== undefined; +} + +export async function isSupportedWorkspace() { + const supported = await workspace.findFiles( + `**/*.{${EXTENSIONS.join(',')}}`, + '**/{node_modules,.git}/**', + 1 + ); + + return supported.length > 1; +} + +export async function checkWorkspace() { + if (workspace.name === undefined) { + state.workspaceSupported = false; + console.log('No open workspace.'); + return; + } + const supported = await isSupportedWorkspace(); + if (supported) { + state.workspaceSupported = true; + } else { + state.workspaceSupported = false; + console.log(`workspace ${workspace.name} does not contain supported files.`); + } +} \ No newline at end of file diff --git a/src/utils/state.ts b/src/utils/state.ts new file mode 100644 index 0000000..f389cef --- /dev/null +++ b/src/utils/state.ts @@ -0,0 +1,5 @@ +export class ExtensionState { + public workspaceSupported = false; +} + +export const state = new ExtensionState(); \ No newline at end of file