Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into fix-parser-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmartina committed Jun 18, 2024
2 parents f265ae5 + f9bb665 commit 5d5bf89
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 141 deletions.
10 changes: 1 addition & 9 deletions packages/colibri/src/commands/teroshdl/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as command_utils from '../../utils/command_utils';
import * as printer from '../../utils/printer';
import * as formatter_common from '../../formatter/common';
import { Formatter } from '../../formatter/formatter';
import * as logger from '../../logger/logger';
import * as cfg from '../../config/config_declaration';
import {e_formatter_verible_full} from '../../formatter/common';

Expand Down Expand Up @@ -211,14 +210,7 @@ export default class MyCLI extends Command {
const formatter_name = flags.formatter;
const python_path = flags['python-path'];
const silent = flags.silent;
const verbose = flags.verbose;

if (verbose === true) {
logger.Logger.set_mode(logger.LOG_MODE.STDOUT);
}
else {
logger.Logger.set_mode(logger.LOG_MODE.SILENT);
}
// const verbose = flags.verbose;

const cmd_current_dir = command_utils.get_current_directory();

Expand Down
10 changes: 1 addition & 9 deletions packages/colibri/src/commands/teroshdl/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import * as command_utils from '../../utils/command_utils';
import * as printer from '../../utils/printer';
import { Linter } from "../../linter/linter";
import * as linter_common from '../../linter/common';
import * as logger from '../../logger/logger';
import * as reporter from '../../reporter/reporter';
import * as cfg from '../../config/config_declaration';

Expand Down Expand Up @@ -338,14 +337,7 @@ export default class MyCLI extends Command {
const linter_path = flags['linter-path'];
const linter_arguments = flags['linter-arguments'];
const silent = flags.silent;
const verbose = flags.verbose;

if (verbose === true) {
logger.Logger.set_mode(logger.LOG_MODE.STDOUT);
}
else {
logger.Logger.set_mode(logger.LOG_MODE.SILENT);
}
// const verbose = flags.verbose;

const cmd_current_dir = command_utils.get_current_directory();

Expand Down
2 changes: 1 addition & 1 deletion packages/colibri/src/formatter/istyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Istyle extends Base_formatter {
command += `"${file}"`;

const msg = `Formatting with command: ${command} `;
logger.Logger.log(msg, logger.T_SEVERITY.INFO);
logger.Logger.log(msg);

const P = new Process();
const exec_result = await P.exec_wait(command);
Expand Down
2 changes: 1 addition & 1 deletion packages/colibri/src/formatter/s3sv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class S3sv extends Base_formatter {

public async format(file: string, opt: cfg.e_formatter_s3sv) {
const msg = `Formatting with command s3sv `;
logger.Logger.log(msg, logger.T_SEVERITY.INFO);
logger.Logger.log(msg);

const code = read_file_sync(file);
const result_f = await this.format_from_code(code, opt);
Expand Down
2 changes: 1 addition & 1 deletion packages/colibri/src/formatter/verible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Verible extends Base_formatter {
const code_formatted = fs.readFileSync(file, "utf8");

const msg = `Formatting with command: ${command} `;
logger.Logger.log(msg, logger.T_SEVERITY.INFO);
logger.Logger.log(msg);

const result: common.f_result = {
code_formatted: code_formatted,
Expand Down
2 changes: 1 addition & 1 deletion packages/colibri/src/formatter/vsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Vsg extends Base_formatter {
const code_formatted = fs.readFileSync(file, "utf8");

const msg = `Formatting with command: ${command} `;
logger.Logger.log(msg, logger.T_SEVERITY.INFO);
logger.Logger.log(msg);

const result: common.f_result = {
code_formatted: code_formatted,
Expand Down
3 changes: 2 additions & 1 deletion packages/colibri/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export * as template from './template/export_t';
export * as project_manager from './project_manager/export_t';
export * as config from './config/export_t';
export * as utils from './utils/export_t';
export * as yosys from './yosys/export_t';
export * as yosys from './yosys/export_t';
export * as logger from './logger/export_t';
2 changes: 1 addition & 1 deletion packages/colibri/src/linter/base_linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export abstract class Base_linter {
const command = this.get_command(file, options);

const msg = `Linting with command: ${command} `;
logger.Logger.log(msg, logger.T_SEVERITY.INFO);
logger.Logger.log(msg);

const P = new Process();
const opt: p_options = {
Expand Down
2 changes: 1 addition & 1 deletion packages/colibri/src/linter/vsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Vsg extends Base_linter {
}

const msg = `Linting with command: ${command} `;
logger.Logger.log(msg, logger.T_SEVERITY.INFO);
logger.Logger.log(msg);

const P = new Process();
await P.exec_wait(command);
Expand Down
20 changes: 20 additions & 0 deletions packages/colibri/src/logger/export_t.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023
// Carlos Alberto Ruiz Naranjo [carlosruiznaranjo@gmail.com]
// Ismael Perez Rojo [ismaelprojo@gmail.com]
//
// This file is part of TerosHDL
//
// Colibri is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Colibri is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TerosHDL. If not, see <https://www.gnu.org/licenses/>.

export * as logger from './logger';
95 changes: 58 additions & 37 deletions packages/colibri/src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,90 @@
// You should have received a copy of the GNU General Public License
// along with TerosHDL. If not, see <https://www.gnu.org/licenses/>.

import * as file_utils from '../utils/file_utils';

export enum LOG_MODE {
FILE = "file",
STDOUT = "stout",
SILENT = "silent"
}

export enum T_SEVERITY {
ERROR = 2,
WARNING = 1,
INFO = 0
ERROR = 3,
WARNING = 2,
INFO = 1,
DEBUG = 0,
}

export class Logger {
static mode = LOG_MODE.STDOUT;
static severity = T_SEVERITY.INFO;
static output_path = "";
export abstract class LoggerBase {
abstract error(msg: string): void;
abstract warn(msg: string): void;
abstract log(msg: string): void;
abstract debug(msg: string): void;
abstract trace(msg: string): void;
}

static log(msg: string, severity = T_SEVERITY.INFO) {
if (this.is_print(severity) === false) {
return;
}
const msg_comlete = `[colibri2][${this.get_severty_name(severity)}]: ${msg}`;
if (this.mode === LOG_MODE.STDOUT) {
// eslint-disable-next-line no-console
console.log(msg_comlete);
}
else if (this.mode === LOG_MODE.FILE) {
file_utils.save_file_sync(this.output_path, `${msg_comlete}\n`, true);
return;
class LoggerConsole extends LoggerBase {
private severity = T_SEVERITY.DEBUG;

error(msg: string) {
this._log(msg, T_SEVERITY.ERROR);
}

warn(msg: string) {
this._log(msg, T_SEVERITY.WARNING);
}

log(msg: string) {
this._log(msg, T_SEVERITY.INFO);
}

debug(msg: string) {
this._log(msg, T_SEVERITY.DEBUG);
}

trace(msg: string) {
this._log(msg, T_SEVERITY.DEBUG);
}

private is_print(severity: T_SEVERITY) {
if (severity >= this.severity) {
return true;
}
return false;
}

static get_severty_name(severity: T_SEVERITY) {
if (severity === T_SEVERITY.ERROR) {
return "error";
private getSevertyName(severity: T_SEVERITY) {
if (severity === T_SEVERITY.INFO) {
return "info";
}
else if (severity === T_SEVERITY.WARNING) {
return "warning";
}
else if (severity === T_SEVERITY.ERROR) {
return "error";
}
else {
return "info";
return "debug";
}
}

static is_print(severity: T_SEVERITY) {
if (severity >= this.severity) {
return true;
private _log(msg: string, severity = T_SEVERITY.INFO) {
if (this.is_print(severity) === false) {
return;
}
return false;
const msg_comlete = `[colibri2][${this.getSevertyName(severity)}]: ${msg}`;
// eslint-disable-next-line no-console
console.log(msg_comlete);
}
}

static set_output_path(path: string) {
file_utils.remove_file(path);
this.output_path = path;
}
export class Logger {
static logger: LoggerBase = new LoggerConsole();

static set_mode(mode: LOG_MODE) {
this.mode = mode;
static log(msg: string) {
this.logger.log(msg);
}

static set_severity(severity: T_SEVERITY) {
this.severity = severity;
static setLogger(logger: LoggerBase) {
this.logger = logger;
}
}
75 changes: 0 additions & 75 deletions packages/colibri/tests/logger/logger.spec.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/colibri/tests/logger/test.log

This file was deleted.

5 changes: 4 additions & 1 deletion packages/teroshdl/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ import * as vscode from 'vscode';
import * as release_notes_webview from "./utils/webview/release_notes";
import { ExtensionManager } from "./utils/webview/utils";
import { Teroshdl } from './teroshdl';
import * as teroshdl2 from "teroshdl2";
import { globalLogger, toolLogger, debugLogger } from './logger';

export async function activate(context: vscode.ExtensionContext) {

debugLogger.info('Congratulations, your extension "TerosHDL" is now active!');

const extension_manager = new ExtensionManager();

globalLogger.clear();
toolLogger.clear();
debugLogger.clear();

teroshdl2.logger.logger.Logger.setLogger(debugLogger);

try {
await extension_manager.init();
Expand Down
Loading

0 comments on commit 5d5bf89

Please sign in to comment.