Skip to content

Commit

Permalink
Merge pull request #114 from Discookie/ericsson/fix-killed-version-check
Browse files Browse the repository at this point in the history
Improvements for handling CodeChecker version checks
  • Loading branch information
vodorok authored Aug 12, 2022
2 parents 8013ae8 + 04ddd49 commit 6ab1f02
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 22 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"description": "Enable CodeLens for displaying the reproduction path",
"default": true
},
"codechecker.executor.enableNotifications": {
"type": "boolean",
"description": "Enable CodeChecker-related notifications",
"default": true
},
"codechecker.executor.runOnSave": {
"type": "boolean",
"description": "Controls auto-run of CodeChecker on save",
Expand Down
50 changes: 42 additions & 8 deletions src/backend/executor/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
import * as fs from 'fs';
import * as path from 'path';
import { ExtensionApi } from '../api';
import { getConfigAndReplaceVariables, parseShellArgsAndReplaceVariables, replaceVariables } from '../../utils/config';
import {
getConfigAndReplaceVariables,
parseShellArgsAndReplaceVariables,
replaceVariables,
shouldShowNotifications
} from '../../utils/config';
import { ProcessStatus, ProcessType, ScheduledProcess } from '.';

// Structure:
Expand All @@ -31,6 +36,12 @@ interface AnalyzerVersion {
export class ExecutorBridge implements Disposable {
private versionChecked = false;
private shownVersionWarning = false;
private versionCheckInProgress = false;

private _versionCheckFinished: EventEmitter<boolean> = new EventEmitter();
private get versionCheckFinished(): Event<boolean> {
return this._versionCheckFinished.event;
}

private databaseWatches: FileSystemWatcher[] = [];
private databaseEvents: Disposable[] = [];
Expand All @@ -51,6 +62,7 @@ export class ExecutorBridge implements Disposable {
return this._databaseLocationChanged.event;
}


/** Automatically adds itself to ctx.subscriptions. */
constructor(ctx: ExtensionContext) {
ctx.subscriptions.push(this);
Expand Down Expand Up @@ -142,7 +154,10 @@ export class ExecutorBridge implements Disposable {
const ccCompileCmd = this.getCompileCommandsPath();

if (ccCompileCmd === undefined) {
window.showWarningMessage('No compilation database found, CodeChecker not started - see logs for details');
if (shouldShowNotifications()) {
window.showWarningMessage(
'No compilation database found, CodeChecker not started - see logs for details');
}
return undefined;
}

Expand Down Expand Up @@ -389,13 +404,26 @@ export class ExecutorBridge implements Disposable {
return;
}

if (this.versionCheckInProgress) {
const disposable = this.versionCheckFinished((result) => {
disposable.dispose();
res(result);
});
return;
}

this.versionCheckInProgress = true;
const ccPath = getConfigAndReplaceVariables('codechecker.executor', 'executablePath') || 'CodeChecker';
const commandArgs = this.getVersionCmdArgs();

if (commandArgs === undefined) {
this._bridgeMessages.fire('>>> Unable to determine CodeChecker version commandline\n');

this.versionChecked = false;

this.versionCheckInProgress = false;
this._versionCheckFinished.fire(this.versionChecked);

res(this.versionChecked);
return;
}
Expand Down Expand Up @@ -427,7 +455,7 @@ export class ExecutorBridge implements Disposable {

this.versionChecked = false;

if (!this.shownVersionWarning) {
if (shouldShowNotifications() && !this.shownVersionWarning) {
this.shownVersionWarning = true;
let choice;

Expand Down Expand Up @@ -473,7 +501,7 @@ export class ExecutorBridge implements Disposable {

this.versionChecked = true;

if (this.shownVersionWarning) {
if (shouldShowNotifications() && this.shownVersionWarning) {
this.shownVersionWarning = false;

window.showInformationMessage(
Expand All @@ -485,9 +513,11 @@ export class ExecutorBridge implements Disposable {
this._bridgeMessages.fire(`>>> Internal error while checking version: ${err}\n`);
this.versionChecked = false;

window.showErrorMessage(
'CodeChecker: Internal error while checking version - see logs for details'
);
if (shouldShowNotifications()) {
window.showErrorMessage(
'CodeChecker: Internal error while checking version - see logs for details'
);
}
}

break;
Expand All @@ -501,8 +531,9 @@ export class ExecutorBridge implements Disposable {
this._bridgeMessages.fire('>>> CodeChecker error while checking version\n');
this.versionChecked = false;

if (!this.shownVersionWarning) {
if (shouldShowNotifications() && !this.shownVersionWarning) {
this.shownVersionWarning = true;

let choice;

while (choice !== 'Close') {
Expand Down Expand Up @@ -542,6 +573,9 @@ export class ExecutorBridge implements Disposable {
}
}

this.versionCheckInProgress = false;
this._versionCheckFinished.fire(this.versionChecked);

res(this.versionChecked);
});

Expand Down
10 changes: 7 additions & 3 deletions src/backend/processor/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Event, EventEmitter, ExtensionContext, TextEditor, Uri, window } from '
import { parseDiagnostics } from '../parser';
import { CheckerMetadata, DiagnosticReport } from '../types';
import { ExtensionApi } from '../api';
import { shouldShowNotifications } from '../../utils/config';

/**
* API interface that provides Diagnostics data.
Expand Down Expand Up @@ -98,9 +99,12 @@ export class DiagnosticsApi {
} catch (err: any) {
console.error('Failed to read CodeChecker data');
console.error(err);
window.showErrorMessage(
'Failed to read some CodeChecker diagnostic data\nCheck console for more details'
);

if (shouldShowNotifications()) {
window.showErrorMessage(
'Failed to read some CodeChecker diagnostic data\nCheck console for more details'
);
}
return;
}

Expand Down
36 changes: 27 additions & 9 deletions src/backend/processor/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import * as path from 'path';
import { parseMetadata } from '../parser';
import { CheckerMetadata } from '../types';
import { shouldShowNotifications } from '../../utils/config';

export class MetadataApi implements Disposable {
private _metadata?: CheckerMetadata;
Expand Down Expand Up @@ -98,7 +99,10 @@ export class MetadataApi implements Disposable {
this.reloadMetadata()
.catch((err) => {
console.log(err);
window.showErrorMessage('Unexpected error when reloading metadata\nCheck console for more details');

if (shouldShowNotifications()) {
window.showErrorMessage('Unexpected error when reloading metadata\nCheck console for more details');
}
});
}

Expand All @@ -113,16 +117,20 @@ export class MetadataApi implements Disposable {
let precheckFailed = false;

if (!this.metadataPath) {
window.showWarningMessage(
'Metadata folder has invalid path\n' +
'Please change `CodeChecker > Backend > Output folder path` in the settings'
);
if (shouldShowNotifications()) {
window.showWarningMessage(
'Metadata folder has invalid path\n' +
'Please change `CodeChecker > Backend > Output folder path` in the settings'
);
}

precheckFailed = true;
}

if (!workspace.workspaceFolders?.length) {
window.showInformationMessage('CodeChecker is disabled - open a workspace to get started');
if (shouldShowNotifications()) {
window.showInformationMessage('CodeChecker is disabled - open a workspace to get started');
}

precheckFailed = true;
}
Expand All @@ -147,20 +155,30 @@ export class MetadataApi implements Disposable {
// For parse errors, print the message instead
case 'UnsupportedVersion':
console.error(err);
window.showErrorMessage(`Failed to read CodeChecker metadata: ${err.message}`);

if (shouldShowNotifications()) {
window.showErrorMessage(`Failed to read CodeChecker metadata: ${err.message}`);
}

break;

default:
console.error(err);

// File format errors
if (err instanceof SyntaxError) {
window.showErrorMessage('Failed to read CodeChecker metadata: Invalid format');
if (shouldShowNotifications()) {
window.showErrorMessage('Failed to read CodeChecker metadata: Invalid format');
}

break;
}

// Misc. errors
window.showErrorMessage('Failed to read CodeChecker metadata\nCheck console for more details');
if (shouldShowNotifications()) {
window.showErrorMessage('Failed to read CodeChecker metadata\nCheck console for more details');
}

break;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/editor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { Editor } from '.';
import { ExtensionApi } from '../backend';
import { ProcessStatus } from '../backend/executor/process';
import { getConfigAndReplaceVariables } from '../utils/config';
import { getConfigAndReplaceVariables, shouldShowNotifications } from '../utils/config';

export class ExecutorAlerts {
private statusBarItem: StatusBarItem;
Expand Down Expand Up @@ -110,7 +110,10 @@ export class ExecutorAlerts {
break;
case ProcessStatus.errored:
this.statusBarItem.text = '$(testing-error-icon) CodeChecker: analysis errored';
window.showErrorMessage('CodeChecker finished with error - see logs for details');

if (shouldShowNotifications()) {
window.showErrorMessage('CodeChecker finished with error - see logs for details');
}
break;
default:
break;
Expand Down
5 changes: 5 additions & 0 deletions src/editor/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExtensionContext, commands, window, workspace } from 'vscode';
import { ExtensionApi } from '../backend';
import { shouldShowNotifications } from '../utils/config';
import { Editor } from './editor';

export class FolderInitializer {
Expand All @@ -20,6 +21,10 @@ export class FolderInitializer {
}

async showDialog() {
if (!shouldShowNotifications()) {
return;
}

const workspaceFolder = workspace.workspaceFolders?.length && workspace.workspaceFolders[0].uri;

if (!workspaceFolder) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export function replaceVariables(pathLike?: string): string | undefined {
.replace(/\${cwd}/g, process.cwd())
.replace(/\${env\.([^}]+)}/g, (sub: string, envName: string) => process.env[envName] ?? '');
}

export function shouldShowNotifications(): boolean {
return workspace.getConfiguration('codechecker.executor').get<boolean>('enableNotifications') ?? true;
}

0 comments on commit 6ab1f02

Please sign in to comment.