diff --git a/spec/atom-environment-spec.js b/spec/atom-environment-spec.js index 991524853..4fdae6c3c 100644 --- a/spec/atom-environment-spec.js +++ b/spec/atom-environment-spec.js @@ -671,6 +671,8 @@ describe('AtomEnvironment', () => { }) it('may be required to be an existing directory', async () => { + spyOn(atom.notifications, 'addWarning') + const nonExistent = path.join(__dirname, 'no') const existingFile = __filename const existingDir = path.join(__dirname, 'fixtures') @@ -683,6 +685,11 @@ describe('AtomEnvironment', () => { expect(atom.workspace.getTextEditors()).toEqual([]) expect(atom.project.getPaths()).toEqual([existingDir]) + + expect(atom.notifications.addWarning).toHaveBeenCalledWith( + 'Unable to open project folders', + {description: `The directories \`${nonExistent}\` and \`${existingFile}\` do not exist.`} + ) }) }) diff --git a/src/atom-environment.js b/src/atom-environment.js index 4e3d7fb30..e53d2b936 100644 --- a/src/atom-environment.js +++ b/src/atom-environment.js @@ -1364,6 +1364,7 @@ or use Pane::saveItemAs for programmatic saving.`) const needsProjectPaths = this.project && this.project.getPaths().length === 0 const foldersToAddToProject = new Set() const fileLocationsToOpen = [] + const missingFolders = [] // Asynchronously fetch stat information about each requested path to open. const locationStats = await Promise.all( @@ -1386,9 +1387,13 @@ or use Pane::saveItemAs for programmatic saving.`) if (stats.isDirectory()) { // Directory: add as a project folder foldersToAddToProject.add(this.project.getDirectoryForProjectPath(pathToOpen).getPath()) - } else if (stats.isFile() && !location.mustBeDirectory) { - // File: add as a file location - fileLocationsToOpen.push(location) + } else if (stats.isFile()) { + if (!location.mustBeDirectory) { + // File: add as a file location + fileLocationsToOpen.push(location) + } else { + missingFolders.push(location) + } } } else { // Path does not exist @@ -1397,7 +1402,10 @@ or use Pane::saveItemAs for programmatic saving.`) if (directory) { // Found: add as a project folder foldersToAddToProject.add(directory.getPath()) - } else if (!location.mustBeDirectory) { + } else if (location.mustBeDirectory) { + // Not found and must be a directory: add to missing list + missingFolders.push(location) + } else { // Not found: open as a new file fileLocationsToOpen.push(location) } @@ -1430,6 +1438,33 @@ or use Pane::saveItemAs for programmatic saving.`) await Promise.all(fileOpenPromises) } + if (missingFolders.length > 0) { + let message = 'Unable to open project folder' + if (missingFolders.length > 1) { + message += 's' + } + + let description = 'The ' + if (missingFolders.length === 1) { + description += 'directory `' + description += missingFolders[0].pathToOpen + description += '` does not exist.' + } else if (missingFolders.length === 2) { + description += `directories \`${missingFolders[0].pathToOpen}\` ` + description += `and \`${missingFolders[1].pathToOpen}\` do not exist.` + } else { + description += 'directories ' + description += (missingFolders + .slice(0, -1) + .map(location => location.pathToOpen) + .map(pathToOpen => '`' + pathToOpen + '`, ') + .join('')) + description += 'and `' + missingFolders[missingFolders.length - 1].pathToOpen + '` do not exist.' + } + + this.notifications.addWarning(message, {description}) + } + ipcRenderer.send('window-command', 'window:locations-opened') }