vscode#debug TypeScript Examples
The following examples show how to use
vscode#debug.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 6 votes |
public async loadTests(): Promise<void> {
if (!this.verifyNoTestProcessCurrentlyRunning('New test load request ignored')) {
return;
}
this.isTestProcessRunning = true;
this.logger.debug(() => 'Test load started');
try {
await this.refresh(true);
} finally {
this.isTestProcessRunning = false;
}
}
Example #2
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 6 votes |
private async reload(): Promise<void> {
this.logger.debug(() => 'Test reload started');
if (this.isTestProcessRunning) {
this.logger.debug(() => 'Test reload - Aborting previously running test operation');
await this.cancel();
}
await this.loadTests();
}
Example #3
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 6 votes |
private storeLoadedTests(rootSuite?: TestSuiteInfo) {
this.logger.debug(() => 'Updating loaded test store');
if (rootSuite) {
this.logger.debug(() => 'Storing newly loaded root suite');
this.testStore?.storeRootSuite(rootSuite);
} else {
this.logger.debug(() => 'Clearing loaded root suite');
this.testStore?.clear();
}
}
Example #4
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 6 votes |
private verifyNoTestProcessCurrentlyRunning(message: string): boolean {
if (!this.isTestProcessRunning) {
return true;
}
const otherTestProcessRunningMessage = `${message} - Another test operation is still running`;
this.logger.debug(() => otherTestProcessRunningMessage);
this.notificationHandler.notify(MessageType.Warning, otherTestProcessRunningMessage);
return false;
}
Example #5
Source File: listener.ts From vscode-discord with MIT License | 6 votes |
public listen() {
// just make sure that no double registration happens
this.dispose();
const fileSwitch = window.onDidChangeActiveTextEditor,
fileEdit = workspace.onDidChangeTextDocument,
debugStart = debug.onDidStartDebugSession,
debugEnd = debug.onDidTerminateDebugSession,
diagnostictsChange = languages.onDidChangeDiagnostics;
if (this.config.get("showFile"))
this.disposables.push(
fileSwitch((e: TextEditor) => this.parser.fileSwitch(e)),
fileEdit((e: TextDocumentChangeEvent) =>
this.parser.fileEdit(e)
)
);
if (this.config.get("showDebugging"))
this.disposables.push(
debugStart(() => this.parser.toggleDebug()),
debugEnd(() => this.parser.toggleDebug())
);
if (this.config.get("showProblems"))
this.disposables.push(
diagnostictsChange(() => this.parser.diagnosticsChange())
);
}
Example #6
Source File: config-provider.ts From plugin-vscode with Apache License 2.0 | 5 votes |
export function activateDebugConfigProvider(ballerinaExtInstance: BallerinaExtension) {
let context = <ExtensionContext>ballerinaExtInstance.context;
context.subscriptions.push(debug.registerDebugConfigurationProvider('ballerina', debugConfigProvider));
const factory = new BallerinaDebugAdapterDescriptorFactory(ballerinaExtInstance);
context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory('ballerina', factory));
}
Example #7
Source File: codelens-provider.ts From plugin-vscode with Apache License 2.0 | 5 votes |
async function startDebugging(uri: Uri, testDebug: boolean, ballerinaCmd: string, ballerinaHome: string, args: any[])
: Promise<boolean> {
const workspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(uri);
const debugConfig: DebugConfiguration = await constructDebugConfig(testDebug, ballerinaCmd,
ballerinaHome, args);
return debug.startDebugging(workspaceFolder, debugConfig);
}
Example #8
Source File: debugger.ts From karma-test-explorer with MIT License | 5 votes |
public startDebugSession(
workspaceFolder: WorkspaceFolder,
debuggerNameOrConfig: string | DebugConfiguration,
sessionStartTimeout: number
): Execution<DebugSession> {
const deferredDebugSessionExecution: DeferredExecution<DebugSession> = new DeferredExecution();
const debugSessionExecution = deferredDebugSessionExecution.execution();
const debuggerNamespaceTag = this.options?.debuggerNamespace ? ` - ${this.options?.debuggerNamespace}` : '';
const actualDebuggerNameOrConfig =
typeof debuggerNameOrConfig === 'string'
? debuggerNameOrConfig
: { ...debuggerNameOrConfig, name: `${debuggerNameOrConfig.name}${debuggerNamespaceTag}` };
const debuggerConfigName =
typeof actualDebuggerNameOrConfig === 'string' ? actualDebuggerNameOrConfig : actualDebuggerNameOrConfig.name;
try {
const activeDebugSession = debug.activeDebugSession;
if (activeDebugSession && activeDebugSession.name === debuggerConfigName) {
this.logger.info(() => `Debug session '${activeDebugSession.name}' is alredy active`);
deferredDebugSessionExecution.start(activeDebugSession);
this.activeDebugSession = activeDebugSession;
} else {
const debugStartSubscription: Disposable = debug.onDidStartDebugSession(session => {
if (session.name === debuggerConfigName) {
this.logger.info(() => `Debug session '${session.name}' has started`);
deferredDebugSessionExecution.start(session);
this.activeDebugSession = session;
}
});
debugSessionExecution.started().finally(() => debugStartSubscription.dispose());
debug.startDebugging(workspaceFolder, actualDebuggerNameOrConfig).then(
isSessionStarted => {
if (!isSessionStarted) {
deferredDebugSessionExecution.fail(`Debug session '${debuggerConfigName}' failed to start`);
}
},
reason =>
deferredDebugSessionExecution.fail(
`Debug session '${debuggerConfigName}' failed to start: ${reason.message ?? reason}`
)
);
deferredDebugSessionExecution.failIfNotStarted(
sessionStartTimeout,
`Timeout after waiting ${sessionStartTimeout} ms for debug session '${debuggerConfigName}' to start`
);
}
debugSessionExecution.started().then(debugSession => {
const debugStopSubscription = debug.onDidTerminateDebugSession(session => {
if (session === debugSession) {
this.logger.info(() => `Debug session '${session.name}' has ended`);
deferredDebugSessionExecution.end();
this.activeDebugSession = undefined;
debugStopSubscription.dispose();
}
});
});
} catch (error) {
deferredDebugSessionExecution.fail(`Debug session '${debuggerConfigName}' failed to start: ${error}`);
}
return debugSessionExecution;
}
Example #9
Source File: debugger.ts From karma-test-explorer with MIT License | 5 votes |
public async dispose() {
if (this.activeDebugSession) {
debug.stopDebugging(this.activeDebugSession);
}
await Disposer.dispose(this.logger);
}
Example #10
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 5 votes |
public async runTests(testIds: string[], isDebug: boolean = false): Promise<void> {
if (!isDebug && !this.verifyNoTestProcessCurrentlyRunning('Cannot run new test')) {
return;
}
try {
this.isTestProcessRunning = isDebug ? this.isTestProcessRunning : true;
const testRunStartTime = Date.now();
this.logger.info(() => `${isDebug ? 'Debug test' : 'Test'} run started`);
this.logger.debug(() => `Test run is requested for ${testIds.length} test ids`);
this.logger.trace(() => `Requested test ids for test run: ${JSON.stringify(testIds)}`);
const rootTestSuite = this.testStore?.getRootSuite();
const tests = this.testStore?.getTestsOrSuitesById(testIds) ?? [];
const testsContainOnlyRootSuite = rootTestSuite !== undefined && tests.length === 1 && tests[0] === rootTestSuite;
const runAllTests = testsContainOnlyRootSuite;
this.logger.trace(
() => `Requested ${testIds.length} test Ids resolved to ${tests.length} actual tests: ${JSON.stringify(tests)}`
);
const testRunStartedEvent: TestRunStartedEvent = { type: 'started', tests: testIds };
this.testRunEmitter.fire(testRunStartedEvent);
let runError: string | undefined;
try {
if (!this.testManager.isStarted()) {
this.logger.debug(
() => `${isDebug ? 'Debug test' : 'Test'} run request - Test manager is not started - Starting it`
);
await this.testManager.start();
}
await this.testLocator?.ready();
await this.testManager.runTests(runAllTests ? [] : tests);
} catch (error) {
runError = `${(error as Error).message ?? error}`;
} finally {
const testRunFinishedEvent: TestRunFinishedEvent = { type: 'finished' };
this.testRunEmitter.fire(testRunFinishedEvent);
}
if (runError) {
const errorMessage = `Failed while ${isDebug ? 'debugging' : 'running'} requested tests - ${runError}`;
this.logger.error(() => errorMessage);
this.retireEmitter.fire({ tests: testIds });
this.notificationHandler.notify(MessageType.Error, errorMessage, [
{ label: 'Retry Test Run', handler: () => (isDebug ? this.debugTests(testIds) : this.runTests(testIds)) }
]);
}
const testRunTotalTimeSecs = (Date.now() - testRunStartTime) / 1000;
this.logger.info(
() => ` ${isDebug ? 'Debug test' : 'Test'} run finished in ${testRunTotalTimeSecs.toFixed(2)} secs`
);
} finally {
this.isTestProcessRunning = isDebug ? this.isTestProcessRunning : false;
}
}
Example #11
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 5 votes |
public async debugTests(testIds: string[]): Promise<void> {
if (!this.verifyNoTestProcessCurrentlyRunning('New test debug request ignored')) {
return;
}
this.isTestProcessRunning = true;
this.logger.info(() => 'Starting debug session');
this.logger.debug(() => `Test debug is requested for ${testIds.length} test ids`);
this.logger.trace(() => `Requested test ids for test debug: ${JSON.stringify(testIds)}`);
try {
let debugSessionExecution: Execution<DebugSession>;
let debugSession: DebugSession;
try {
this.logger.debug(() => 'Ensuring Test Manager is started for debug test run');
const serverStartInfo: ServerStartInfo = await this.testManager.start();
const debuggerConfig = this.config.debuggerConfigName || {
...this.config.debuggerConfig,
port: serverStartInfo.debugPort ?? this.config.debuggerConfig.port
};
const debuggerConfigName = typeof debuggerConfig === 'string' ? debuggerConfig : debuggerConfig.name;
const debuggerPort = typeof debuggerConfig !== 'string' ? debuggerConfig.port : undefined;
if (debuggerPort) {
this.logger.debug(
() =>
`Starting debug session '${debuggerConfigName}' ` +
'with requested --> available debug port: ' +
`${this.config.debuggerConfig.port ?? '<none>'} --> ${debuggerPort}`
);
} else {
this.logger.debug(() => `Starting debug session '${debuggerConfigName}'`);
}
const deferredDebugSessionStart = new DeferredPromise();
this.notificationHandler.notifyStatus(
StatusType.Busy,
`Starting debug session: ${debuggerConfigName}`,
deferredDebugSessionStart.promise()
);
debugSessionExecution = this.testDebugger.startDebugSession(
this.workspaceFolder,
debuggerConfig,
DEBUG_SESSION_START_TIMEOUT
);
debugSession = await debugSessionExecution.started();
deferredDebugSessionStart.fulfill();
} catch (error) {
const errorMessage = `Test debug run failed - ${(error as Error).message ?? error}`;
this.logger.error(() => errorMessage);
this.notificationHandler.notify(MessageType.Error, errorMessage, [
{ label: 'Retry Debug', handler: () => this.debugTests(testIds) },
{ label: 'Retry With Run', handler: () => this.runTests(testIds) }
]);
return;
}
await this.runTests(testIds, true);
await debug.stopDebugging(debugSession);
await debugSessionExecution.ended();
} finally {
this.isTestProcessRunning = false;
}
}
Example #12
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 5 votes |
private async refresh(isForcedRefresh: boolean = false): Promise<void> {
this.logger.debug(() => `Test ${isForcedRefresh ? 'hard ' : ''}refresh started`);
const refreshStartTime = Date.now();
const testLoadFinishedEvent: TestLoadFinishedEvent = { type: 'finished' };
let discoveredTests: TestSuiteInfo | undefined;
let testDiscoveryError: string | undefined;
try {
this.testLoadEmitter.fire({ type: 'started' } as TestLoadStartedEvent);
this.testLocator?.refreshFiles();
if (!this.testManager.isStarted()) {
this.logger.debug(() => 'Refresh request - Test manager is not started - Starting it');
await this.testManager.start();
} else if (isForcedRefresh) {
await this.testManager.restart();
}
const testFileLoadCompletion = this.testLocator?.ready();
this.notificationHandler.notifyStatus(StatusType.Busy, 'Loading test files', testFileLoadCompletion);
await testFileLoadCompletion;
discoveredTests = await this.testManager.discoverTests();
testLoadFinishedEvent.suite = discoveredTests;
this.logger.debug(() => `Test discovery got ${discoveredTests?.testCount ?? 0} tests`);
} catch (error) {
if (!(error instanceof CancellationRequestedError)) {
testDiscoveryError = `Failed to load tests - ${(error as Error).message ?? error}`;
testLoadFinishedEvent.errorMessage = testDiscoveryError;
this.logger.error(() => testDiscoveryError!);
this.notificationHandler.notify(MessageType.Error, testDiscoveryError, [
{ label: 'Retry Test Load', handler: () => this.reload() }
]);
}
} finally {
this.storeLoadedTests(discoveredTests);
this.testLoadEmitter.fire(testLoadFinishedEvent);
this.retireEmitter.fire({});
}
const refreshTotalTimeSecs = (Date.now() - refreshStartTime) / 1000;
this.logger.info(
() =>
`Finished loading tests in ${refreshTotalTimeSecs.toFixed(2)} secs ` +
(testDiscoveryError ? '(Failed)' : `(${discoveredTests?.testCount ?? 0} tests loaded)`)
);
}
Example #13
Source File: karma-test-explorer.ts From karma-test-explorer with MIT License | 5 votes |
public async cancel(): Promise<void> {
this.logger.debug(() => 'Test operation cancellation requested - Aborting any currently running test operation');
await this.testManager.stop();
this.isTestProcessRunning = false;
}
Example #14
Source File: extension.ts From vscode-stripe with MIT License | 4 votes |
export function activate(this: any, context: ExtensionContext) {
initializeStripeWorkspaceState(context);
new TelemetryPrompt(context).activate();
const surveyPrompt: SurveyPrompt = new SurveyPrompt(context);
surveyPrompt.activate();
const telemetry = getTelemetry(context);
telemetry.sendEvent('activate');
const stripeOutputChannel = window.createOutputChannel('Stripe');
const stripeClient = new StripeClient(telemetry, context);
const stripeDaemon = new StripeDaemon(stripeClient);
const stripeSamples = new StripeSamples(stripeClient, stripeDaemon);
const stripeEventsViewProvider = new StripeEventsViewProvider(
stripeClient,
stripeDaemon,
context,
);
window.createTreeView('stripeEventsView', {
treeDataProvider: stripeEventsViewProvider,
showCollapseAll: true,
});
const stripeLogsViewProvider = new StripeLogsViewProvider(stripeClient, stripeDaemon, context);
window.createTreeView('stripeLogsView', {
treeDataProvider: stripeLogsViewProvider,
showCollapseAll: true,
});
const stripeWebhooksViewProvider = new StripeWebhooksViewProvider(stripeDaemon);
window.createTreeView('stripeWebhooksView', {
treeDataProvider: stripeWebhooksViewProvider,
showCollapseAll: true,
});
stripeWebhooksViewProvider.refreshEndpoints();
window.createTreeView('stripeSamplesView', {
treeDataProvider: new StripeSamplesViewProvider(),
showCollapseAll: false,
});
window.createTreeView('stripeQuickLinksView', {
treeDataProvider: new StripeQuickLinksViewProvider(),
showCollapseAll: false,
});
const stripeHelpView = window.createTreeView('stripeHelpView', {
treeDataProvider: new StripeHelpViewProvider(),
showCollapseAll: false,
});
stripeHelpView.message = 'This extension runs with your Stripe account in test mode.';
debug.registerDebugConfigurationProvider('stripe', new StripeDebugProvider(telemetry));
workspace.registerTextDocumentContentProvider(
'stripeEvent',
new StripeResourceDocumentContentProvider(context, EVENT_ID_REGEXP, retrieveEventDetails),
);
workspace.registerTextDocumentContentProvider(
'stripeLog',
new StripeResourceDocumentContentProvider(context, LOG_ID_REGEXP, retrieveLogDetails),
);
languages.registerDocumentLinkProvider(
{scheme: 'stripeLog'},
new StripeLogsDashboardLinkProvider(),
);
const git = new Git();
new StripeLinter(telemetry, git).activate();
// Start language Server for hover matching of Stripe methods
const serverModule = context.asAbsolutePath(
path.join('dist', 'stripeLanguageServer', 'server.js'),
);
const serverOptions: ServerOptions = {
run: {
module: serverModule,
transport: TransportKind.ipc,
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: {execArgv: ['--nolazy', '--inspect=6009']},
},
};
StripeLanguageClient.activate(context, serverOptions, telemetry);
const stripeTerminal = new StripeTerminal(stripeClient);
const stripeCommands = new Commands(telemetry, stripeTerminal, context);
const commandCallbackPairs: [string, (...args: any[]) => any][] = [
['stripe.createStripeSample', () => stripeCommands.createStripeSample(stripeSamples)],
['stripe.login', () => stripeCommands.startLogin(stripeDaemon)],
['stripe.openCLI', stripeCommands.openCLI],
['stripe.openDashboardApikeys', stripeCommands.openDashboardApikeys],
['stripe.openDashboardEvent', stripeCommands.openDashboardEvent],
['stripe.openDashboardEvents', stripeCommands.openDashboardEvents],
['stripe.openDashboardLog', stripeCommands.openDashboardLog],
['stripe.openDashboardLogs', stripeCommands.openDashboardLogs],
['stripe.openDashboardWebhooks', stripeCommands.openDashboardWebhooks],
['stripe.openDocs', stripeCommands.openDocs],
['stripe.openEventDetails', stripeCommands.openEventDetails],
['stripe.openLogDetails', stripeCommands.openLogDetails],
['stripe.openReportIssue', stripeCommands.openReportIssue],
['stripe.openSamples', stripeCommands.openSamples],
['stripe.openSurvey', () => stripeCommands.openSurvey(surveyPrompt)],
['stripe.openTelemetryInfo', stripeCommands.openTelemetryInfo],
[
'stripe.openTriggerEvent',
() => stripeCommands.openTriggerEvent(context, stripeDaemon, stripeOutputChannel),
],
[
'stripe.openCreateCustomizedEvent',
() => stripeCommands.openCreateCustomizedEvent(context, stripeDaemon, stripeOutputChannel),
],
[
'stripe.openTriggerCustomizedEvent',
() => stripeCommands.openTriggerCustomizedEvent(stripeDaemon, stripeOutputChannel),
],
['stripe.openWebhooksDebugConfigure', stripeCommands.openWebhooksDebugConfigure],
['stripe.openWebhooksListen', stripeCommands.openWebhooksListen],
[
'stripe.createWebhookEndpoint',
() => stripeCommands.createWebhookEndpoint(stripeDaemon, stripeOutputChannel, stripeWebhooksViewProvider),
],
[
'stripe.resendEvent',
(treeItem) => stripeCommands.resendEvent(treeItem, stripeDaemon, stripeOutputChannel),
],
[
'stripe.startEventsStreaming',
() => stripeCommands.startEventsStreaming(stripeEventsViewProvider),
],
[
'stripe.stopEventsStreaming',
() => stripeCommands.stopEventsStreaming(stripeEventsViewProvider),
],
['stripe.clearRecentEvents', () => stripeCommands.clearRecentEvents(stripeEventsViewProvider)],
['stripe.startLogsStreaming', () => stripeCommands.startLogsStreaming(stripeLogsViewProvider)],
['stripe.stopLogsStreaming', () => stripeCommands.stopLogsStreaming(stripeLogsViewProvider)],
['stripe.clearRecentLogs', () => stripeCommands.clearRecentLogs(stripeLogsViewProvider)],
];
const registeredCommands: Disposable[] = commandCallbackPairs.map(([command, callback]) =>
commands.registerCommand(command, callback),
);
context.subscriptions.push(...registeredCommands);
}