Skip to content

Commit

Permalink
Move QBS project configuration data to qbstypes.ts file
Browse files Browse the repository at this point in the history
... and use all data types from this file.
  • Loading branch information
denis-shienkov committed Oct 31, 2020
1 parent a2055bb commit 98fa497
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 116 deletions.
40 changes: 12 additions & 28 deletions src/qbsproject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {basename} from 'path';
import * as QbsUtils from './qbsutils';

import {QbsSession} from './qbssession';
import {QbsBuildStep, QbsRunStep, QbsProduct, QbsRunEnvironment} from './qbssteps';
import {QbsBuildStep, QbsRunStep} from './qbssteps';
import {QbsProjectData, QbsProductData, QbsRunEnvironmentData} from './qbstypes';

export class QbsProject implements vscode.Disposable {
private _data?: any;
private _data?: QbsProjectData;
private _buildStep: QbsBuildStep = new QbsBuildStep(this);
private _runStep: QbsRunStep = new QbsRunStep(this);

Expand All @@ -23,39 +24,22 @@ export class QbsProject implements vscode.Disposable {
name(): string { return this._uri ? basename(this._uri.fsPath) : 'unknown'; }
filePath(): string { return QbsUtils.fixPathSeparators(this._uri?.fsPath || ''); }

async setData(response: any, withBuildSystemFiles: boolean) {
const data = response['project-data'];
if (data) {
this._data = data;
async setData(data: QbsProjectData, withBuildSystemFiles: boolean) {
if (!data.isEmpty()) {
const buildSystemFiles = this._data?.buildSystemFiles();
if (!withBuildSystemFiles) {
this._data['build-system-files'] = data['build-system-files'];
data.setBuildSystemFiles(buildSystemFiles);
}
this._data = data;
}
}

data(): any | undefined { return this._data; }
setRunEnvironment(env: QbsRunEnvironment) { this._runStep.setup(undefined, undefined, env); }
data(): QbsProjectData | undefined { return this._data; }
setRunEnvironment(env: QbsRunEnvironmentData) { this._runStep.setup(undefined, undefined, env); }
buildStep(): QbsBuildStep { return this._buildStep; }
runStep(): QbsRunStep { return this._runStep; }
isEmpty(): boolean { return this._data; }

async enumerateProducts(): Promise<QbsProduct[]> {
const products: QbsProduct[] = [];
const parseProject = async (project: any) => {
const datas = project ? (project['products'] || []) : [];
for (const data of datas) {
const product = new QbsProduct(data);
products.push(product);
}

const subProjects = project ? (project['sub-projects'] || []) : [];
for (const subProject of subProjects) {
await parseProject(subProject);
}
};
await parseProject(this._data);
return products;
}
isEmpty(): boolean { return this._data ? true : false; }
products(): QbsProductData[] { return this._data?.products() || []; }

async updateSteps() {
await this._buildStep.restore();
Expand Down
5 changes: 2 additions & 3 deletions src/qbsprojectexplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ class QbsProjectDataProvider implements vscode.TreeDataProvider<BaseNode> {
if (node) {
return node.getChildren();
}
const data = this._session.project()?.data();
if (data) {
const project = new QbsProjectData(data);
const project = this._session.project()?.data();
if (project) {
return [ new QbsProjectNode(project, true) ];
}
return [];
Expand Down
20 changes: 10 additions & 10 deletions src/qbsselectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {basename} from 'path';

import {QbsSession} from './qbssession';
import {QbsProject} from './qbsproject';
import {QbsProfile, QbsConfig, QbsProduct, QbsDebugger} from './qbssteps';
import {QbsProfileData, QbsConfigData, QbsProductData, QbsDebuggerData} from './qbstypes';

export async function displayWorkspaceProjectSelector(session: QbsSession) {
const projects = await QbsProject.enumerateWorkspaceProjects();
Expand All @@ -25,7 +25,7 @@ export async function displayWorkspaceProjectSelector(session: QbsSession) {
export async function displayProfileSelector(session: QbsSession) {
const profiles = await session.settings().enumerateProfiles();
interface QbsProfileQuickPickItem extends vscode.QuickPickItem {
profile: QbsProfile;
profile: QbsProfileData;
}
const items: QbsProfileQuickPickItem[] = profiles.map(profile => {
return {
Expand All @@ -42,7 +42,7 @@ export async function displayProfileSelector(session: QbsSession) {
export async function displayConfigurationSelector(session: QbsSession) {
const configurations = await session.settings().enumerateConfigurations();
interface QbsConfigQuickPickItem extends vscode.QuickPickItem {
configuration: QbsConfig;
configuration: QbsConfigData;
}
const items: QbsConfigQuickPickItem[] = configurations.map(configuration => {
return {
Expand All @@ -62,17 +62,17 @@ export async function displayConfigurationSelector(session: QbsSession) {
placeHolder: 'Enter custom configuration name',
});
const selectedCustomConfiguration = customConfigurationName
? new QbsConfig(customConfigurationName) : undefined;
? new QbsConfigData(customConfigurationName) : undefined;
session.project()?.buildStep().setup(undefined, selectedCustomConfiguration, undefined);
}
}

export async function displayBuildProductSelector(session: QbsSession) {
const products = [
new QbsProduct('all')
].concat(await session.project()?.enumerateProducts() || []);
new QbsProductData('all')
].concat(session.project()?.products() || []);
interface QbsProductQuickPickItem extends vscode.QuickPickItem {
product: QbsProduct;
product: QbsProductData;
}
const items: QbsProductQuickPickItem[] = products?.map(product => {
return {
Expand All @@ -87,10 +87,10 @@ export async function displayBuildProductSelector(session: QbsSession) {
}

export async function displayRunProductSelector(session: QbsSession) {
const products = (await session.project()?.enumerateProducts() || [])
const products = (session.project()?.products() || [])
.filter(product => product.isRunnable());
interface QbsProductQuickPickItem extends vscode.QuickPickItem {
product: QbsProduct;
product: QbsProductData;
}
const items: QbsProductQuickPickItem[] = products.map(product => {
return {
Expand All @@ -107,7 +107,7 @@ export async function displayRunProductSelector(session: QbsSession) {
export async function displayDebuggerSelector(session: QbsSession) {
const dbgs = (await session.settings().enumerateDebuggers()) || [];
interface QbsDebuggerQuickPickItem extends vscode.QuickPickItem {
dbg: QbsDebugger;
dbg: QbsDebuggerData;
}
const items: QbsDebuggerQuickPickItem[] = dbgs.map(dbg => {
return {
Expand Down
13 changes: 7 additions & 6 deletions src/qbssession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import * as vscode from 'vscode';
import * as nls from 'vscode-nls';

import {QbsProject} from './qbsproject';
import {QbsRunEnvironment} from './qbssteps';
import {QbsSettings, QbsSettingsEvent} from './qbssettings';
import {
QbsSessionProtocol, QbsSessionProtocolStatus
} from './qbssessionprotocol';
import {
QbsOperation,
QbsOperation, QbsRunEnvironmentData,
// Protocol requests.
QbsGetRunEnvironmentRequest, QbsRequest,
// Protocol responses.
QbsHelloResponse, QbsProcessResponse,
QbsTaskStartedResponse, QbsTaskProgressResponse,
QbsTaskMaxProgressResponse, QbsMessageResponse
QbsTaskMaxProgressResponse, QbsMessageResponse, QbsProjectData
} from './qbstypes';

const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -211,12 +210,14 @@ export class QbsSession implements vscode.Disposable {
const result = new QbsHelloResponse(response)
this._onHelloReceived.fire(result);
} else if (type === 'project-resolved') {
await this._project?.setData(response, true);
const data = new QbsProjectData(response['project-data']);
await this._project?.setData(data, true);
await this._project?.updateSteps();
const result = new QbsMessageResponse(response['error']);
this._onProjectResolved.fire(result);
} else if (type === 'project-built' || type === 'build-done') {
await this._project?.setData(response, false);
const data = new QbsProjectData(response['project-data']);
await this._project?.setData(data, false);
await this._project?.updateSteps();
const result = new QbsMessageResponse(response['error']);
this._onProjectBuilt.fire(result);
Expand Down Expand Up @@ -253,7 +254,7 @@ export class QbsSession implements vscode.Disposable {
const result = new QbsProcessResponse(response);
this._onProcessResultReceived.fire(result);
} else if (type === 'run-environment') {
const env = new QbsRunEnvironment(response['full-environment']);
const env = new QbsRunEnvironmentData(response['full-environment']);
this._project?.setRunEnvironment(env);
const result = new QbsMessageResponse(response['error']);
this._onRunEnvironmentResultReceived.fire(result);
Expand Down
26 changes: 13 additions & 13 deletions src/qbssettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as cp from 'child_process';
import * as QbsUtils from './qbsutils';

import {QbsSession} from './qbssession';
import {QbsProfile, QbsConfig, QbsDebugger} from './qbssteps';
import {QbsProfileData, QbsConfigData, QbsDebuggerData} from './qbstypes';

const localize: nls.LocalizeFunc = nls.loadMessageBundle();

Expand Down Expand Up @@ -197,8 +197,8 @@ export class QbsSettings implements vscode.Disposable {
*
* @note This function calls the Qbs executable and parses the output.
*/
async enumerateProfiles(): Promise<QbsProfile[]> {
return new Promise<QbsProfile[]>((resolve, reject) => {
async enumerateProfiles(): Promise<QbsProfileData[]> {
return new Promise<QbsProfileData[]>((resolve, reject) => {
const qbsPath = this.executablePath();
if (!qbsPath) {
reject(undefined);
Expand All @@ -212,15 +212,15 @@ export class QbsSettings implements vscode.Disposable {
if (error) {
reject(undefined);
} else {
const profiles: QbsProfile[] = [];
const profiles: QbsProfileData[] = [];
stdout.split('\n').map(function (line) {
if (!line.startsWith('profiles'))
return;
const startIndex = line.indexOf('.');
if (startIndex !== -1) {
const endIndex = line.indexOf('.', startIndex + 1);
if (endIndex != -1) {
const profile = new QbsProfile(line.substring(startIndex + 1, endIndex));
const profile = new QbsProfileData(line.substring(startIndex + 1, endIndex));
if (profiles.map(profile => profile.name()).indexOf(profile.name()) === -1)
profiles.push(profile);
}
Expand All @@ -239,19 +239,19 @@ export class QbsSettings implements vscode.Disposable {
* @note Right now these are just two hardcoded configurations
* @c debug and @c release.
*/
async enumerateConfigurations(): Promise<QbsConfig[]> {
async enumerateConfigurations(): Promise<QbsConfigData[]> {
const configurations = [];
configurations.push(new QbsConfig(
configurations.push(new QbsConfigData(
'debug',
localize('qbs.configuration.debug.label', 'Debug'),
localize('qbs.configuration.debug.description', 'Disable optimizations.'))
);
configurations.push(new QbsConfig(
configurations.push(new QbsConfigData(
'release',
localize('qbs.configuration.release.label', 'Release'),
localize('qbs.configuration.release.description', 'Enable optimizations.'))
);
configurations.push(new QbsConfig(
configurations.push(new QbsConfigData(
'custom',
localize('qbs.configuration.custom.label', '[Custom]'),
localize('qbs.configuration.custom.description', 'Custom configuration.'))
Expand All @@ -263,16 +263,16 @@ export class QbsSettings implements vscode.Disposable {
* Returns the list of all available debug configurations
* stored in the 'launch.json' files.
*/
async enumerateDebuggers(): Promise<QbsDebugger[]> {
return new Promise<QbsDebugger[]>((resolve, reject) => {
async enumerateDebuggers(): Promise<QbsDebuggerData[]> {
return new Promise<QbsDebuggerData[]>((resolve, reject) => {
const settingsPath = this.debuggerSettingsPath();
fs.readFile(settingsPath, (error, data) => {
const debuggers: QbsDebugger[] = [];
const debuggers: QbsDebuggerData[] = [];
try {
const json = JSON.parse(data.toString());
const configurations = (json['configurations'] || []);
for (const configuration of configurations) {
debuggers.push(new QbsDebugger(configuration));
debuggers.push(new QbsDebuggerData(configuration));
}
} catch (e) {
}
Expand Down
Loading

0 comments on commit 98fa497

Please sign in to comment.