-
Notifications
You must be signed in to change notification settings - Fork 405
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
feat: core extension command log #5856
base: develop
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
export enum CommandEventType { | ||
START = 'start', | ||
END = 'end', | ||
EXIT_CODE = 'exitCode', | ||
DATA = 'data', | ||
ERROR = 'error' | ||
} | ||
|
||
export type CommandEventStart = { | ||
type: CommandEventType.START; | ||
commandId: string; | ||
}; | ||
|
||
export type CommandEventEnd = { | ||
type: CommandEventType.END; | ||
commandId: string; | ||
}; | ||
|
||
export type CommandEventExitCode = { | ||
type: CommandEventType.EXIT_CODE; | ||
exitCode: number; | ||
}; | ||
|
||
export type CommandEventData = { | ||
type: CommandEventType.DATA; | ||
data: any; | ||
}; | ||
|
||
export type CommandEventError = { | ||
type: CommandEventType.ERROR; | ||
error: string; | ||
}; | ||
|
||
export type CommandEvent = CommandEventStart | CommandEventEnd | CommandEventExitCode | CommandEventData | CommandEventError; | ||
|
||
export class CommandEventStream { | ||
private static instance: CommandEventStream; | ||
private readonly eventEmitter = new vscode.EventEmitter<CommandEvent>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be assigned in the constructor for testability? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS complains somewhere about the member not being initialized if I do that, when I write the tests I'll see if I can refactor to make everything happy. |
||
|
||
private constructor() {} | ||
|
||
public static getInstance(): CommandEventStream { | ||
if (!CommandEventStream.instance) { | ||
CommandEventStream.instance = new CommandEventStream(); | ||
} | ||
return CommandEventStream.instance; | ||
} | ||
|
||
public initialize(extensionContext: vscode.ExtensionContext) { | ||
extensionContext.subscriptions.push(this.eventEmitter); | ||
} | ||
|
||
public readonly onCommandEvent: vscode.Event<CommandEvent> = this.eventEmitter.event; | ||
|
||
public post(event: CommandEvent) { | ||
this.eventEmitter.fire(event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we wrap this in a try/catch and log, but not fail on the error if on occurs? It'd be good to avoid failing command execution due to monitoring code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. good call |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a safer way to do this without all the eslint bypasses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see what I can do.