Skip to content

Commit

Permalink
chore: improve debug logging util (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn authored Sep 16, 2023
1 parent ae828db commit f723f6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { activateTaskProvider } from "./tasks";
import { getTsApi } from "./ts_api";
import type { DenoExtensionContext, Settings } from "./types";
import { assert } from "./util";
import * as util from "util";

import * as vscode from "vscode";

Expand Down Expand Up @@ -218,6 +219,12 @@ function handleTextDocumentSave(doc: vscode.TextDocument) {
}
}

export function log(...msgs: unknown[]) {
extensionContext.outputChannel.appendLine(
msgs.map((m) => typeof m === "string" ? m : util.inspect(m)).join(" "),
);
}

const extensionContext = {} as DenoExtensionContext;

/** When the extension activates, this function is called with the extension
Expand Down
12 changes: 9 additions & 3 deletions typescript-deno-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { PluginSettings, Settings } from "../../client/src/shared_types";
import type * as ts from "../node_modules/typescript/lib/tsserverlibrary";
import * as path from "path";
import * as os from "os";
import * as util from "util";

/** Extract the return type from a maybe function. */
// deno-lint-ignore no-explicit-any
Expand Down Expand Up @@ -114,12 +115,17 @@ class Plugin implements ts.server.PluginModule {
this.#denoEnabled();
}

#log = (_msg: string) => {};
#log = (..._msgs: unknown[]) => {};

create(info: ts.server.PluginCreateInfo): ts.LanguageService {
const { languageService: ls, project, config } = info;
this.#log = (msg) =>
project.projectService.logger.info(`[typescript-deno-plugin] ${msg}`);
this.#log = (...msgs) => {
project.projectService.logger.info(
`[typescript-deno-plugin] ${
msgs.map((m) => typeof m === "string" ? m : util.inspect(m)).join(" ")
}`,
);
};

this.#project = project;
this.#projectName = project.getProjectName();
Expand Down

0 comments on commit f723f6c

Please sign in to comment.