in src/extension.ts [87:132]
function registerComponents(context: ExtensionContext): void {
registerAskForChoiceCommand(context);
registerAdvanceAskForChoice(context);
registerAskForInputCommand(context);
context.subscriptions.push(
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_OPEN_STACKTRACE, openStackTrace),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.RUN_TEST_FROM_EDITOR, async () => await commands.executeCommand(VSCodeCommands.RUN_TESTS_IN_CURRENT_FILE)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_TEST_FROM_EDITOR, async () => await commands.executeCommand(VSCodeCommands.DEBUG_TESTS_IN_CURRENT_FILE)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_GENERATE_TESTS, ((uri: Uri, startPosition: number) => generateTests(uri, startPosition))),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.RUN_FROM_TEST_EXPLORER, async (node: TestItem, launchConfiguration: DebugConfiguration) => await runTestsFromTestExplorer(node, launchConfiguration, false)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_FROM_TEST_EXPLORER, async (node: TestItem, launchConfiguration: DebugConfiguration) => await runTestsFromTestExplorer(node, launchConfiguration, false)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.REFRESH_TEST_EXPLORER, async () => await refresh()),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.RUN_TEST_FROM_JAVA_PROJECT_EXPLORER, async (node: any) => await runTestsFromJavaProjectExplorer(node, false /* isDebug */)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_TEST_FROM_JAVA_PROJECT_EXPLORER, async (node: any) => await runTestsFromJavaProjectExplorer(node, true /* isDebug */)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.GO_TO_TEST, async () => await navigateToTestOrTarget(true)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.GO_TO_TEST_SUBJECT, async () => await navigateToTestOrTarget(false)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.ENABLE_TESTS, async () => await enableTests()),
window.onDidChangeActiveTextEditor(async (e: TextEditor | undefined) => {
if (await isTestJavaFile(e?.document)) {
await updateItemForDocumentWithDebounce(e!.document.uri);
}
}),
workspace.onDidChangeTextDocument(async (e: TextDocumentChangeEvent) => {
if (await isTestJavaFile(e.document)) {
await updateItemForDocumentWithDebounce(e.document.uri);
}
}),
workspace.onDidChangeWorkspaceFolders(async (e: WorkspaceFoldersChangeEvent) => {
for (const deletedFolder of e.removed) {
testSourceProvider.delete(deletedFolder.uri);
}
// workaround to wait for Java Language Server to accept the workspace folder change event,
// otherwise we cannot find the projects in the new workspace folder.
// TODO: this event should be notified by onDidProjectsImport, we need to fix upstream
setTimeout(() => {
createTestController();
}, 1000);
}),
);
registerTestCodeActionProvider();
createTestController();
showTestItemsInCurrentFile();
commands.executeCommand('setContext', Context.ACTIVATION_CONTEXT_KEY, true);
}