Skip to content

Commit

Permalink
refactor: update ui to success driven
Browse files Browse the repository at this point in the history
  • Loading branch information
samwelkanda committed Dec 10, 2024
1 parent b707d47 commit ec5b123
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 53 deletions.
10 changes: 10 additions & 0 deletions packages/vscode-extension/src/debug/common/debugConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export enum Host {
office = "www.office.com",
}

export enum ANSIColors {
RED = "\u001b[31m",
GREEN = "\u001b[32m",
YELLOW = "\u001b[33m",
BLUE = "\u001b[34m",
MAGENTA = "\u001b[35m",
WHITE = "\u001b[37m",
GRAY = "\u001b[38;5;244m",
}

export const accountHintPlaceholder = "${account-hint}";
export const agentHintPlaceholder = "${agent-hint}";
export const m365AppIdEnv = "M365_APP_ID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import fs from "fs-extra";
import { LogLevel } from "@microsoft/teamsfx-api";
import { defaultExtensionLogPath } from "../globalVariables";
import { ANSIColors } from "../debug/common/debugConstants";

interface Plugin {
name: string;
Expand Down Expand Up @@ -31,14 +33,6 @@ interface FunctionExecution {
errorMessage: string;
}

export const RED = "\u001b[31m";
const GREEN = "\u001b[32m";
const YELLOW = "\u001b[33m";
const BLUE = "\u001b[34m";
const MAGENTA = "\u001b[35m";
export const WHITE = "\u001b[37m";
const GRAY = "\u001b[38;5;244m";

/**
* @Sample [2021-03-15T03:41:04.961Z] - 0 plugin enabled.
*/
Expand All @@ -47,15 +41,23 @@ export function logToDebugConsole(logLevel: LogLevel, message: string): void {
const dateString = new Date().toJSON();
const debugConsole = vscode.debug.activeDebugConsole;
if (logLevel === LogLevel.Info) {
debugConsole.appendLine(WHITE + `[${dateString}] - ` + BLUE + `${message}`);
debugConsole.appendLine(
ANSIColors.WHITE + `[${dateString}] - ` + ANSIColors.BLUE + `${message}`
);
} else if (logLevel === LogLevel.Warning) {
debugConsole.appendLine(WHITE + `[${dateString}] - ` + YELLOW + `${message}`);
debugConsole.appendLine(
ANSIColors.WHITE + `[${dateString}] - ` + ANSIColors.YELLOW + `${message}`
);
} else if (logLevel === LogLevel.Error) {
debugConsole.appendLine(WHITE + `[${dateString}] - ` + RED + `${message}`);
debugConsole.appendLine(
ANSIColors.WHITE + `[${dateString}] - ` + ANSIColors.RED + `${message}`
);
} else if (logLevel === LogLevel.Debug) {
debugConsole.appendLine(WHITE + `[${dateString}] - ` + GREEN + `${message}`);
debugConsole.appendLine(
ANSIColors.WHITE + `[${dateString}] - ` + ANSIColors.GREEN + `${message}`
);
} else {
debugConsole.appendLine(WHITE + `[${dateString}] - ${message}`);
debugConsole.appendLine(ANSIColors.WHITE + `[${dateString}] - ${message}`);
}
} catch (e) {}
}
Expand Down Expand Up @@ -103,106 +105,78 @@ export class CopilotDebugLog {
if (this.enabledPlugins && this.enabledPlugins.length > 0) {
debugConsole.appendLine("");
logToDebugConsole(LogLevel.Info, `${this.enabledPlugins.length} enabled plugin(s).`);
debugConsole.appendLine(WHITE + "Copilot plugin developer info:");
debugConsole.appendLine(ANSIColors.WHITE + "Copilot plugin developer info:");
debugConsole.appendLine("");
this.enabledPlugins.forEach((plugin) => {
debugConsole.appendLine(
`${GREEN}(√) ${WHITE}Enabled plugin: ${MAGENTA}${plugin.name} ${GRAY}• version ${plugin.version}${plugin.id}`
`${ANSIColors.GREEN}(√) ${ANSIColors.WHITE}Enabled plugin: ${ANSIColors.MAGENTA}${plugin.name} ${ANSIColors.GRAY}• version ${plugin.version}${plugin.id}`
);

if (!this.matchedFunctionCandidates || this.matchedFunctionCandidates.length === 0) {
this.logNoMatchedFunctions(debugConsole);
} else {
if (this.matchedFunctionCandidates && this.matchedFunctionCandidates.length > 0) {
this.matchedFunctionCandidates.forEach((matchedFunction) => {
if (matchedFunction.plugin.id === plugin.id) {
debugConsole.appendLine(
`${GREEN} (√) ${WHITE}Matched functions: ${MAGENTA}${matchedFunction.functionDisplayName}`
`${ANSIColors.GREEN} (√) ${ANSIColors.WHITE}Matched functions: ${ANSIColors.MAGENTA}${matchedFunction.functionDisplayName}`
);
this.logFunctionExecutions(debugConsole, matchedFunction);
} else {
this.logNoMatchedFunctions(debugConsole);
}
});
}
});
} else {
debugConsole.appendLine("");
logToDebugConsole(LogLevel.Info, `0 enabled plugin(s).`);
debugConsole.appendLine(WHITE + "Copilot plugin developer info:");
debugConsole.appendLine(ANSIColors.WHITE + "Copilot plugin developer info:");
debugConsole.appendLine("");
this.logNoPlugins(debugConsole);
}
}

private logNoMatchedFunctions(debugConsole: vscode.DebugConsole): void {
debugConsole.appendLine(`${RED} (×) Error: ${WHITE}Matched functions: None`);
debugConsole.appendLine(
`${RED} (×) Error: ${WHITE}Selected functions for execution: None`
`${ANSIColors.RED} (×) Error: ${ANSIColors.WHITE}Matched functions: None`
);
debugConsole.appendLine(`${RED} (×) Error: ${WHITE}Function execution details: None`);
}

private logNoPlugins(debugConsole: vscode.DebugConsole): void {
debugConsole.appendLine(`${RED}(×) Error: ${WHITE}Enabled plugin: None`);
debugConsole.appendLine(`${RED} (×) Error: ${WHITE}Matched functions: None`);
debugConsole.appendLine(
`${RED} (×) Error: ${WHITE}Selected functions for execution: None`
);
debugConsole.appendLine(`${RED} (×) Error: ${WHITE}Function execution details: None`);
debugConsole.appendLine(`${ANSIColors.RED}(×) Error: ${ANSIColors.WHITE}Enabled plugin: None`);
}

private logFunctionExecutions(
debugConsole: vscode.DebugConsole,
matchedFunction: FunctionDescriptor
): void {
if (!this.functionsSelectedForInvocation || this.functionsSelectedForInvocation.length === 0) {
this.logNoSelectedFunctions(debugConsole);
} else {
if (this.functionsSelectedForInvocation && this.functionsSelectedForInvocation.length > 0) {
this.functionsSelectedForInvocation.forEach((selectedFunction) => {
if (selectedFunction.functionDisplayName === matchedFunction.functionDisplayName) {
debugConsole.appendLine(
`${GREEN} (√) ${WHITE}Selected functions for execution: ${MAGENTA}${selectedFunction.functionDisplayName}`
`${ANSIColors.GREEN} (√) ${ANSIColors.WHITE}Selected functions for execution: ${ANSIColors.MAGENTA}${selectedFunction.functionDisplayName}`
);
this.logExecutionDetails(debugConsole, matchedFunction);
} else {
this.logNoSelectedFunctions(debugConsole);
}
});
}
}

private logNoSelectedFunctions(debugConsole: vscode.DebugConsole): void {
debugConsole.appendLine(
`${RED} (×) Error: ${WHITE}Selected functions for execution: None`
);
debugConsole.appendLine(`${RED} (×) Error: ${WHITE}Function execution details: None`);
}

private logExecutionDetails(
debugConsole: vscode.DebugConsole,
matchedFunction: FunctionDescriptor
): void {
const logFileName = `Copilot log ${new Date().toISOString().replace(/-|:|\.\d+Z$/g, "")}.txt`;
const logFilePath = `${defaultExtensionLogPath}/${logFileName}`;
if (!this.functionExecutions || this.functionExecutions.length === 0) {
debugConsole.appendLine(`${RED} (×) Error: ${WHITE}Function execution details: None`);
} else {
if (this.functionExecutions && this.functionExecutions.length > 0) {
this.functionExecutions.forEach((functionExecution) => {
if (
functionExecution.function.functionDisplayName === matchedFunction.functionDisplayName
) {
debugConsole.appendLine(
`${GREEN} (√) ${WHITE}Function execution details: ${GREEN}Status ${functionExecution.executionStatus.responseStatus}, ${WHITE}refer to ${BLUE}${logFilePath}${WHITE} for all details.`
`${ANSIColors.GREEN} (√) ${ANSIColors.WHITE}Function execution details: ${ANSIColors.GREEN}Status ${functionExecution.executionStatus.responseStatus}, ${ANSIColors.WHITE}refer to ${ANSIColors.BLUE}${logFilePath}${ANSIColors.WHITE} for all details.`
);
if (functionExecution.errorMessage) {
debugConsole.appendLine(
`${RED} (×) Error: ${WHITE}${functionExecution.errorMessage}`
`${ANSIColors.RED} (×) Error: ${ANSIColors.WHITE}${functionExecution.errorMessage}`
);
}
} else {
debugConsole.appendLine(
`${RED} (×) Error: ${WHITE}Function execution details: None`
);
}
});
}
Expand Down

0 comments on commit ec5b123

Please sign in to comment.