Skip to content

Commit 7862c7c

Browse files
committed
Moves suppressed msgs from globalState to settings
1 parent a963299 commit 7862c7c

File tree

9 files changed

+189
-75
lines changed

9 files changed

+189
-75
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Added
9+
- Adds `gitlens.advanced.messages` setting to specify which messages should be suppressed
10+
11+
### Changed
12+
- Changes from using `globalState` to use `gitlens.advanced.messages` setting for message suppression - provides more control and avoids strange intermittent with `globalState`
13+
714
## [6.1.2] - 2017-11-21
815
### Fixed
916
- Fixes [#207](https://github.com/eamodio/vscode-gitlens/issues/207) - Applying and deleting stashes suddenly stopped working

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ GitLens is highly customizable and provides many configuration settings to allow
463463
|`gitlens.advanced.git`|Specifies the git path to use
464464
|`gitlens.advanced.repositorySearchDepth`|Specifies how many folders deep to search for repositories
465465
|`gitlens.advanced.menus`|Specifies which commands will be added to which menus
466+
|`gitlens.advanced.messages`|Specifies which messages should be suppressed
466467
|`gitlens.advanced.caching.enabled`|Specifies whether git output will be cached
467468
|`gitlens.advanced.caching.maxLines`|Specifies the threshold for caching larger documents
468469
|`gitlens.advanced.maxQuickHistory`|Specifies the maximum number of QuickPick history entries to show

package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,55 @@
974974
"description": "Specifies which commands will be added to which menus",
975975
"scope": "window"
976976
},
977+
"gitlens.advanced.messages": {
978+
"type": "object",
979+
"default": {
980+
"suppressCommitHasNoPreviousCommitWarning": false,
981+
"suppressCommitNotFoundWarning": false,
982+
"suppressFileNotUnderSourceControlWarning": false,
983+
"suppressGitVersionWarning": false,
984+
"suppressLineUncommittedWarning": false,
985+
"suppressNoRepositoryWarning": false,
986+
"suppressUpdateNotice": false,
987+
"suppressWelcomeNotice": false
988+
},
989+
"properties": {
990+
"suppressCommitHasNoPreviousCommitWarning": {
991+
"type": "boolean",
992+
"default": false
993+
},
994+
"suppressCommitNotFoundWarning": {
995+
"type": "boolean",
996+
"default": false
997+
},
998+
"suppressFileNotUnderSourceControlWarning": {
999+
"type": "boolean",
1000+
"default": false
1001+
},
1002+
"suppressGitVersionWarning": {
1003+
"type": "boolean",
1004+
"default": false
1005+
},
1006+
"suppressLineUncommittedWarning": {
1007+
"type": "boolean",
1008+
"default": false
1009+
},
1010+
"suppressNoRepositoryWarning": {
1011+
"type": "boolean",
1012+
"default": false
1013+
},
1014+
"suppressUpdateNotice": {
1015+
"type": "boolean",
1016+
"default": false
1017+
},
1018+
"suppressWelcomeNotice": {
1019+
"type": "boolean",
1020+
"default": false
1021+
}
1022+
},
1023+
"description": "Specifies which messages should be suppressed",
1024+
"scope": "window"
1025+
},
9771026
"gitlens.advanced.quickPick.closeOnFocusOut": {
9781027
"type": "boolean",
9791028
"default": true,

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function configureCommands(
8787
context.subscriptions.push(new Commands.ToggleFileBlameCommand(annotationController));
8888
context.subscriptions.push(new Commands.ToggleFileRecentChangesCommand(annotationController));
8989
context.subscriptions.push(new Commands.ToggleLineBlameCommand(currentLineController));
90-
context.subscriptions.push(new Commands.ResetSuppressedWarningsCommand(context));
90+
context.subscriptions.push(new Commands.ResetSuppressedWarningsCommand());
9191
context.subscriptions.push(new Commands.ShowLastQuickPickCommand());
9292
context.subscriptions.push(new Commands.ShowQuickBranchHistoryCommand(git));
9393
context.subscriptions.push(new Commands.ShowQuickCurrentBranchHistoryCommand(git));
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
'use strict';
2-
import { Objects } from '../system';
3-
import { ExtensionContext } from 'vscode';
2+
import { ConfigurationTarget } from 'vscode';
43
import { Command, Commands } from './common';
5-
import { SuppressedKeys } from '../messages';
4+
import { configuration } from '../configuration';
65

76
export class ResetSuppressedWarningsCommand extends Command {
87

9-
constructor(
10-
private readonly context: ExtensionContext
11-
) {
8+
constructor() {
129
super(Commands.ResetSuppressedWarnings);
1310
}
1411

1512
async execute() {
16-
for (const key of Objects.values(SuppressedKeys)) {
17-
await this.context.globalState.update(key, undefined);
18-
}
13+
await configuration.update(configuration.name('advanced')('messages').value, undefined, ConfigurationTarget.Global);
1914
}
2015
}

src/configuration.ts

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import { ConfigurationChangeEvent, Event, EventEmitter, ExtensionContext, Uri, workspace } from 'vscode';
2+
import { ConfigurationChangeEvent, ConfigurationTarget, Event, EventEmitter, ExtensionContext, Uri, workspace } from 'vscode';
33
import { FileAnnotationType } from './annotations/annotationController';
44
import { ExtensionKey } from './constants';
55
import { LineAnnotationType } from './currentLineController';
@@ -90,6 +90,16 @@ export interface IAdvancedConfig {
9090
remote: boolean;
9191
};
9292
};
93+
messages: {
94+
suppressCommitHasNoPreviousCommitWarning: boolean,
95+
suppressCommitNotFoundWarning: boolean,
96+
suppressFileNotUnderSourceControlWarning: boolean,
97+
suppressGitVersionWarning: boolean,
98+
suppressLineUncommittedWarning: boolean,
99+
suppressNoRepositoryWarning: boolean,
100+
suppressUpdateNotice: boolean,
101+
suppressWelcomeNotice: boolean
102+
};
93103
quickPick: {
94104
closeOnFocusOut: boolean;
95105
};
@@ -363,45 +373,45 @@ const emptyConfig: IConfig = {
363373
file: {
364374
gutter: {
365375
format: '',
366-
dateFormat: null,
367-
compact: false,
368-
heatmap: {
376+
dateFormat: null,
377+
compact: false,
378+
heatmap: {
369379
enabled: false,
370-
location: 'left'
371-
},
372-
hover: {
380+
location: 'left'
381+
},
382+
hover: {
373383
details: false,
374-
changes: false,
375-
wholeLine: false
376-
}
384+
changes: false,
385+
wholeLine: false
386+
}
377387
},
378-
hover: {
388+
hover: {
379389
details: false,
380-
changes: false,
381-
heatmap: {
390+
changes: false,
391+
heatmap: {
382392
enabled: false
383-
}
393+
}
384394
},
385-
recentChanges: {
395+
recentChanges: {
386396
hover: {
387397
details: false,
388-
changes: false
389-
}
398+
changes: false
399+
}
390400
}
391401
},
392-
line: {
402+
line: {
393403
hover: {
394404
details: false,
395-
changes: false
396-
},
397-
trailing: {
405+
changes: false
406+
},
407+
trailing: {
398408
format: '',
399-
dateFormat: null,
400-
hover: {
409+
dateFormat: null,
410+
hover: {
401411
details: false,
402-
changes: false,
403-
wholeLine: false
404-
}
412+
changes: false,
413+
wholeLine: false
414+
}
405415
}
406416
}
407417
},
@@ -472,9 +482,9 @@ const emptyConfig: IConfig = {
472482
codeLens: {
473483
unsavedChanges: {
474484
recentChangeAndAuthors: '',
475-
recentChangeOnly: '',
476-
authorsOnly: ''
477-
}
485+
recentChangeOnly: '',
486+
authorsOnly: ''
487+
}
478488
}
479489
},
480490
theme: themeDefaults,
@@ -484,16 +494,16 @@ const emptyConfig: IConfig = {
484494
advanced: {
485495
caching: {
486496
enabled: false,
487-
maxLines: 0
488-
},
497+
maxLines: 0
498+
},
489499
git: '',
490500
maxQuickHistory: 0,
491501
menus: {
492502
explorerContext: {
493503
fileDiff: false,
494-
history: false,
495-
remote: false
496-
},
504+
history: false,
505+
remote: false
506+
},
497507
editorContext: {
498508
blame: false,
499509
copy: false,
@@ -516,6 +526,16 @@ const emptyConfig: IConfig = {
516526
remote: false
517527
}
518528
},
529+
messages: {
530+
suppressCommitHasNoPreviousCommitWarning: false,
531+
suppressCommitNotFoundWarning: false,
532+
suppressFileNotUnderSourceControlWarning: false,
533+
suppressGitVersionWarning: false,
534+
suppressLineUncommittedWarning: false,
535+
suppressNoRepositoryWarning: false,
536+
suppressUpdateNotice: false,
537+
suppressWelcomeNotice: false
538+
},
519539
quickPick: {
520540
closeOnFocusOut: false
521541
},
@@ -563,6 +583,10 @@ export class Configuration {
563583
name<K extends keyof IConfig>(name: K) {
564584
return Functions.propOf(emptyConfig, name);
565585
}
586+
587+
update(section: string, value: any, target: ConfigurationTarget) {
588+
return workspace.getConfiguration(ExtensionKey).update(section, value, target);
589+
}
566590
}
567591

568592
export const configuration = new Configuration();

src/extension.ts

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
2-
import { ExtensionContext, extensions, languages, window, workspace } from 'vscode';
2+
import { Objects } from './system';
3+
import { ConfigurationTarget, ExtensionContext, extensions, languages, window, workspace } from 'vscode';
34
import { AnnotationController } from './annotations/annotationController';
4-
import { Configuration, IConfig } from './configuration';
5+
import { configuration, Configuration, IConfig } from './configuration';
56
import { ApplicationInsightsKey, CommandContext, ExtensionKey, GlobalState, QualifiedExtensionId, setCommandContext } from './constants';
67
import { CodeLensController } from './codeLensController';
78
import { configureCommands } from './commands';
@@ -12,14 +13,13 @@ import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
1213
import { GitContextTracker, GitService } from './gitService';
1314
import { Keyboard } from './keyboard';
1415
import { Logger } from './logger';
15-
import { Messages, SuppressedKeys } from './messages';
16+
import { Messages, SuppressedMessages } from './messages';
1617
import { Telemetry } from './telemetry';
1718

1819
// this method is called when your extension is activated
1920
export async function activate(context: ExtensionContext) {
2021
Configuration.configure(context);
2122
Logger.configure(context);
22-
Messages.configure(context);
2323
Telemetry.configure(ApplicationInsightsKey);
2424

2525
const gitlens = extensions.getExtension(QualifiedExtensionId)!;
@@ -49,8 +49,11 @@ export async function activate(context: ExtensionContext) {
4949
telemetryContext['git.version'] = gitVersion;
5050
Telemetry.setContext(telemetryContext);
5151

52+
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
53+
54+
await migrateSettings(context, previousVersion);
5255
notifyOnUnsupportedGitVersion(context, gitVersion);
53-
notifyOnNewGitLensVersion(context, gitlensVersion);
56+
notifyOnNewGitLensVersion(context, gitlensVersion, previousVersion);
5457

5558
await context.globalState.update(GlobalState.GitLensVersion, gitlensVersion);
5659

@@ -87,14 +90,50 @@ export async function activate(context: ExtensionContext) {
8790
// this method is called when your extension is deactivated
8891
export function deactivate() { }
8992

90-
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
91-
if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return;
93+
const migration = {
94+
major: 6,
95+
minor: 1,
96+
patch: 2
97+
};
9298

93-
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
99+
async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) {
100+
if (previousVersion === undefined) return;
101+
102+
const [major, minor, patch] = previousVersion.split('.');
103+
if (parseInt(major, 10) >= migration.major && parseInt(minor, 10) >= migration.minor && parseInt(patch, 10) >= migration.patch) return;
104+
105+
try {
106+
const section = configuration.name('advanced')('messages').value;
107+
const messages: { [key: string]: boolean } = configuration.get(section);
108+
109+
let migrated = false;
110+
111+
for (const m of Objects.values(SuppressedMessages)) {
112+
const suppressed = context.globalState.get<boolean>(m);
113+
if (suppressed === undefined) continue;
114+
115+
migrated = true;
116+
messages[m] = suppressed;
117+
118+
context.globalState.update(m, undefined);
119+
}
120+
121+
if (!migrated) return;
122+
123+
await configuration.update(section, messages, ConfigurationTarget.Global);
124+
}
125+
catch (ex) {
126+
Logger.error(ex, 'migrateSettings');
127+
}
128+
}
129+
130+
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string, previousVersion: string | undefined) {
131+
if (configuration.get<boolean>(configuration.name('advanced')('messages')(SuppressedMessages.UpdateNotice).value)) return;
94132

95133
if (previousVersion === undefined) {
96134
Logger.log(`GitLens first-time install`);
97135
await Messages.showWelcomeMessage();
136+
98137
return;
99138
}
100139

0 commit comments

Comments
 (0)