diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f4da6..ad959c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Fixes [#276](https://github.com/eamodio/vscode-gitlens/issues/276) - Lookup for branches without upstreams fails - Fixes [#274](https://github.com/eamodio/vscode-gitlens/issues/274) - TextEditor is closed/disposed occurs when this extension is enabled - Fixes [#288](https://github.com/eamodio/vscode-gitlens/issues/288) - CSS errors on welcome page (mask-* properties) +- Fixes issues with settings migration — should now migrate any existing settings that haven't already been set ## [8.0.0] - 2018-02-07 ### Added diff --git a/src/configuration.ts b/src/configuration.ts index d424539..533bd7e 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -106,6 +106,51 @@ export class Configuration { } } + async migrateIfMissing(from: string, to: string, migrationFn?: (value: TFrom) => TTo) { + const fromInspection = configuration.inspect(from); + if (fromInspection === undefined) return; + + const toInspection = configuration.inspect(to); + if (fromInspection.globalValue !== undefined) { + if (toInspection === undefined || toInspection.globalValue === undefined) { + await this.update(to, migrationFn ? migrationFn(fromInspection.globalValue as TFrom) : fromInspection.globalValue, ConfigurationTarget.Global); + // Can't delete the old setting currently because it errors with `Unable to write to User Settings because is not a registered configuration` + // if (from !== to) { + // try { + // await this.update(from, undefined, ConfigurationTarget.Global); + // } + // catch { } + // } + } + } + + if (fromInspection.workspaceValue !== undefined) { + if (toInspection === undefined || toInspection.workspaceValue === undefined) { + await this.update(to, migrationFn ? migrationFn(fromInspection.workspaceValue as TFrom) : fromInspection.workspaceValue, ConfigurationTarget.Workspace); + // Can't delete the old setting currently because it errors with `Unable to write to User Settings because is not a registered configuration` + // if (from !== to) { + // try { + // await this.update(from, undefined, ConfigurationTarget.Workspace); + // } + // catch { } + // } + } + } + + if (fromInspection.workspaceFolderValue !== undefined) { + if (toInspection === undefined || toInspection.workspaceFolderValue === undefined) { + await this.update(to, migrationFn ? migrationFn(fromInspection.workspaceFolderValue as TFrom) : fromInspection.workspaceFolderValue, ConfigurationTarget.WorkspaceFolder); + // Can't delete the old setting currently because it errors with `Unable to write to User Settings because is not a registered configuration` + // if (from !== to) { + // try { + // await this.update(from, undefined, ConfigurationTarget.WorkspaceFolder); + // } + // catch { } + // } + } + } + } + name(name: K) { return Functions.propOf(emptyConfig as IConfig, name); } diff --git a/src/extension.ts b/src/extension.ts index a32a647..d567531 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -120,7 +120,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin await configuration.migrate('gitExplorer.gravatarsDefault', configuration.name('defaultGravatarsStyle').value); } - if (Versions.compare(previous, Versions.from(7, 5, 9)) !== 1) { + if (Versions.compare(previous, Versions.from(7, 5, 10)) !== 1) { await configuration.migrate('annotations.file.gutter.gravatars', configuration.name('blame')('avatars').value); await configuration.migrate('annotations.file.gutter.compact', configuration.name('blame')('compact').value); await configuration.migrate('annotations.file.gutter.dateFormat', configuration.name('blame')('dateFormat').value); @@ -195,6 +195,55 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin return v as HighlightLocations[]; }); } + + if (Versions.compare(previous, Versions.from(8, 0, 0)) !== 1) { + await configuration.migrateIfMissing('annotations.file.gutter.gravatars', configuration.name('blame')('avatars').value); + await configuration.migrateIfMissing('annotations.file.gutter.compact', configuration.name('blame')('compact').value); + await configuration.migrateIfMissing('annotations.file.gutter.dateFormat', configuration.name('blame')('dateFormat').value); + await configuration.migrateIfMissing('annotations.file.gutter.format', configuration.name('blame')('format').value); + await configuration.migrateIfMissing('annotations.file.gutter.heatmap.enabled', configuration.name('blame')('heatmap')('enabled').value); + await configuration.migrateIfMissing('annotations.file.gutter.heatmap.location', configuration.name('blame')('heatmap')('location').value); + await configuration.migrateIfMissing('annotations.file.gutter.lineHighlight.enabled', configuration.name('blame')('highlight')('enabled').value); + await configuration.migrateIfMissing('annotations.file.gutter.lineHighlight.locations', configuration.name('blame')('highlight')('locations').value); + await configuration.migrateIfMissing('annotations.file.gutter.separateLines', configuration.name('blame')('separateLines').value); + + await configuration.migrateIfMissing('codeLens.locations', configuration.name('codeLens')('scopes').value); + await configuration.migrateIfMissing<{ customSymbols?: string[], language: string | undefined, locations: CodeLensScopes[] }[], CodeLensLanguageScope[]>('codeLens.perLanguageLocations', configuration.name('codeLens')('scopesByLanguage').value, + v => { + const scopes = v.map(ls => { + return { + language: ls.language, + scopes: ls.locations, + symbolScopes: ls.customSymbols + }; + }); + return scopes; + }); + await configuration.migrateIfMissing('codeLens.customLocationSymbols', configuration.name('codeLens')('symbolScopes').value); + + await configuration.migrateIfMissing('annotations.line.trailing.dateFormat', configuration.name('currentLine')('dateFormat').value); + await configuration.migrateIfMissing('blame.line.enabled', configuration.name('currentLine')('enabled').value); + await configuration.migrateIfMissing('annotations.line.trailing.format', configuration.name('currentLine')('format').value); + + await configuration.migrateIfMissing('annotations.file.gutter.hover.changes', configuration.name('hovers')('annotations')('changes').value); + await configuration.migrateIfMissing('annotations.file.gutter.hover.details', configuration.name('hovers')('annotations')('details').value); + await configuration.migrateIfMissing('annotations.file.gutter.hover.details', configuration.name('hovers')('annotations')('enabled').value); + await configuration.migrateIfMissing('annotations.file.gutter.hover.wholeLine', configuration.name('hovers')('annotations')('over').value, v => v ? 'line' : 'annotation'); + + await configuration.migrateIfMissing('annotations.line.trailing.hover.changes', configuration.name('hovers')('currentLine')('changes').value); + await configuration.migrateIfMissing('annotations.line.trailing.hover.details', configuration.name('hovers')('currentLine')('details').value); + await configuration.migrateIfMissing('blame.line.enabled', configuration.name('hovers')('currentLine')('enabled').value); + await configuration.migrateIfMissing('annotations.line.trailing.hover.wholeLine', configuration.name('hovers')('currentLine')('over').value, v => v ? 'line' : 'annotation'); + + await configuration.migrateIfMissing('gitExplorer.gravatars', configuration.name('explorers')('avatars').value); + await configuration.migrateIfMissing('gitExplorer.commitFileFormat', configuration.name('explorers')('commitFileFormat').value); + await configuration.migrateIfMissing('gitExplorer.commitFormat', configuration.name('explorers')('commitFormat').value); + await configuration.migrateIfMissing('gitExplorer.stashFileFormat', configuration.name('explorers')('stashFileFormat').value); + await configuration.migrateIfMissing('gitExplorer.stashFormat', configuration.name('explorers')('stashFormat').value); + await configuration.migrateIfMissing('gitExplorer.statusFileFormat', configuration.name('explorers')('statusFileFormat').value); + + await configuration.migrateIfMissing('recentChanges.file.lineHighlight.locations', configuration.name('recentChanges')('highlight')('locations').value); + } } catch (ex) { Logger.error(ex, 'migrateSettings');