Skip to content

Commit

Permalink
Merge pull request #8137 from petrovic-d/handle-errors-in-test-adapter
Browse files Browse the repository at this point in the history
Error handling for TestAdapter and DBConfigurationProvider
  • Loading branch information
jhorvath authored Jan 14, 2025
2 parents b3bdee7 + 5661a33 commit 11078f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions java/java.lsp.server/vscode/src/dbConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ class DBConfigurationProvider implements vscode.DebugConfigurationProvider {
}

resolveDebugConfigurationWithSubstitutedVariables?(_folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
return new Promise<vscode.DebugConfiguration>(async resolve => {
let o: Object = await vscode.commands.executeCommand('nbls.db.connection');
return new Promise<vscode.DebugConfiguration>(async (resolve, reject) => {
let o: Object;
try {
o = await vscode.commands.executeCommand('nbls.db.connection');
} catch(err) {
console.log(err);
reject(err);
return;
}
if (config === undefined) {
config = {} as vscode.DebugConfiguration;
}
Expand Down
2 changes: 1 addition & 1 deletion java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
};

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel', async (projects?) => {
testAdapter?.runTestsWithParallelParallel(projects);
testAdapter?.runTestsWithParallelProfile(projects);
}));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel.createProfile', async (projects?) => {
Expand Down
23 changes: 17 additions & 6 deletions java/java.lsp.server/vscode/src/testAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class NbTestAdapter {
return this.parallelRunProfile ? true : false;
}

public runTestsWithParallelParallel(projects?: string[]) {
public runTestsWithParallelProfile(projects?: string[]) {
if (this.parallelRunProfile) {
this.run(new TestRunRequest(undefined, undefined, this.parallelRunProfile), new CancellationTokenSource().token, true, projects);
}
Expand All @@ -82,6 +82,7 @@ export class NbTestAdapter {
}
cancellation.onCancellationRequested(() => this.cancel());
this.currentRun = this.testController.createTestRun(request);
this.currentRun.token.onCancellationRequested(() => this.cancel());
this.itemsToRun = new Set();
this.started = false;
if (request.include) {
Expand All @@ -105,18 +106,28 @@ export class NbTestAdapter {
nestedClass = nestedClass.replace('$', '.');
}
if (!cancellation.isCancellationRequested) {
await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1), nestedClass);
try {
await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1), nestedClass);
} catch(err) {
// test state will be handled in the code below
console.log(err);
}
}
}
}
} else {
this.testController.items.forEach(item => this.set(item, 'enqueued'));
for (let workspaceFolder of workspace.workspaceFolders || []) {
if (!cancellation.isCancellationRequested) {
if (testInParallel) {
await commands.executeCommand(COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString(), undefined, undefined, undefined, true, projects);
} else {
await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString());
try {
if (testInParallel) {
await commands.executeCommand(COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString(), undefined, undefined, undefined, true, projects);
} else {
await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString());
}
} catch(err) {
// test state will be handled in the code below
console.log(err);
}
}
}
Expand Down

0 comments on commit 11078f7

Please sign in to comment.