@ -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 ( '.' ) ;