Skip to content

Commit

Permalink
Change to prettier as code formatter
Browse files Browse the repository at this point in the history
Fixes #56
  • Loading branch information
Radeonmann committed Apr 19, 2023
1 parent 1e9cf44 commit c8fed0c
Show file tree
Hide file tree
Showing 53 changed files with 1,897 additions and 2,047 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"useTabs": false,
"printWidth": 500
}
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
"FIXME",
"TODO",
"SYNC" // SYNC tag for places which need to be in sync with contribution points of package.json
]
],
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
170 changes: 94 additions & 76 deletions CHANGELOG.md

Large diffs are not rendered by default.

172 changes: 84 additions & 88 deletions README.md

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@
"@vscode/test-electron": "^1.6.2",
"@vscode/vsce": "^2.16.0",
"eslint": "8.38",
"eslint-config-prettier": "^8.8.0",
"glob": "^7.2.0",
"mocha": "^9.2.2",
"prettier": "2.8.7",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"webpack": "^5.76.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Environment/AsProjectCBuildData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Uri } from 'vscode';
import { Uri } from "vscode";

export interface AsProjectCBuildInfo {
readonly compilerPath: Uri | undefined;
Expand Down Expand Up @@ -32,4 +32,4 @@ export function mergeAsProjectCBuildInfo(...values: (AsProjectCBuildInfo | undef
userIncludes: userIncludes,
buildOptions: buildOptions,
};
}
}
61 changes: 31 additions & 30 deletions src/Environment/AutomationStudioVersion.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as vscode from 'vscode';
import * as uriTools from '../Tools/UriTools';
import * as semver from 'semver';
import { logger } from '../Tools/Logger';
import { GccInstallation } from './GccInstallation';
import { BrAsBuildExe } from './BrAsBuildExe';
import * as vscode from "vscode";
import * as uriTools from "../Tools/UriTools";
import * as semver from "semver";
import { logger } from "../Tools/Logger";
import { GccInstallation } from "./GccInstallation";
import { BrAsBuildExe } from "./BrAsBuildExe";

/**
* Representation of an Automation Studio version
*/
export class AutomationStudioVersion {

/**
* Gets all Automation Studio versions which are located in the installRoot.
* @param installRoot The root directory containing multiple Automation Studio installations. e.g. `C:\BrAutomation`
Expand Down Expand Up @@ -61,11 +60,9 @@ export class AutomationStudioVersion {
this.#version = await parseAutomationStudioVersion(this.#rootPath);
// Find BR.AS.Build.exe
this.#buildExe = await searchAutomationStudioBuildExe(this.#rootPath);
if (!this.#buildExe) {
throw new Error('Cannot find BR.AS.Build.exe');
}
if (!this.#buildExe) throw new Error("Cannot find BR.AS.Build.exe");
// find gcc versions
const gccInstallRoot = vscode.Uri.joinPath(this.#rootPath, './AS/gnuinst');
const gccInstallRoot = vscode.Uri.joinPath(this.#rootPath, "./AS/gnuinst");
this.#gccInstallation = await GccInstallation.searchAutomationStudioGnuinst(gccInstallRoot);
// init done
this.#isInitialized = true;
Expand All @@ -74,28 +71,28 @@ export class AutomationStudioVersion {

/** The root URI of the Automation Studio version */
public get rootPath(): vscode.Uri {
if (!this.#isInitialized) { throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`); }
if (!this.#isInitialized) throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`);
return this.#rootPath;
}
#rootPath: vscode.Uri;

/** The Automation Studio version */
public get version(): semver.SemVer {
if (!this.#isInitialized || !this.#version) { throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`); }
if (!this.#isInitialized || !this.#version) throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`);
return this.#version;
}
#version: semver.SemVer | undefined;

/** The Automation Studio project build tool */
public get buildExe(): BrAsBuildExe {
if (!this.#isInitialized || !this.#buildExe) { throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`); }
if (!this.#isInitialized || !this.#buildExe) throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`);
return this.#buildExe;
}
#buildExe: BrAsBuildExe | undefined;

/** gcc compiler versions available in this Automation Studio version */
public get gccInstallation(): GccInstallation {
if (!this.#isInitialized || !this.#gccInstallation) { throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`); }
if (!this.#isInitialized || !this.#gccInstallation) throw new Error(`Use of not initialized ${AutomationStudioVersion.name} object`);
return this.#gccInstallation;
}
#gccInstallation: GccInstallation | undefined;
Expand All @@ -121,16 +118,20 @@ async function parseAutomationStudioVersion(asRoot: vscode.Uri): Promise<semver.
// Try to get version from ./BrSetup/VInfo/ProductInfo_bin-en.brv or ./BrSetup/VInfo/ProductInfo_bin-de.brv
// -> Depending on installed languages both or only one may exist
// -> In older AS versions bin was written in caps (Bin)
const prodInfoBasePath = uriTools.pathJoin(asRoot, 'BrSetup/VInfo');
const prodInfoPathEn = uriTools.pathJoin(prodInfoBasePath, 'ProductInfo_bin-en.brv');
const prodInfoPathEnOld = uriTools.pathJoin(prodInfoBasePath, 'ProductInfo_Bin-en.brv');
const prodInfoPathDe = uriTools.pathJoin(prodInfoBasePath, 'ProductInfo_bin-de.brv');
const prodInfoPathDeOld = uriTools.pathJoin(prodInfoBasePath, 'ProductInfo_Bin-de.brv');
const prodInfoPath = await uriTools.exists(prodInfoPathEn) ? prodInfoPathEn
: await uriTools.exists(prodInfoPathDe) ? prodInfoPathDe
: await uriTools.exists(prodInfoPathEnOld) ? prodInfoPathEnOld
: await uriTools.exists(prodInfoPathDeOld) ? prodInfoPathDeOld
: undefined;
const prodInfoBasePath = uriTools.pathJoin(asRoot, "BrSetup/VInfo");
const prodInfoPathEn = uriTools.pathJoin(prodInfoBasePath, "ProductInfo_bin-en.brv");
const prodInfoPathEnOld = uriTools.pathJoin(prodInfoBasePath, "ProductInfo_Bin-en.brv");
const prodInfoPathDe = uriTools.pathJoin(prodInfoBasePath, "ProductInfo_bin-de.brv");
const prodInfoPathDeOld = uriTools.pathJoin(prodInfoBasePath, "ProductInfo_Bin-de.brv");
const prodInfoPath = (await uriTools.exists(prodInfoPathEn))
? prodInfoPathEn
: (await uriTools.exists(prodInfoPathDe))
? prodInfoPathDe
: (await uriTools.exists(prodInfoPathEnOld))
? prodInfoPathEnOld
: (await uriTools.exists(prodInfoPathDeOld))
? prodInfoPathDeOld //
: undefined;
if (prodInfoPath !== undefined) {
try {
const prodInfoDoc = await vscode.workspace.openTextDocument(prodInfoPath);
Expand Down Expand Up @@ -162,7 +163,7 @@ async function parseAutomationStudioVersion(asRoot: vscode.Uri): Promise<semver.
logger.warning(`Failed to parse AS Version from directory name ${logger.formatUri(asRoot)}. AS will be listed as V0.0.0`);
}
// set to V0.0.0 as backup, so AS is still available but with wrong version...
return new semver.SemVer('0.0.0');
return new semver.SemVer("0.0.0");
}

/**
Expand All @@ -172,21 +173,21 @@ async function parseAutomationStudioVersion(asRoot: vscode.Uri): Promise<semver.
*/
async function searchAutomationStudioBuildExe(asRoot: vscode.Uri): Promise<BrAsBuildExe | undefined> {
// english
const buildExeUriEn = uriTools.pathJoin(asRoot, 'Bin-en/BR.AS.Build.exe');
const buildExeUriEn = uriTools.pathJoin(asRoot, "Bin-en/BR.AS.Build.exe");
if (await uriTools.exists(buildExeUriEn)) {
return new BrAsBuildExe(buildExeUriEn);
}
// german
const buildExeUriDe = uriTools.pathJoin(asRoot, 'Bin-de/BR.AS.Build.exe');
const buildExeUriDe = uriTools.pathJoin(asRoot, "Bin-de/BR.AS.Build.exe");
if (await uriTools.exists(buildExeUriDe)) {
return new BrAsBuildExe(buildExeUriDe);
}
// slower search if none was found yet
const searchPattern = new vscode.RelativePattern(asRoot, '**/BR.AS.Build.exe');
const searchPattern = new vscode.RelativePattern(asRoot, "**/BR.AS.Build.exe");
const searchResult = await vscode.workspace.findFiles(searchPattern);
if (searchResult.length > 0) {
return new BrAsBuildExe(searchResult[0]);
}
// none was found
return undefined;
}
}
8 changes: 4 additions & 4 deletions src/Environment/BrAsBuildExe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from 'vscode';
import * as vscode from "vscode";

/**
* Representation of Automation Studio build exe (BR.AS.Build.exe)
Expand All @@ -9,9 +9,9 @@ export class BrAsBuildExe {
public constructor(exePath: vscode.Uri) {
this.#exePath = exePath;
}

/** The path to the BR.AS.Build.exe file */
public get exePath() : vscode.Uri {
public get exePath(): vscode.Uri {
return this.#exePath;
}
#exePath: vscode.Uri;
Expand All @@ -22,4 +22,4 @@ export class BrAsBuildExe {
exePath: this.exePath.toString(true),
};
}
}
}
5 changes: 2 additions & 3 deletions src/Environment/CommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* @packageDocumentation
*/


/** B&R system generations */
export type SystemGeneration = 'SG3' | 'SGC' | 'SG4' | 'UNKNOWN';
export type SystemGeneration = "SG3" | "SGC" | "SG4" | "UNKNOWN";
/** B&R CPU architectures */
export type TargetArchitecture = 'IA32' | 'Arm' | 'M68K' | 'UNKNOWN';
export type TargetArchitecture = "IA32" | "Arm" | "M68K" | "UNKNOWN";
40 changes: 18 additions & 22 deletions src/Environment/Environment.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
/**
* Handling of installed PVI versions on the developer PC
* @packageDocumentation
*/

import { logger } from '../Tools/Logger';
import * as semver from 'semver';
import { extensionConfiguration } from '../ExtensionConfiguration';
import { getMatchingVersion } from '../Tools/SemVer';
import { PviVersion } from './PviVersion';
import { AutomationStudioVersion } from './AutomationStudioVersion';
import { statusBar } from '../UI/StatusBar';
*/

import { logger } from "../Tools/Logger";
import * as semver from "semver";
import { extensionConfiguration } from "../ExtensionConfiguration";
import { getMatchingVersion } from "../Tools/SemVer";
import { PviVersion } from "./PviVersion";
import { AutomationStudioVersion } from "./AutomationStudioVersion";
import { statusBar } from "../UI/StatusBar";

export class Environment {

/** static only class */
private constructor() { }
private constructor() {}

/** PVI (Process Variable Interface) environment */
public static pvi = class {

/** static only class */
private constructor() { }
private constructor() {}

/**
* Get all available PVI versions
Expand All @@ -30,7 +27,7 @@ export class Environment {
public static async getVersions(): Promise<PviVersion[]> {
if (this.#versions === undefined) {
this.#versions = this.#searchVersions();
statusBar.addBusyItem(this.#versions, 'Searching for installed PVI versions');
statusBar.addBusyItem(this.#versions, "Searching for installed PVI versions");
}
return await this.#versions;
}
Expand All @@ -52,11 +49,11 @@ export class Environment {
*/
public static async updateVersions(): Promise<PviVersion[]> {
this.#versions = this.#searchVersions();
statusBar.addBusyItem(this.#versions, 'Searching for installed PVI versions');
statusBar.addBusyItem(this.#versions, "Searching for installed PVI versions");
return await this.#versions;
}
static async #searchVersions(): Promise<PviVersion[]> {
logger.info('Start searching for PVI versions');
logger.info("Start searching for PVI versions");
// search for PVI installations in all configured directories
const foundVersions: PviVersion[] = [];
const configuredDirs = extensionConfiguration.environment.pviInstallPaths;
Expand All @@ -78,9 +75,8 @@ export class Environment {

/** Automation Studio environment */
public static automationStudio = class {

/** static only class */
private constructor() { }
private constructor() {}

/**
* Get all available Automation Studio versions
Expand All @@ -89,7 +85,7 @@ export class Environment {
public static async getVersions(): Promise<AutomationStudioVersion[]> {
if (this.#versions === undefined) {
this.#versions = this.#searchVersions();
statusBar.addBusyItem(this.#versions, 'Searching for installed AS versions');
statusBar.addBusyItem(this.#versions, "Searching for installed AS versions");
}
return await this.#versions;
}
Expand All @@ -111,11 +107,11 @@ export class Environment {
*/
public static async updateVersions(): Promise<AutomationStudioVersion[]> {
this.#versions = this.#searchVersions();
statusBar.addBusyItem(this.#versions, 'Searching for installed AS versions');
statusBar.addBusyItem(this.#versions, "Searching for installed AS versions");
return await this.#versions;
}
static async #searchVersions(): Promise<AutomationStudioVersion[]> {
logger.info('Start searching for Automation Studio versions');
logger.info("Start searching for Automation Studio versions");
// search for Automation Studio installations in all configured directories
const foundVersions: AutomationStudioVersion[] = [];
const configuredDirs = extensionConfiguration.environment.automationStudioInstallPaths;
Expand All @@ -134,4 +130,4 @@ export class Environment {
}
static #versions: Promise<AutomationStudioVersion[]> | undefined;
};
}
}
Loading

0 comments on commit c8fed0c

Please sign in to comment.