Skip to content

feat: print all logs to the vscode.OutputChannel #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { Status, StatusBarEntry } from './util/status';
export async function activate(context: vscode.ExtensionContext): Promise<ExtensionApi> {
configureLanguage();

const outputChannel = vscode.window.createOutputChannel("Kotlin");
LOG.appendLine = outputChannel.appendLine.bind(outputChannel);
context.subscriptions.push(outputChannel);

const kotlinConfig = vscode.workspace.getConfiguration("kotlin");
let langServerEnabled = kotlinConfig.get("languageServer.enabled");
let debugAdapterEnabled = kotlinConfig.get("debugAdapter.enabled");
Expand Down Expand Up @@ -64,7 +68,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<Extens
status,
config: kotlinConfig,
javaInstallation,
javaOpts
javaOpts,
outputChannel
});

let extensionApi = new ExtensionApi();
Expand Down
8 changes: 3 additions & 5 deletions src/languageSetup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as child_process from "child_process";
import * as util from "util";
import * as fs from "fs";
import * as net from "net";
import * as path from "path";
Expand All @@ -15,8 +16,8 @@ import { RunDebugCodeLens } from "./runDebugCodeLens";
import { MainClassRequest, OverrideMemberRequest } from "./lspExtensions";

/** Downloads and starts the language server. */
export async function activateLanguageServer({ context, status, config, javaInstallation, javaOpts }: ServerSetupParams): Promise<KotlinApi> {
LOG.info('Activating Kotlin Language Server...');
export async function activateLanguageServer({ context, status, config, javaInstallation, javaOpts, outputChannel }: ServerSetupParams): Promise<KotlinApi> {
LOG.info('Activating Kotlin Language Server: {}', util.inspect({ javaInstallation, javaOpts }));
status.update("Activating Kotlin Language Server...");

// Prepare language server
Expand All @@ -35,9 +36,6 @@ export async function activateLanguageServer({ context, status, config, javaInst
}
}

const outputChannel = vscode.window.createOutputChannel("Kotlin");
context.subscriptions.push(outputChannel);

const transportLayer = config.get("languageServer.transport");
let tcpPort: number = null;
let env: any = { ...process.env };
Expand Down
1 change: 1 addition & 0 deletions src/setupParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface ServerSetupParams {
config: vscode.WorkspaceConfiguration;
javaInstallation: JavaInstallation;
javaOpts: string;
outputChannel: vscode.OutputChannel;
}
8 changes: 5 additions & 3 deletions src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export enum LogLevel {

export class Logger {
level: LogLevel;
appendLine: (line: string) => void;

public constructor(level: LogLevel) {
public constructor(level: LogLevel, appendLine: (line: string) => void) {
this.level = level;
this.appendLine = appendLine;
}

private format(msg: String, placeholders: any[]): string {
Expand All @@ -36,7 +38,7 @@ export class Logger {

private log(prefix: String, level: LogLevel, msg: String, placeholders: any[]): void {
if (level >= this.level) {
console.log(prefix + this.format(msg, placeholders));
this.appendLine(prefix + this.format(msg, placeholders));
}
}

Expand All @@ -53,4 +55,4 @@ export class Logger {
public deepTrace(msg: String, ...placeholders: any[]): void { this.log("Extension: [D_TRACE]", LogLevel.DEEP_TRACE, msg, placeholders); }
}

export const LOG = new Logger(LogLevel.INFO);
export const LOG = new Logger(LogLevel.DEBUG, console.log);