Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
"code analysis"
],
"activationEvents": [
"onCommand:codechecker.backend.reloadMetadata",
"onView:codechecker.views.overview",
"onFileSystem:file"
"onStartupFinished"
],
"main": "./dist/extension.js",
"contributes": {
Expand Down
23 changes: 14 additions & 9 deletions src/backend/executor/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", ...}
Expand Down Expand Up @@ -116,8 +118,10 @@ export class ExecutorBridge implements Disposable {
ExtensionApi.executorManager
));

this.updateCompilationDatabasePaths();
this.checkVersion();
if (state.workspaceSupported) {
this.updateCompilationDatabasePaths();
this.checkVersion();
}
}

dispose() {
Expand Down Expand Up @@ -387,13 +391,13 @@ export class ExecutorBridge implements Disposable {
public async analyzeCurrentFile() {
const currentFile = window.activeTextEditor?.document.uri;

if (currentFile !== undefined) {
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;
}

Expand All @@ -411,7 +415,7 @@ export class ExecutorBridge implements Disposable {
}

public async analyzeProject() {
if (!await this.checkVersion()) {
if (!state.workspaceSupported || !await this.checkVersion()) {
return;
}

Expand All @@ -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.');
Expand Down Expand Up @@ -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;
}

Expand All @@ -599,7 +604,7 @@ export class ExecutorBridge implements Disposable {
}

public async reloadCheckerData() {
if (!await this.checkVersion()) {
if (!state.workspaceSupported || !await this.checkVersion()) {
return;
}

Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/editor/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,6 +16,8 @@ export function activate(context: vscode.ExtensionContext): CodeCheckerExtension
Editor.init(context);
SidebarContainer.init(context);

checkWorkspace();

console.log('Extension "codechecker" activated');

return {
Expand Down
42 changes: 42 additions & 0 deletions src/utils/files.ts
Original file line number Diff line number Diff line change
@@ -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.`);
}
}
5 changes: 5 additions & 0 deletions src/utils/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class ExtensionState {
public workspaceSupported = false;
}

export const state = new ExtensionState();
Loading