Include now-missing project folders in initial state key computation

This commit is contained in:
Ash Wilson 2019-01-24 11:33:44 -05:00
parent 07dc40362f
commit 88d7c6dbdd
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A
2 changed files with 28 additions and 3 deletions

View File

@ -742,6 +742,27 @@ describe('AtomEnvironment', () => {
expect(atom.project.getPaths()).toEqual([])
})
it('includes missing mandatory project folders in computation of initial state key', async () => {
const existingDir = path.join(__dirname, 'fixtures')
const missingDir = path.join(__dirname, 'no')
atom.loadState.andCallFake(function (key) {
if (key === `${existingDir}:${missingDir}`) {
return Promise.resolve(state)
} else {
return Promise.resolve(null)
}
})
await atom.openLocations([
{pathToOpen: existingDir},
{pathToOpen: missingDir, mustBeDirectory: true}
])
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [existingDir], [])
expect(atom.project.getPaths(), [existingDir])
})
it('opens the specified files', async () => {
await atom.openLocations([{pathToOpen: __dirname}, {pathToOpen: __filename}])
expect(atom.attemptRestoreProjectStateForPaths).toHaveBeenCalledWith(state, [__dirname], [__filename])

View File

@ -1404,7 +1404,7 @@ or use Pane::saveItemAs for programmatic saving.`)
// Found: add as a project folder
foldersToAddToProject.add(directory.getPath())
} else if (location.mustBeDirectory) {
// Not found and must be a directory: add to missing list
// Not found and must be a directory: add to missing list and use to derive state key
missingFolders.push(location)
} else {
// Not found: open as a new file
@ -1416,8 +1416,12 @@ or use Pane::saveItemAs for programmatic saving.`)
}
let restoredState = false
if (foldersToAddToProject.size > 0) {
const state = await this.loadState(this.getStateKey(Array.from(foldersToAddToProject)))
if (foldersToAddToProject.size > 0 || missingFolders.length > 0) {
// Include missing folders in the state key so that sessions restored with no-longer-present project root folders
// don't lose data.
const foldersForStateKey = Array.from(foldersToAddToProject)
.concat(missingFolders.map(location => location.pathToOpen))
const state = await this.loadState(this.getStateKey(Array.from(foldersForStateKey)))
// only restore state if this is the first path added to the project
if (state && needsProjectPaths) {