From 570afb8efc7ee99bd6d12ea6ec6ba58373a5fcbd Mon Sep 17 00:00:00 2001 From: Josh Vera Date: Mon, 22 Jul 2024 15:50:37 -0400 Subject: [PATCH] Enable debug logs (#1800) * Add an enableDebugLogs flag * Send logs to VSCode --- core/index.d.ts | 1 + core/util/filesystem.ts | 1 + extensions/vscode/package.json | 5 + .../src/ContinueGUIWebviewViewProvider.ts | 67 +++++++++ extensions/vscode/src/ideProtocol.ts | 1 + gui/src/hooks/useSubmenuContextProviders.tsx | 141 +++++++++++------- 6 files changed, 160 insertions(+), 56 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 55969eed8..53205fe82 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -422,6 +422,7 @@ export interface IdeSettings { remoteConfigSyncPeriod: number; userToken: string; enableControlServerBeta: boolean; + enableDebugLogs: boolean } export interface IDE { diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index 7b849cb33..3f214bc69 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -38,6 +38,7 @@ class FileSystemIde implements IDE { remoteConfigSyncPeriod: 60, userToken: "", enableControlServerBeta: false, + enableDebugLogs: false, }; } async getGitHubAuthToken(): Promise { diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index b3423829c..ce591b2e4 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -94,6 +94,11 @@ "default": false, "markdownDescription": "Pause Continue's tab autocomplete feature when your battery is low." }, + "continue.enableDebugLogs": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable Continue Debug Logs in the Output panel." + }, "continue.remoteConfigServerUrl": { "type": "string", "default": null, diff --git a/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts index c713244b0..08fedd54e 100644 --- a/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts +++ b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts @@ -12,12 +12,55 @@ export class ContinueGUIWebviewViewProvider public static readonly viewType = "continue.continueGUIView"; public webviewProtocol: VsCodeWebviewProtocol; + private updateDebugLogsStatus() { + const settings = vscode.workspace.getConfiguration("continue"); + this.enableDebugLogs = settings.get("enableDebugLogs", false); + if (this.enableDebugLogs) { + this.outputChannel.show(true); + } else { + this.outputChannel.hide(); + } + } + + // Show or hide the output channel on enableDebugLogs + private setupDebugLogsListener() { + vscode.workspace.onDidChangeConfiguration((event) => { + if (event.affectsConfiguration('continue.enableDebugLogs')) { + const settings = vscode.workspace.getConfiguration("continue"); + const enableDebugLogs = settings.get("enableDebugLogs", false); + if (enableDebugLogs) { + this.outputChannel.show(true); + } else { + this.outputChannel.hide(); + } + } + }); + } + + private async handleWebviewMessage(message: any) { + if (message.messageType === "log") { + const settings = vscode.workspace.getConfiguration("continue"); + const enableDebugLogs = settings.get("enableDebugLogs", false); + + if (message.level === "debug" && !enableDebugLogs) { + return; // Skip debug logs if enableDebugLogs is false + } + + const timestamp = new Date().toISOString().split(".")[0]; + const logMessage = `[${timestamp}] [${message.level.toUpperCase()}] ${message.text}`; + this.outputChannel.appendLine(logMessage); + } +} + resolveWebviewView( webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken, ): void | Thenable { this._webview = webviewView.webview; + this._webview.onDidReceiveMessage((message) => + this.handleWebviewMessage(message), + ); webviewView.webview.html = this.getSidebarContent( this.extensionContext, webviewView, @@ -26,6 +69,8 @@ export class ContinueGUIWebviewViewProvider private _webview?: vscode.Webview; private _webviewView?: vscode.WebviewView; + private outputChannel: vscode.OutputChannel; + private enableDebugLogs: boolean; get isVisible() { return this._webviewView?.visible; @@ -50,11 +95,17 @@ export class ContinueGUIWebviewViewProvider }); } + constructor( private readonly configHandlerPromise: Promise, private readonly windowId: string, private readonly extensionContext: vscode.ExtensionContext, ) { + this.outputChannel = vscode.window.createOutputChannel("Continue"); + this.enableDebugLogs = false; + this.updateDebugLogsStatus(); + this.setupDebugLogsListener(); + this.webviewProtocol = new VsCodeWebviewProtocol( (async () => { const configHandler = await this.configHandlerPromise; @@ -131,6 +182,22 @@ export class ContinueGUIWebviewViewProvider
+ ${``} ${ inDevelopmentMode ? `