Skip to content

Commit

Permalink
Better vs code logging
Browse files Browse the repository at this point in the history
  • Loading branch information
minestarks committed Jun 27, 2023
1 parent 12d3e0d commit 8aa4ac8
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,7 @@ import { createHoverProvider } from "./hover.js";
import { registerQSharpNotebookHandlers } from "./notebook.js";

export async function activate(context: vscode.ExtensionContext) {
const output = vscode.window.createOutputChannel("Q#");
output.appendLine("Q# extension activated.");

// Override the global logger with functions that write to the output channel
global.qscLog.error = (...args: unknown[]) => {
output.appendLine(
args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")
);
};
global.qscLog.warn = (...args: unknown[]) => {
output.appendLine(
args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")
);
};
global.qscLog.info = (...args: unknown[]) => {
output.appendLine(
args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")
);
};
global.qscLog.debug = (...args: unknown[]) => {
output.appendLine(
args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")
);
};
global.qscLog.trace = (...args: unknown[]) => {
output.appendLine(
args.map((a) => (typeof a === "string" ? a : JSON.stringify(a))).join(" ")
);
};
initializeLogger();

const languageService = await loadLanguageService(context.extensionUri);

Expand Down Expand Up @@ -76,6 +48,19 @@ export async function activate(context: vscode.ExtensionContext) {
);
}

function initializeLogger() {
const output = vscode.window.createOutputChannel("Q#", { log: true });

// Override the global logger with functions that write to the output channel
global.qscLog.error = output.error;
global.qscLog.warn = output.warn;
global.qscLog.info = output.info;
global.qscLog.debug = output.debug;
global.qscLog.trace = output.trace;

global.qscLog.trace("Q# extension activated.");
}

function registerDocumentUpdateHandlers(languageService: ILanguageService) {
vscode.workspace.textDocuments.forEach((document) => {
updateIfQsharpDocument(document);
Expand Down

0 comments on commit 8aa4ac8

Please sign in to comment.