Skip to content

Commit

Permalink
Fix hanging startup tasks (posit-dev#3327)
Browse files Browse the repository at this point in the history
Use await instead of parallelized promise
  • Loading branch information
timtmok authored May 31, 2024
1 parent 73a7a2e commit f6b428d
Showing 1 changed file with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,53 +258,41 @@ export class PositronNewProjectService extends Disposable implements IPositronNe
*/
private async _runGitInit() {
const projectRoot = URI.file(this._newProjectConfig?.projectFolder!);
const gitInitTask = new Promise(() => {
// true to skip the folder prompt
this._commandService.executeCommand('git.init', true)
.catch((error) => {
const errorMessage = localize('positronNewProjectService.gitInitError', 'Error initializing git repository {0}', error);
this._notificationService.error(errorMessage);
});
});
const readmeTask = new Promise(() => {
this._fileService.createFile(joinPath(projectRoot, 'README.md'), VSBuffer.fromString(`# ${this._newProjectConfig?.projectName}`))
.catch((error) => {
this._handleGitIgnoreError(error);
});
});
const tasks = [gitInitTask, readmeTask];

// true to skip the folder prompt
await this._commandService.executeCommand('git.init', true)
.catch((error) => {
const errorMessage = localize('positronNewProjectService.gitInitError', 'Error initializing git repository {0}', error);
this._notificationService.error(errorMessage);
});
await this._fileService.createFile(joinPath(projectRoot, 'README.md'), VSBuffer.fromString(`# ${this._newProjectConfig?.projectName}`))
.catch((error) => {
this._handleGitIgnoreError(error);
});

// TODO: use enum values instead of strings
switch (this._newProjectConfig?.projectType) {
case 'Python Project':
tasks.push(new Promise(() => {
this._fileService.createFile(joinPath(projectRoot, '.gitignore'), VSBuffer.fromString(DOT_IGNORE_PYTHON))
.catch((error) => {
this._handleGitIgnoreError(error);
});
}));
await this._fileService.createFile(joinPath(projectRoot, '.gitignore'), VSBuffer.fromString(DOT_IGNORE_PYTHON))
.catch((error) => {
this._handleGitIgnoreError(error);
});
break;
case 'R Project':
tasks.push(new Promise(() => {
this._fileService.createFile(joinPath(projectRoot, '.gitignore'), VSBuffer.fromString(DOT_IGNORE_R))
.catch((error) => {
this._handleGitIgnoreError(error);
});
}));
await this._fileService.createFile(joinPath(projectRoot, '.gitignore'), VSBuffer.fromString(DOT_IGNORE_R))
.catch((error) => {
this._handleGitIgnoreError(error);
});
break;
case 'Jupyter Notebook':
tasks.push(new Promise(() => {
this._fileService.createFile(joinPath(projectRoot, '.gitignore'), VSBuffer.fromString(DOT_IGNORE_JUPYTER))
.catch((error) => {
this._handleGitIgnoreError(error);
});
}));
await this._fileService.createFile(joinPath(projectRoot, '.gitignore'), VSBuffer.fromString(DOT_IGNORE_JUPYTER))
.catch((error) => {
this._handleGitIgnoreError(error);
});
break;
default:
}

await Promise.allSettled(tasks);

this._removePendingTask(NewProjectTask.Git);
}

Expand Down

0 comments on commit f6b428d

Please sign in to comment.