Skip to content

Commit

Permalink
Merge pull request #130 from Discookie/ericsson/multiroot-ui
Browse files Browse the repository at this point in the history
Rework UI to handle CodeChecker's autodetection
  • Loading branch information
vodorok authored Jul 18, 2023
2 parents 1b06408 + 3362854 commit 8a81e21
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 56 deletions.
9 changes: 6 additions & 3 deletions src/backend/executor/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -324,10 +327,9 @@ export class ExecutorBridge implements Disposable {

private analyzeOnSave() {
const canAnalyzeOnSave = workspace.getConfiguration('codechecker.executor').get<boolean>('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;
}

Expand Down Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions src/backend/processor/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions src/editor/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
5 changes: 4 additions & 1 deletion src/editor/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
94 changes: 44 additions & 50 deletions src/sidebar/views/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,51 @@ export class OverviewView implements TreeDataProvider<OverviewItem> {
]
};

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',
Expand All @@ -122,22 +141,6 @@ export class OverviewView implements TreeDataProvider<OverviewItem> {
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(
Expand All @@ -148,15 +151,6 @@ export class OverviewView implements TreeDataProvider<OverviewItem> {
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',
Expand Down Expand Up @@ -212,7 +206,7 @@ export class OverviewView implements TreeDataProvider<OverviewItem> {
? 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();
}
Expand Down

0 comments on commit 8a81e21

Please sign in to comment.