Skip to content
Draft
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
13 changes: 7 additions & 6 deletions src/LanguageServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import * as path from 'path';
import type { Disposable } from 'vscode';
import { window, workspace } from 'vscode';
import { BusyStatus, NotificationName, standardizePath as s } from 'brighterscript';
import { Logger } from '@rokucommunity/logger';
import { CustomCommands, Deferred } from 'brighterscript';
import { logger as extensionLogger } from './extensionLogger';

const logger = extensionLogger.createLogger('LanguageServerManager');
import type { CodeWithSourceMap } from 'source-map';
import BrightScriptDefinitionProvider from './BrightScriptDefinitionProvider';
import { BrightScriptWorkspaceSymbolProvider, SymbolInformationRepository } from './SymbolInformationRepository';
Expand Down Expand Up @@ -279,7 +281,7 @@ export class LanguageServerManager {
this.client = this.constructLanguageClient();

this.client.onDidChangeState((event: StateChangeEvent) => {
console.log(new Date().toLocaleTimeString(), 'onDidChangeState', State[event.newState]);
logger.info('onDidChangeState', State[event.newState]);
this.lspRunTracker.setState(event.newState);
});

Expand Down Expand Up @@ -316,7 +318,6 @@ export class LanguageServerManager {
private registerBusyStatusHandler() {
let timeoutHandle: NodeJS.Timeout;

const logger = new Logger();
this.client.onNotification(NotificationName.busyStatus, (event: any) => {
this.updateStatusbar(event.status === BusyStatus.busy, event.activeRuns);

Expand Down Expand Up @@ -487,7 +488,7 @@ export class LanguageServerManager {
try {
this.selectedBscInfo = await this.ensureBscVersionInstalled(versionInfo);
} catch (e) {
console.error(e);
logger.error(e);
//fall back to the embedded version, and show a popup (don't await the popup because that blocks this flow)
void vscode.window.showErrorMessage(`Language server failure. Did you forget \`npm install\`? Using embedded version ${this.embeddedBscInfo.version}. Can't find language server for "${versionInfo}"`);
this.selectedBscInfo = this.embeddedBscInfo;
Expand Down Expand Up @@ -608,7 +609,7 @@ export class LanguageServerManager {

} catch (e) {
if (retryCount > 0) {
console.error('Failed to install brighterscript', versionInfo, e);
logger.error('Failed to install brighterscript', versionInfo, e);

//if the install failed for some reason, uninstall the package and try again
await this.localPackageManager.uninstall('brighterscript', versionInfo);
Expand Down Expand Up @@ -673,7 +674,7 @@ function OneAtATime(options: { timeout?: number }) {
//race for the timeout to expire (we give up waiting for the previous task to complete)
timer.then(() => {
//our timer fired before we had a chance to cancel it. Report the error and move on
console.error(`timer expired waiting for the previous ${propertyKey} to complete. Running the next instance`, target);
logger.error(`timer expired waiting for the previous ${propertyKey} to complete. Running the next instance`, target);
})
//now we can move on to the actual task
]).then(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { standardizePath as s } from 'brighterscript';
import { PerfettoEditorProvider } from './editors/PerfettoEditor';
import { RokuProjectManager } from './managers/RokuProject/RokuProjectManager';
import { RokuProjectsViewProvider } from './viewProviders/RokuProjectsViewProvider';
import { attachExtensionOutputChannel } from './extensionLogger';

export class Extension {
public outputChannel: vscode.OutputChannel;
Expand Down Expand Up @@ -81,6 +82,7 @@ export class Extension {

this.telemetryManager.sendStartupEvent();
this.extensionOutputChannel = util.createOutputChannel('BrightScript Extension', this.writeExtensionLog.bind(this));
attachExtensionOutputChannel(this.extensionOutputChannel);
this.extensionOutputChannel.appendLine('Extension startup');
this.deviceManager = new DeviceManager(context, this.globalStateManager, this.extensionOutputChannel);
let userInputManager = new UserInputManager(
Expand Down
57 changes: 57 additions & 0 deletions src/extensionLogger.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BrighterScript and roku-debug both call this file logging.ts, let's standardize on that.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type * as vscode from 'vscode';
import type { LogMessage, Transport } from '@rokucommunity/logger';
import { Logger, ConsoleTransport } from '@rokucommunity/logger';

/**
* Routes log messages to a vscode OutputChannel once one has been attached.
* Until then, messages are buffered so logs emitted during module load
* (before extension activation) are not lost.
*/
class OutputChannelTransport implements Transport {
private channel: vscode.OutputChannel | undefined;
private buffer: LogMessage[] = [];

public attach(channel: vscode.OutputChannel) {
this.channel = channel;
for (const message of this.buffer) {
this.write(message);
}
this.buffer = [];
}

public pipe(message: LogMessage) {
if (this.channel) {
this.write(message);
} else {
this.buffer.push(message);
}
}

private write(message: LogMessage) {
this.channel.appendLine(message.logger.formatMessage(message, false));
}
}

const outputChannelTransport = new OutputChannelTransport();

/**
* Singleton logger for the extension. Writes to the developer console (for
* extension-host debugging) and to the `BrightScript Extension` output channel
* (for end-users). Use `logger.createLogger('Prefix')` to make a sub-logger
* that tags every message with a component name.
*/
export const logger = new Logger({
logLevel: 'log',
transports: [
new ConsoleTransport(),
outputChannelTransport
]
});

/**
* Attach the extension output channel to the shared logger. Should be called
* once during extension activation, right after the channel is created.
*/
export function attachExtensionOutputChannel(channel: vscode.OutputChannel) {
outputChannelTransport.attach(channel);
}
Loading