From 1e9549535d882982522cf0004050c59f95c657a5 Mon Sep 17 00:00:00 2001 From: Discookie Date: Tue, 18 Jul 2023 15:14:48 +0100 Subject: [PATCH 1/2] Rework UI to handle CodeChecker's autodetection It is now possible to run an analysis from the UI even if no compilation database is found by the plugin, only by CodeChecker --- src/backend/executor/bridge.ts | 9 ++-- src/editor/initialize.ts | 1 + src/sidebar/views/overview.ts | 94 ++++++++++++++++------------------ 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/src/backend/executor/bridge.ts b/src/backend/executor/bridge.ts index 8f4ddb6..4962516 100644 --- a/src/backend/executor/bridge.ts +++ b/src/backend/executor/bridge.ts @@ -233,8 +233,10 @@ export class ExecutorBridge implements Disposable { } } else if (files.length === 0) { // FIXME: Add a way to analyze all open workspaces, or a selected one + this._bridgeMessages.fire('>>> Using CodeChecker\'s built-in compilation database resolver\n'); args.push(workspace.workspaceFolders[0].uri.fsPath); } else if (files.length === 1) { + this._bridgeMessages.fire('>>> Using CodeChecker\'s built-in compilation database resolver\n'); args.push(files[0].fsPath); } else { // Fallback to autodetection @@ -286,6 +288,7 @@ export class ExecutorBridge implements Disposable { const logArguments = parseShellArgsAndReplaceVariables(logArgumentsSetting ?? ''); // Use a predefined path as fallback here + // TODO: Add handling for multi-root workspaces here by resolving the build command's target const ccCompileCmd = this.getCompileCommandsPath() ?? path.join(ccFolder, 'compile_commands.json'); return [ @@ -324,10 +327,9 @@ export class ExecutorBridge implements Disposable { private analyzeOnSave() { const canAnalyzeOnSave = workspace.getConfiguration('codechecker.executor').get('runOnSave'); - // Fail silently if there's no compile_commands.json - const ccExists = this.getCompileCommandsPath() !== undefined; - if (!canAnalyzeOnSave || !ccExists) { + // Analyze even if the comp.db doesn't exists, for multi-root workspaces + if (!canAnalyzeOnSave) { return; } @@ -372,6 +374,7 @@ export class ExecutorBridge implements Disposable { return; } + // FIXME: Add handling for missing comp.db. output messages of CodeChecker const process = new ScheduledProcess(ccPath, commandArgs, { processType: ProcessType.analyze }); ExtensionApi.executorManager.addToQueue(process, 'prepend'); diff --git a/src/editor/initialize.ts b/src/editor/initialize.ts index 3419f24..ca3e8d4 100644 --- a/src/editor/initialize.ts +++ b/src/editor/initialize.ts @@ -16,6 +16,7 @@ export class FolderInitializer { async showDialogIfAvailable() { if ( + // TODO: Don't show setup dialog for multi-root workspaces ExtensionApi.executorBridge.getCompileCommandsPath() === undefined && workspace.getConfiguration('codechecker.editor').get('showDatabaseDialog') !== false ) { diff --git a/src/sidebar/views/overview.ts b/src/sidebar/views/overview.ts index 28f8c73..a7ae919 100644 --- a/src/sidebar/views/overview.ts +++ b/src/sidebar/views/overview.ts @@ -80,32 +80,51 @@ export class OverviewView implements TreeDataProvider { ] }; + private middleItems = [ + new OverviewItem( + 'Reload CodeChecker metadata', + 'debug-restart', + { + title: 'reloadMetadata', + command: 'codechecker.backend.reloadMetadata', + } + ), + new OverviewItem( + 'Re-analyze current file', + 'run', + { + title: 'reloadMetadata', + command: 'codechecker.executor.analyzeCurrentFile', + }, + ), + new OverviewItem( + 'Re-analyze entire project', + 'run-all', + { + title: 'reloadMetadata', + command: 'codechecker.executor.analyzeProject', + } + ), + new OverviewItem( + 'Stop running CodeChecker instance', + 'debug-stop', + { + title: 'stopCodeChecker', + command: 'codechecker.executor.stopCodeChecker', + } + ), + new OverviewItem( + 'Clear analysis queue', + 'clear-all', + { + title: 'clearQueue', + command: 'codechecker.executor.clearQueue', + } + ), + ]; + private bottomItems: {[id: string]: OverviewItem[]} = { 'normal': [ - new OverviewItem( - 'Reload CodeChecker metadata', - 'debug-restart', - { - title: 'reloadMetadata', - command: 'codechecker.backend.reloadMetadata', - } - ), - new OverviewItem( - 'Re-analyze current file', - 'run', - { - title: 'reloadMetadata', - command: 'codechecker.executor.analyzeCurrentFile', - }, - ), - new OverviewItem( - 'Re-analyze entire project', - 'run-all', - { - title: 'reloadMetadata', - command: 'codechecker.executor.analyzeProject', - } - ), new OverviewItem( 'Re-run CodeChecker log', 'list-flat', @@ -122,22 +141,6 @@ export class OverviewView implements TreeDataProvider { command: 'codechecker.executor.previewLogInTerminal' } ), - new OverviewItem( - 'Stop running CodeChecker instance', - 'debug-stop', - { - title: 'stopCodeChecker', - command: 'codechecker.executor.stopCodeChecker', - } - ), - new OverviewItem( - 'Clear analysis queue', - 'clear-all', - { - title: 'clearQueue', - command: 'codechecker.executor.clearQueue', - } - ), ], 'ccNotFound': [ new OverviewItem( @@ -148,15 +151,6 @@ export class OverviewView implements TreeDataProvider { command: 'codechecker.editor.showSetupDialog' } ), - new OverviewItem('——'), - new OverviewItem( - 'Reload CodeChecker metadata', - 'debug-restart', - { - title: 'reloadMetadata', - command: 'codechecker.backend.reloadMetadata', - } - ), new OverviewItem( 'Run CodeChecker log', 'list-flat', @@ -212,7 +206,7 @@ export class OverviewView implements TreeDataProvider { ? this.bottomItems.normal : this.bottomItems.ccNotFound; - this.itemsList = [topItems, this.separator, bottomItems]; + this.itemsList = [topItems, this.separator, this.middleItems, this.separator, bottomItems]; this._onDidChangeTreeData.fire(); } From 3362854e9e4673e80873c90a7c45c1cca39c8cba Mon Sep 17 00:00:00 2001 From: Discookie Date: Tue, 18 Jul 2023 16:31:21 +0100 Subject: [PATCH 2/2] Fix exceptions on first run --- src/backend/processor/metadata.ts | 5 +++-- src/editor/notifications.ts | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/processor/metadata.ts b/src/backend/processor/metadata.ts index 0b0d0ca..e3a979c 100644 --- a/src/backend/processor/metadata.ts +++ b/src/backend/processor/metadata.ts @@ -128,7 +128,8 @@ export class MetadataApi implements Disposable { let precheckFailed = false; if (!this.metadataPath) { - Editor.notificationHandler.showNotification( + // When the constructor calls this function, the notification handler is not yet initialized + Editor.notificationHandler?.showNotification( NotificationType.warning, 'Metadata folder has invalid path\n' + 'Please change `CodeChecker > Backend > Output folder path` in the settings' @@ -138,7 +139,7 @@ export class MetadataApi implements Disposable { } if (!workspace.workspaceFolders?.length) { - Editor.notificationHandler.showNotification( + Editor.notificationHandler?.showNotification( NotificationType.information, 'CodeChecker is disabled - open a workspace to get started', { showOnTray: false } diff --git a/src/editor/notifications.ts b/src/editor/notifications.ts index 6ea8f6c..cb41433 100644 --- a/src/editor/notifications.ts +++ b/src/editor/notifications.ts @@ -45,7 +45,10 @@ export class NotificationHandler { }; if (options.showOnSidebar) { - SidebarContainer.notificationView.addNotification(type, options.sidebarMessage ?? message, options.choices); + // When the constructor calls this function, the sidebar is not yet initialized + SidebarContainer.notificationView?.addNotification( + type, options.sidebarMessage ?? message, options.choices + ); } if (options.showOnTray === 'always' || (options.showOnTray && this.showTrayNotifications)) {