feat: 🔊 give users access to Continue server logs

can see logs in ~/.continue/continue.log
This commit is contained in:
Nate Sesti 2023-07-27 11:23:55 -07:00
parent 4e47da8398
commit 5d97349068
10 changed files with 105 additions and 33 deletions

View file

@ -44,3 +44,8 @@ def getConfigFilePath() -> str:
f.write(getDefaultConfigFile())
return path
def getLogFilePath():
path = os.path.join(getGlobalFolderPath(), "continue.log")
return path

View file

@ -13,14 +13,13 @@ def get_file_contents(filepath: str) -> str:
try:
filesize = os.path.getsize(filepath)
if filesize > MAX_SIZE_IN_BYTES:
print("File is over 1MB size limit: ", filepath, filesize)
return ""
return None
with open(filepath, "r") as f:
return f.read()
except Exception as e:
print("Error reading file contents", filepath, e)
return ""
# Some files cannot be read, e.g. binary files
return None
DEFAULT_IGNORE_DIRS = [
@ -68,15 +67,21 @@ class FileContextProvider(ContextProvider):
if len(filepaths) > 1000:
break
return [ContextItem(
content=get_file_contents(file)[:min(
2000, len(get_file_contents(file)))],
description=ContextItemDescription(
name=os.path.basename(file),
description=file,
id=ContextItemId(
provider_title=self.title,
item_id=re.sub(r'[^0-9a-zA-Z_-]', '', file)
items = []
for file in filepaths:
content = get_file_contents(file)
if content is None:
continue # no pun intended
items.append(ContextItem(
content=content[:min(2000, len(content))],
description=ContextItemDescription(
name=os.path.basename(file),
description=file,
id=ContextItemId(
provider_title=self.title,
item_id=re.sub(r'[^0-9a-zA-Z_-]', '', file)
)
)
)
) for file in filepaths]
))
return items

View file

@ -1,4 +1,5 @@
import asyncio
import sys
import time
import psutil
import os
@ -7,10 +8,13 @@ from fastapi.middleware.cors import CORSMiddleware
import atexit
import uvicorn
import argparse
import logging.config
from .ide import router as ide_router
from .gui import router as gui_router
from .session_manager import session_manager
from ..libs.util.paths import getLogFilePath
app = FastAPI()
@ -39,12 +43,31 @@ parser.add_argument("-p", "--port", help="server port",
type=int, default=65432)
args = parser.parse_args()
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'uvicorn.log',
},
},
'root': {
'level': 'DEBUG',
'handlers': ['file']
}
}
logging.config.dictConfig(LOGGING_CONFIG)
sys.stdout = open(getLogFilePath(), 'w')
# log_file = open('output.log', 'a')
# sys.stdout = log_file
def run_server():
uvicorn.run(app, host="0.0.0.0", port=args.port)
config = uvicorn.Config(app, host="0.0.0.0", port=args.port)
server = uvicorn.Server(config)
server.run()
async def cleanup_coroutine():

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.0.209",
"version": "0.0.210",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.0.209",
"version": "0.0.210",
"license": "Apache-2.0",
"dependencies": {
"@electron/rebuild": "^3.2.10",

View file

@ -14,7 +14,7 @@
"displayName": "Continue",
"pricing": "Free",
"description": "The open-source coding autopilot",
"version": "0.0.209",
"version": "0.0.210",
"publisher": "Continue",
"engines": {
"vscode": "^1.67.0"
@ -106,6 +106,11 @@
"command": "continue.quickFix",
"category": "Continue",
"title": "Quick Fix"
},
{
"command": "continue.viewLogs",
"category": "Continue",
"title": "View Logs"
}
],
"keybindings": [

View file

@ -22,6 +22,10 @@ function getExtensionVersionInt(versionString: string): number {
export async function activateExtension(context: vscode.ExtensionContext) {
extensionContext = context;
console.log("Using Continue version: ", getExtensionVersion());
console.log(
"In workspace: ",
vscode.workspace.workspaceFolders?.[0].uri.fsPath
);
// Before anything else, check whether this is an out-of-date version of the extension
// Do so by grabbing the package.json off of the GitHub respository for now.
fetch(PACKAGE_JSON_RAW_GITHUB_URL)

View file

@ -53,7 +53,16 @@ async function retryThenFail(
}
} finally {
console.log("After retries, failed to set up Continue extension", msg);
vscode.window.showErrorMessage(msg);
vscode.window
.showErrorMessage(msg, "View Logs", "Retry")
.then((selection) => {
if (selection === "View Logs") {
vscode.commands.executeCommand("continue.viewLogs");
} else if (selection === "Retry") {
// Reload VS Code window
vscode.commands.executeCommand("workbench.action.reloadWindow");
}
});
}
throw e;

View file

@ -1,9 +1,6 @@
import * as vscode from "vscode";
import {
decorationManager,
showAnswerInTextEditor,
showGutterSpinner,
} from "./decorations";
import * as path from "path";
import * as os from "os";
import {
acceptSuggestionCommand,
rejectSuggestionCommand,
@ -65,6 +62,12 @@ const commandsMap: { [command: string]: (...args: any) => any } = {
ideProtocolClient.sendMainUserInput(text);
}
},
"continue.viewLogs": async () => {
// Open ~/.continue/continue.log
const logFile = path.join(os.homedir(), ".continue", "continue.log");
const uri = vscode.Uri.file(logFile);
await vscode.window.showTextDocument(uri);
},
};
export function registerAllCommands(context: vscode.ExtensionContext) {

View file

@ -72,9 +72,16 @@ class IdeProtocolClient {
});
messenger.onMessage((messageType, data, messenger) => {
this.handleMessage(messageType, data, messenger).catch((err) => {
vscode.window.showErrorMessage(
"Error handling message from Continue server: " + err.message
);
vscode.window
.showErrorMessage(
"Error handling message from Continue server: " + err.message,
"View Logs"
)
.then((selection) => {
if (selection === "View Logs") {
vscode.commands.executeCommand("continue.viewLogs");
}
});
});
});
}

View file

@ -10,9 +10,20 @@ async function dynamicImportAndActivate(context: vscode.ExtensionContext) {
await activateExtension(context);
} catch (e) {
console.log("Error activating extension: ", e);
vscode.window.showInformationMessage(
"Error activating the Continue extension."
);
vscode.window
.showInformationMessage(
"Error activating the Continue extension.",
"View Logs",
"Retry"
)
.then((selection) => {
if (selection === "View Logs") {
vscode.commands.executeCommand("continue.viewLogs");
} else if (selection === "Retry") {
// Reload VS Code window
vscode.commands.executeCommand("workbench.action.reloadWindow");
}
});
}
}