mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 01:25:43 -05:00
Adds settings migration support
This commit is contained in:
154
package.json
154
package.json
@@ -516,14 +516,10 @@
|
||||
"gitlens.advanced.menus": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"explorerContext": {
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true
|
||||
},
|
||||
"editorContext": {
|
||||
"blame": true,
|
||||
"copy": true,
|
||||
"details": true,
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"lineDiff": true,
|
||||
@@ -533,6 +529,7 @@
|
||||
"blame": true,
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true,
|
||||
"status": true
|
||||
},
|
||||
"editorTitleContext": {
|
||||
@@ -540,37 +537,21 @@
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true
|
||||
},
|
||||
"explorerContext": {
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true
|
||||
}
|
||||
},
|
||||
"description": "Specifies which commands will be added to which menus",
|
||||
"properties": {
|
||||
"explorerContext": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true
|
||||
},
|
||||
"properties": {
|
||||
"fileDiff": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"history": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"remote": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"editorContext": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"blame": true,
|
||||
"copy": true,
|
||||
"details": true,
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"lineDiff": true,
|
||||
@@ -613,6 +594,7 @@
|
||||
"blame": true,
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true,
|
||||
"status": true
|
||||
},
|
||||
"properties": {
|
||||
@@ -628,6 +610,10 @@
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"remote": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"status": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
@@ -660,6 +646,28 @@
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"explorerContext": {
|
||||
"type": "object",
|
||||
"default": {
|
||||
"fileDiff": true,
|
||||
"history": true,
|
||||
"remote": true
|
||||
},
|
||||
"properties": {
|
||||
"fileDiff": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"history": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"remote": {
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -977,26 +985,56 @@
|
||||
"when": "gitlens:enabled"
|
||||
}
|
||||
],
|
||||
"explorer/context": [
|
||||
"editor/context": [
|
||||
{
|
||||
"command": "gitlens.openFileInRemote",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.remote",
|
||||
"when": "editorTextFocus && gitlens:isTracked && gitlens:hasRemotes && config.gitlens.advanced.menus.editorContext.remote",
|
||||
"group": "navigation@100"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffWithPrevious",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.fileDiff",
|
||||
"command": "gitlens.diffLineWithPrevious",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.lineDiff",
|
||||
"group": "1_gitlens@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffWithWorking",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.fileDiff",
|
||||
"command": "gitlens.diffLineWithWorking",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.lineDiff",
|
||||
"group": "1_gitlens@2"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.showQuickFileHistory",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.history",
|
||||
"command": "gitlens.showQuickCommitFileDetails",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.details",
|
||||
"group": "1_gitlens@3"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffWithPrevious",
|
||||
"when": "editorTextFocus && gitlens:isTracked && config.gitlens.advanced.menus.editorContext.fileDiff",
|
||||
"group": "1_gitlens_1@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffWithWorking",
|
||||
"when": "editorTextFocus && gitlens:isTracked && config.gitlens.advanced.menus.editorContext.fileDiff",
|
||||
"group": "1_gitlens_1@2"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.showQuickFileHistory",
|
||||
"when": "gitlens:isTracked && config.gitlens.advanced.menus.editorContext.history",
|
||||
"group": "3_gitlens@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.toggleFileBlame",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.blame",
|
||||
"group": "3_gitlens@2"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.copyShaToClipboard",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.copy",
|
||||
"group": "9_gitlens@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.copyMessageToClipboard",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.copy",
|
||||
"group": "9_gitlens@2"
|
||||
}
|
||||
],
|
||||
"editor/title": [
|
||||
@@ -1068,56 +1106,26 @@
|
||||
"group": "1_gitlens_2@2"
|
||||
}
|
||||
],
|
||||
"editor/context": [
|
||||
"explorer/context": [
|
||||
{
|
||||
"command": "gitlens.openFileInRemote",
|
||||
"when": "editorTextFocus && gitlens:isTracked && gitlens:hasRemotes && config.gitlens.advanced.menus.editorContext.remote",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.remote",
|
||||
"group": "navigation@100"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffLineWithPrevious",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.lineDiff",
|
||||
"command": "gitlens.diffWithPrevious",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.fileDiff",
|
||||
"group": "1_gitlens@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffLineWithWorking",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.lineDiff",
|
||||
"command": "gitlens.diffWithWorking",
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.fileDiff",
|
||||
"group": "1_gitlens@2"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.showQuickCommitFileDetails",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.details",
|
||||
"group": "1_gitlens@3"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffWithPrevious",
|
||||
"when": "editorTextFocus && gitlens:isTracked && config.gitlens.advanced.menus.editorContext.fileDiff",
|
||||
"group": "1_gitlens_1@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.diffWithWorking",
|
||||
"when": "editorTextFocus && gitlens:isTracked && config.gitlens.advanced.menus.editorContext.fileDiff",
|
||||
"group": "1_gitlens_1@2"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.showQuickFileHistory",
|
||||
"when": "gitlens:isTracked && config.gitlens.advanced.menus.editorContext.history",
|
||||
"group": "3_gitlens@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.toggleFileBlame",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.blame",
|
||||
"group": "3_gitlens@2"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.copyShaToClipboard",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.copy",
|
||||
"group": "9_gitlens@1"
|
||||
},
|
||||
{
|
||||
"command": "gitlens.copyMessageToClipboard",
|
||||
"when": "editorTextFocus && gitlens:isBlameable && config.gitlens.advanced.menus.editorContext.copy",
|
||||
"group": "9_gitlens@2"
|
||||
"when": "gitlens:enabled && config.gitlens.advanced.menus.explorerContext.history",
|
||||
"group": "1_gitlens_1@1"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
131
src/extension.ts
131
src/extension.ts
@@ -16,7 +16,7 @@ import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './command
|
||||
import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
|
||||
import { ToggleCodeLensCommand } from './commands';
|
||||
import { Keyboard } from './commands';
|
||||
import { IConfig } from './configuration';
|
||||
import { BlameLineHighlightLocations, CodeLensLocations, IConfig, LineAnnotationType } from './configuration';
|
||||
import { ApplicationInsightsKey, BuiltInCommands, ExtensionKey, QualifiedExtensionId, WorkspaceState } from './constants';
|
||||
import { CurrentLineController } from './currentLineController';
|
||||
import { GitContentProvider } from './gitContentProvider';
|
||||
@@ -61,9 +61,12 @@ export async function activate(context: ExtensionContext) {
|
||||
telemetryContext['git.version'] = gitVersion;
|
||||
Telemetry.setContext(telemetryContext);
|
||||
|
||||
await migrateSettings(context);
|
||||
notifyOnUnsupportedGitVersion(context, gitVersion);
|
||||
notifyOnNewGitLensVersion(context, gitlensVersion);
|
||||
|
||||
await context.globalState.update(WorkspaceState.GitLensVersion, gitlensVersion);
|
||||
|
||||
const git = new GitService(context, repoPath);
|
||||
context.subscriptions.push(git);
|
||||
|
||||
@@ -124,6 +127,130 @@ export async function activate(context: ExtensionContext) {
|
||||
// this method is called when your extension is deactivated
|
||||
export function deactivate() { }
|
||||
|
||||
async function migrateSettings(context: ExtensionContext) {
|
||||
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion);
|
||||
if (previousVersion === undefined) return;
|
||||
|
||||
const [major] = previousVersion.split('.');
|
||||
if (parseInt(major, 10) >= 4) return;
|
||||
|
||||
try {
|
||||
const cfg = workspace.getConfiguration(ExtensionKey);
|
||||
const prevCfg = workspace.getConfiguration().get<any>(ExtensionKey)!;
|
||||
|
||||
if (prevCfg.blame !== undefined && prevCfg.blame.annotation !== undefined) {
|
||||
switch (prevCfg.blame.annotation.activeLine) {
|
||||
case 'off':
|
||||
await cfg.update('blame.line.enabled', false, true);
|
||||
break;
|
||||
case 'hover':
|
||||
await cfg.update('blame.line.annotationType', LineAnnotationType.Hover, true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (prevCfg.blame.annotation.activeLineDarkColor != null) {
|
||||
await cfg.update('theme.annotations.line.trailing.dark.foregroundColor', prevCfg.blame.annotation.activeLineDarkColor, true);
|
||||
}
|
||||
|
||||
if (prevCfg.blame.annotation.activeLineLightColor != null) {
|
||||
await cfg.update('theme.annotations.line.trailing.light.foregroundColor', prevCfg.blame.annotation.activeLineLightColor, true);
|
||||
}
|
||||
|
||||
switch (prevCfg.blame.annotation.highlight) {
|
||||
case 'none':
|
||||
await cfg.update('blame.file.lineHighlight.enabled', false);
|
||||
break;
|
||||
case 'gutter':
|
||||
await cfg.update('blame.file.lineHighlight.locations', [BlameLineHighlightLocations.Gutter, BlameLineHighlightLocations.OverviewRuler], true);
|
||||
break;
|
||||
case 'line':
|
||||
await cfg.update('blame.file.lineHighlight.locations', [BlameLineHighlightLocations.Line, BlameLineHighlightLocations.OverviewRuler], true);
|
||||
break;
|
||||
case 'both':
|
||||
}
|
||||
|
||||
if (prevCfg.blame.annotation.dateFormat != null) {
|
||||
await cfg.update('annotations.file.gutter.dateFormat', prevCfg.blame.annotation.dateFormat, true);
|
||||
await cfg.update('annotations.line.trailing.dateFormat', prevCfg.blame.annotation.dateFormat, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (prevCfg.codeLens !== undefined) {
|
||||
switch (prevCfg.codeLens.visibility) {
|
||||
case 'ondemand':
|
||||
case 'off':
|
||||
await cfg.update('codeLens.enabled', false);
|
||||
}
|
||||
|
||||
switch (prevCfg.codeLens.location) {
|
||||
case 'all':
|
||||
await cfg.update('codeLens.locations', [CodeLensLocations.Document, CodeLensLocations.Containers, CodeLensLocations.Blocks], true);
|
||||
break;
|
||||
case 'document+containers':
|
||||
await cfg.update('codeLens.locations', [CodeLensLocations.Document, CodeLensLocations.Containers], true);
|
||||
break;
|
||||
case 'document':
|
||||
await cfg.update('codeLens.locations', [CodeLensLocations.Document], true);
|
||||
break;
|
||||
case 'custom':
|
||||
await cfg.update('codeLens.locations', [CodeLensLocations.Custom], true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (prevCfg.codeLens.locationCustomSymbols != null) {
|
||||
await cfg.update('codeLens.customLocationSymbols', prevCfg.codeLens.locationCustomSymbols, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ((prevCfg.menus && prevCfg.menus.diff && prevCfg.menus.diff.enabled) === false) {
|
||||
await cfg.update('advanced.menus', {
|
||||
editorContext: {
|
||||
blame: true,
|
||||
copy: true,
|
||||
details: true,
|
||||
fileDiff: false,
|
||||
history: true,
|
||||
lineDiff: false,
|
||||
remote: true
|
||||
},
|
||||
editorTitle: {
|
||||
blame: true,
|
||||
fileDiff: false,
|
||||
history: true,
|
||||
remote: true,
|
||||
status: true
|
||||
},
|
||||
editorTitleContext: {
|
||||
blame: true,
|
||||
fileDiff: false,
|
||||
history: true,
|
||||
remote: true
|
||||
},
|
||||
explorerContext: {
|
||||
fileDiff: false,
|
||||
history: true,
|
||||
remote: true
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
switch (prevCfg.statusBar && prevCfg.statusBar.date) {
|
||||
case 'off':
|
||||
await cfg.update('statusBar.format', '${author}', true);
|
||||
break;
|
||||
case 'absolute':
|
||||
await cfg.update('statusBar.format', '${author}, ${date}', true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
Logger.error(ex, 'migrateSettings');
|
||||
}
|
||||
finally {
|
||||
await window.showInformationMessage(`GitLens v4 adds many new settings and removes a few old ones, so please review your settings to ensure they are configured properly.`);
|
||||
}
|
||||
}
|
||||
|
||||
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
|
||||
if (context.globalState.get(WorkspaceState.SuppressUpdateNotice, false)) return;
|
||||
|
||||
@@ -143,8 +270,6 @@ async function notifyOnNewGitLensVersion(context: ExtensionContext, version: str
|
||||
}
|
||||
}
|
||||
|
||||
await context.globalState.update(WorkspaceState.GitLensVersion, version);
|
||||
|
||||
if (previousVersion) {
|
||||
const [major, minor] = version.split('.');
|
||||
const [prevMajor, prevMinor] = previousVersion.split('.');
|
||||
|
||||
Reference in New Issue
Block a user