Enable debug logs (#1800)
* Add an enableDebugLogs flag * Send logs to VSCode
This commit is contained in:
parent
423a8169a8
commit
570afb8efc
6 changed files with 160 additions and 56 deletions
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -422,6 +422,7 @@ export interface IdeSettings {
|
|||
remoteConfigSyncPeriod: number;
|
||||
userToken: string;
|
||||
enableControlServerBeta: boolean;
|
||||
enableDebugLogs: boolean
|
||||
}
|
||||
|
||||
export interface IDE {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ class FileSystemIde implements IDE {
|
|||
remoteConfigSyncPeriod: 60,
|
||||
userToken: "",
|
||||
enableControlServerBeta: false,
|
||||
enableDebugLogs: false,
|
||||
};
|
||||
}
|
||||
async getGitHubAuthToken(): Promise<string | undefined> {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<boolean>("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<boolean>("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<boolean>("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<void> {
|
||||
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<ConfigHandler>,
|
||||
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
|
|||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
${`<script>
|
||||
function log(level, ...args) {
|
||||
const text = args.map(arg =>
|
||||
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
|
||||
).join(' ');
|
||||
vscode.postMessage({ messageType: 'log', level, text, messageId: "log" });
|
||||
}
|
||||
|
||||
window.console.log = (...args) => log('log', ...args);
|
||||
window.console.info = (...args) => log('info', ...args);
|
||||
window.console.warn = (...args) => log('warn', ...args);
|
||||
window.console.error = (...args) => log('error', ...args);
|
||||
window.console.debug = (...args) => log('debug', ...args);
|
||||
|
||||
console.debug('Logging initialized');
|
||||
</script>`}
|
||||
${
|
||||
inDevelopmentMode
|
||||
? `<script type="module">
|
||||
|
|
|
|||
|
|
@ -522,6 +522,7 @@ class VsCodeIde implements IDE {
|
|||
),
|
||||
userToken: settings.get<string>("userToken", ""),
|
||||
enableControlServerBeta: internalBetaPathExists(),
|
||||
enableDebugLogs: settings.get<boolean>("enableDebugLogs", false),
|
||||
// settings.get<boolean>(
|
||||
// "enableControlServerBeta",
|
||||
// false,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
groupByLastNPathParts,
|
||||
} from "core/util";
|
||||
import MiniSearch, { SearchResult } from "minisearch";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { selectContextProviderDescriptions } from "../redux/selectors";
|
||||
|
|
@ -107,6 +107,90 @@ function useSubmenuContextProviders() {
|
|||
};
|
||||
}, []);
|
||||
|
||||
const getSubmenuSearchResults = useMemo(
|
||||
() =>
|
||||
(providerTitle: string | undefined, query: string): SearchResult[] => {
|
||||
console.debug(
|
||||
"Executing getSubmenuSearchResults. Provider:",
|
||||
providerTitle,
|
||||
"Query:",
|
||||
query,
|
||||
);
|
||||
console.debug("Current minisearches:", Object.keys(minisearches));
|
||||
if (providerTitle === undefined) {
|
||||
// Return search combined from all providers
|
||||
const results = Object.keys(minisearches).map((providerTitle) => {
|
||||
const results = minisearches[providerTitle].search(
|
||||
query,
|
||||
MINISEARCH_OPTIONS,
|
||||
);
|
||||
console.debug(`Search results for ${providerTitle}:`, results.length);
|
||||
return results.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
});
|
||||
|
||||
return results.flat().sort((a, b) => b.score - a.score);
|
||||
}
|
||||
if (!minisearches[providerTitle]) {
|
||||
console.debug(`No minisearch found for provider: ${providerTitle}`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const results = minisearches[providerTitle]
|
||||
.search(query, MINISEARCH_OPTIONS)
|
||||
.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
console.debug(`Search results for ${providerTitle}:`, results.length);
|
||||
|
||||
return results;
|
||||
},
|
||||
[minisearches],
|
||||
);
|
||||
|
||||
const getSubmenuContextItems = useMemo(
|
||||
() =>
|
||||
(
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
limit: number = MAX_LENGTH,
|
||||
): (ContextSubmenuItem & { providerTitle: string })[] => {
|
||||
console.debug(
|
||||
"Executing getSubmenuContextItems. Provider:",
|
||||
providerTitle,
|
||||
"Query:",
|
||||
query,
|
||||
"Limit:",
|
||||
limit,
|
||||
);
|
||||
|
||||
const results = getSubmenuSearchResults(providerTitle, query);
|
||||
if (results.length === 0) {
|
||||
const fallbackItems = (fallbackResults[providerTitle] ?? [])
|
||||
.slice(0, limit)
|
||||
.map((result) => {
|
||||
return {
|
||||
...result,
|
||||
providerTitle,
|
||||
};
|
||||
});
|
||||
console.debug("Using fallback results:", fallbackItems.length);
|
||||
return fallbackItems;
|
||||
}
|
||||
const limitedResults = results.slice(0, limit).map((result) => {
|
||||
return {
|
||||
id: result.id,
|
||||
title: result.title,
|
||||
description: result.description,
|
||||
providerTitle: result.providerTitle,
|
||||
};
|
||||
});
|
||||
return limitedResults;
|
||||
},
|
||||
[fallbackResults, getSubmenuSearchResults],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (contextProviderDescriptions.length === 0 || loaded) {
|
||||
return;
|
||||
|
|
@ -141,61 +225,6 @@ function useSubmenuContextProviders() {
|
|||
});
|
||||
}, [contextProviderDescriptions, loaded]);
|
||||
|
||||
function getSubmenuSearchResults(
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
): SearchResult[] {
|
||||
if (providerTitle === undefined) {
|
||||
// Return search combined from all providers
|
||||
const results = Object.keys(minisearches).map((providerTitle) => {
|
||||
const results = minisearches[providerTitle].search(
|
||||
query,
|
||||
MINISEARCH_OPTIONS,
|
||||
);
|
||||
return results.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
});
|
||||
|
||||
return results.flat().sort((a, b) => b.score - a.score);
|
||||
}
|
||||
if (!minisearches[providerTitle]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return minisearches[providerTitle]
|
||||
.search(query, MINISEARCH_OPTIONS)
|
||||
.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
}
|
||||
|
||||
function getSubmenuContextItems(
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
limit: number = MAX_LENGTH,
|
||||
): (ContextSubmenuItem & { providerTitle: string })[] {
|
||||
const results = getSubmenuSearchResults(providerTitle, query);
|
||||
if (results.length === 0) {
|
||||
return (fallbackResults[providerTitle] ?? [])
|
||||
.slice(0, limit)
|
||||
.map((result) => {
|
||||
return {
|
||||
...result,
|
||||
providerTitle,
|
||||
};
|
||||
});
|
||||
}
|
||||
return results.slice(0, limit).map((result) => {
|
||||
return {
|
||||
id: result.id,
|
||||
title: result.title,
|
||||
description: result.description,
|
||||
providerTitle: result.providerTitle,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
getSubmenuContextItems,
|
||||
addItem,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue