Skip to content

Commit

Permalink
feat: support for configuration file webview
Browse files Browse the repository at this point in the history
  • Loading branch information
qarlosalberto committed May 28, 2024
1 parent d5dd14a commit a8523f6
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 10 deletions.
21 changes: 21 additions & 0 deletions packages/colibri/src/common/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export enum LANGUAGE {
NONE = "none"
}

export function getLanguageEnumValue(value: string): LANGUAGE {
for (const key in LANGUAGE) {
if (LANGUAGE[key as keyof typeof LANGUAGE] === value) {
return LANGUAGE[key as keyof typeof LANGUAGE];
}
}
return LANGUAGE.NONE;
}

////////////////////////////////////////////////////////////////////////////////
// Versions
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -96,6 +105,18 @@ export const LANGUAGE_VERSIONS_LIST: Record<LANGUAGE, t_versions> = {
[LANGUAGE.QSYS]: undefined,
};

export function getLanguageVersion(language: LANGUAGE, version: string | undefined): t_version_inst {
const versions = LANGUAGE_VERSIONS_LIST[language];
if (versions && version) {
for (const v of versions) {
if (v === version) {
return v;
}
}
}
return undefined;
}

////////////////////////////////////////////////////////////////////////////////
// Extensions
////////////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 9 additions & 0 deletions packages/colibri/src/project_manager/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export enum e_source_type {
SYNTHESIS = "synthesis"
}

export function getSourceTypeEnumValue(value: string): e_source_type {
for (const key in e_source_type) {
if (e_source_type[key as keyof typeof e_source_type] === value) {
return e_source_type[key as keyof typeof e_source_type];
}
}
return e_source_type.NONE;
}

export type t_logical = {
name: string;
file_list: t_file[];
Expand Down
33 changes: 29 additions & 4 deletions packages/colibri/src/project_manager/list_manager/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { t_file, t_action_result, t_logical, e_source_type } from "../common";
import * as file_utils from "../../utils/file_utils";
import { Manager } from "./manager";
import { Dependency_graph } from "../dependency/dependency";
import { LANGUAGE } from "../../common/general";
import { LANGUAGE, t_version_inst } from "../../common/general";
import { get_files_from_csv } from "../prj_loaders/csv_loader";

export class File_manager extends Manager<t_file, undefined, string, string> {
Expand All @@ -33,19 +33,19 @@ export class File_manager extends Manager<t_file, undefined, string, string> {
const orderResult = get_files_from_csv(compileOrderPath, false);
if (orderResult.successful && orderResult.file_list.length > 0) {
const fileListInOrder = orderResult.file_list;

const orderedFiles = fileListInOrder.filter(fileInOrder =>
this.files.some(file =>
file.name === fileInOrder.name && file.logical_name === fileInOrder.logical_name
)
);

const remainingFiles = this.files.filter(file =>
!fileListInOrder.some(fileInOrder =>
file.name === fileInOrder.name && file.logical_name === fileInOrder.logical_name
)
);

this.files = [...orderedFiles, ...remainingFiles];
}
}
Expand Down Expand Up @@ -152,6 +152,31 @@ export class File_manager extends Manager<t_file, undefined, string, string> {
return result;
}

configureSource(name: string, logical_name: string, fileType: LANGUAGE, fileVersion: t_version_inst,
sourceType: e_source_type): t_action_result {

const result: t_action_result = {
result: "",
successful: true,
msg: ""
};
if (this.check_if_exists(name, logical_name) === false) {
result.successful = false;
result.msg = "Toplevel path doesn't exist";
return result;
}

for (let i = 0; i < this.files.length; i++) {
const fileInst = this.files[i];
if (fileInst.name === name && fileInst.logical_name === logical_name) {
fileInst.file_type = fileType;
fileInst.file_version = fileVersion;
fileInst.source_type = sourceType;
}
}
return result;
}

delete(name: string, logical_name = ""): t_action_result {
const result: t_action_result = {
result: "",
Expand Down
2 changes: 1 addition & 1 deletion packages/colibri/src/project_manager/project_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Project_manager extends ConfigManager {
const is_manual = file?.["is_manual"] ?? true;
const file_type = file_utils.get_language_from_filepath(name);
const file_version = file_utils.check_default_version_for_filepath(name, file.file_version);
const source_type = file?.["is_manual"] ?? e_source_type.NONE;
const source_type = file?.["source_type"] ?? e_source_type.NONE;

prj.add_file({
name: name, is_include_file: is_include_file,
Expand Down
7 changes: 5 additions & 2 deletions packages/teroshdl/auto_package/script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
command: "npm run generate-examples & npm run compile"

- name: "compile"
command: "npm run-script build-webviews & tsc -p ./"
command: "npm run-script build-webviews & npm run-script build-webviews-configuration & tsc -p ./"

- name: "lint"
command: "eslint src --ext ts"
Expand All @@ -32,4 +32,7 @@
command: "cd auto_package & ./gen.sh"

- name : "build-webviews"
command: "NODE_ENV=production node resources/webviews/reporters/esbuild.js"
command: "NODE_ENV=production node resources/webviews/reporters/esbuild.js"

- name : "build-webviews-configuration"
command: "NODE_ENV=production node resources/webviews/fileConfiguration/esbuild.js"
5 changes: 3 additions & 2 deletions packages/teroshdl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,16 @@
"build-package": "cd auto_package && ./gen.sh",
"clean": "shx rm -rf out",
"vscode:prepublish": "npm run generate-examples & npm run compile",
"compile": "npm run-script build-webviews & tsc -p ./",
"compile": "npm run-script build-webviews & npm run-script build-webviews-configuration & tsc -p ./",
"lint": "eslint src --ext ts",
"watch": "tsc --watch --p ./ & nodemon --ignore 'resources/webviews/reporters/**/wb/' --watch resources/webviews/reporters -e js,ts,tsx,html --exec \"npm run-script build-webviews\"",
"generate-examples": "cd ./resources/project_manager; ./copy_examples.sh",
"pre-package": "mkdir ./node_modules/teroshdl2/node_modules/onml/lib; cp ./node_modules/teroshdl2/node_modules/onml/*.js ./node_modules/teroshdl2/node_modules/onml/lib",
"package": "npm run pre-package & vsce package --yarn --allow-star-activation",
"package-prerelease": "npm run pre-package & vsce package --pre-release -o ./pre-release.vsix --yarn --allow-star-activation",
"auto-package": "cd auto_package & ./gen.sh",
"build-webviews": "NODE_ENV=production node resources/webviews/reporters/esbuild.js"
"build-webviews": "NODE_ENV=production node resources/webviews/reporters/esbuild.js",
"build-webviews-configuration": "NODE_ENV=production node resources/webviews/fileConfiguration/esbuild.js"
},
"dependencies": {
"@octokit/rest": "16.36.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wb
66 changes: 66 additions & 0 deletions packages/teroshdl/resources/webviews/fileConfiguration/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { build } = require("esbuild");
const path = require("path");

//@ts-check
/** @typedef {import('esbuild').BuildOptions} BuildOptions **/

/** @type BuildOptions */
const baseConfig = {
bundle: true,
minify: process.env.NODE_ENV === "production",
sourcemap: process.env.NODE_ENV !== "production",
};

// Config for webview source code (to be run in a web-based context)
/** @type BuildOptions */
const webviewFileConfiguration = {
...baseConfig,
target: "es2020",
format: "esm",
entryPoints: [path.join(__dirname, "fileConfiguration.ts")],
outfile: path.join(__dirname, "wb", "webviewFileConfiguration.js"),
};

// This watch config adheres to the conventions of the esbuild-problem-matchers
// extension (https://github.com/connor4312/esbuild-problem-matchers#esbuild-via-js)
/** @type BuildOptions */
const watchConfig = {
watch: {
onRebuild(error, result) {
console.log("[watch] build started");
if (error) {
error.errors.forEach((error) =>
console.error(
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
)
);
} else {
console.log("[watch] build finished");
}
},
},
};

// Build script
(async () => {
const args = process.argv.slice(2);
try {
if (args.includes("--watch")) {
// Build and watch extension and webview code
console.log("[watch] build started");
await build({
...webviewFileConfiguration,
...watchConfig,
});
console.log("[watch] build finished");
} else {
// Build extension and webview code
await build(webviewFileConfiguration);
console.log("build complete");
}
} catch (err) {
console.log(err);
// process.stderr.write(err.stderr);
process.exit(1);
}
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
vscode-dropdown {
width: 100%;
}
</style>

</head>

<body>
<vscode-form-group>

<br><br>

<vscode-badge id="file-name"></vscode-badge>

<br><br>

<vscode-label for="file-type">File type:</vscode-label>
<vscode-dropdown id="file-type">
</vscode-dropdown>

<br><br><br>

<vscode-label for="file-version">File Version:</vscode-label>
<vscode-dropdown id="file-version">
</vscode-dropdown>

<br><br><br>

<vscode-label for="source-type">Source Type:</vscode-label>
<vscode-dropdown id="source-type">
</vscode-dropdown>

<br><br><br>

<vscode-button id="apply-button">Apply</vscode-button>

</vscode-form-group>
<script type="module" src="{{webviewUri}}"></script>
</body>

</html>
Loading

0 comments on commit a8523f6

Please sign in to comment.