Skip to content

Commit 1e9a6a1

Browse files
committed
Make SettingsProvider responsible for settings
This moves the Consumer-Visible interfaces for Settings into the SettingsProvider project. Additionally a base-implementation for a ConfigurationService is provided. It uses a clear reflection-based mechanism to load the defaults for a given settings type from a settings class. The type is provided as a Type-Argument to the constructor. This structure should allow easily extensible and customizable settings loading with caching and defaults.
1 parent fd9aa78 commit 1e9a6a1

File tree

50 files changed

+505
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+505
-562
lines changed

Rubberduck.CodeAnalysis/Inspections/Inspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Inspector(IConfigurationService<CodeInspectionSettings> configService, II
4040

4141
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
4242
{
43-
var config = _configService.Load();
43+
var config = _configService.Read();
4444
UpdateInspectionSeverity(config);
4545
}
4646

@@ -71,7 +71,7 @@ public async Task<IEnumerable<IInspectionResult>> FindIssuesAsync(RubberduckPars
7171
var allIssues = new ConcurrentBag<IInspectionResult>();
7272
token.ThrowIfCancellationRequested();
7373

74-
var config = _configService.Load();
74+
var config = _configService.Read();
7575
UpdateInspectionSeverity(config);
7676
token.ThrowIfCancellationRequested();
7777

Rubberduck.CodeAnalysis/Settings/CodeInspectionConfigProvider.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,41 @@ namespace Rubberduck.CodeAnalysis.Settings
1010
{
1111
public class CodeInspectionConfigProvider : ConfigurationServiceBase<CodeInspectionSettings>
1212
{
13-
private readonly CodeInspectionSettings defaultSettings;
1413
private readonly HashSet<string> foundInspectionNames;
1514

16-
public CodeInspectionConfigProvider(IPersistanceService<CodeInspectionSettings> persister, IInspectionProvider inspectionProvider)
17-
: base(persister)
15+
public CodeInspectionConfigProvider(IPersistenceService<CodeInspectionSettings> persister, IInspectionProvider inspectionProvider)
16+
: base(persister, new DefaultSettings<CodeInspectionSettings, Properties.CodeInspectionDefaults>())
1817
{
1918
foundInspectionNames = inspectionProvider.Inspections.Select(inspection => inspection.Name).ToHashSet();
20-
defaultSettings = new DefaultSettings<CodeInspectionSettings, Properties.CodeInspectionDefaults>().Default;
2119
// Ignore settings for unknown inspections, for example when using the Experimental attribute
22-
defaultSettings.CodeInspections = defaultSettings.CodeInspections.Where(setting => foundInspectionNames.Contains(setting.Name)).ToHashSet();
20+
Defaults.Default.CodeInspections = Defaults.Default.CodeInspections.Where(setting => foundInspectionNames.Contains(setting.Name)).ToHashSet();
2321

24-
var defaultNames = defaultSettings.CodeInspections.Select(x => x.Name);
22+
var defaultNames = Defaults.Default.CodeInspections.Select(x => x.Name);
2523
var nonDefaultInspections = inspectionProvider.Inspections.Where(inspection => !defaultNames.Contains(inspection.Name));
2624

27-
defaultSettings.CodeInspections.UnionWith(nonDefaultInspections.Select(inspection => new CodeInspectionSetting(inspection)));
25+
Defaults.Default.CodeInspections.UnionWith(nonDefaultInspections.Select(inspection => new CodeInspectionSetting(inspection)));
2826
}
2927

30-
public override CodeInspectionSettings Load()
28+
public override CodeInspectionSettings Read()
3129
{
32-
var loaded = persister.Load(defaultSettings);
33-
34-
if (loaded == null)
35-
{
36-
return defaultSettings;
37-
}
38-
30+
var loaded = LoadCacheValue();
3931
// Loaded settings don't contain defaults, so we need to combine user settings with defaults.
4032
var settings = new HashSet<CodeInspectionSetting>();
4133

4234
foreach (var loadedSetting in loaded.CodeInspections.Where(inspection => foundInspectionNames.Contains(inspection.Name)))
4335
{
44-
var matchingDefaultSetting = defaultSettings.CodeInspections.FirstOrDefault(inspection => inspection.Equals(loadedSetting));
36+
var matchingDefaultSetting = Defaults.Default.CodeInspections.FirstOrDefault(inspection => inspection.Equals(loadedSetting));
4537
if (matchingDefaultSetting != null)
4638
{
4739
loadedSetting.InspectionType = matchingDefaultSetting.InspectionType;
4840
}
4941

5042
settings.Add(loadedSetting);
5143
}
52-
53-
settings.UnionWith(defaultSettings.CodeInspections.Where(inspection => !settings.Contains(inspection)));
44+
settings.UnionWith(Defaults.Default.CodeInspections.Where(inspection => !settings.Contains(inspection)));
5445

5546
loaded.CodeInspections = settings;
56-
5747
return loaded;
5848
}
59-
60-
public override CodeInspectionSettings LoadDefaults()
61-
{
62-
return defaultSettings;
63-
}
6449
}
6550
}

Rubberduck.Core/App.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public App(IMessageBox messageBox,
5454

5555
private void _configService_SettingsChanged(object sender, ConfigurationChangedEventArgs e)
5656
{
57-
_config = _configService.Load();
57+
_config = _configService.Read();
5858
_hooks.HookHotkeys();
5959
UpdateLoggingLevel();
6060

@@ -160,7 +160,7 @@ public void Shutdown()
160160

161161
private void ApplyCultureConfig()
162162
{
163-
_config = _configService.Load();
163+
_config = _configService.Read();
164164

165165
var currentCulture = Resources.RubberduckUI.Culture;
166166
try

Rubberduck.Core/AutoComplete/AutoCompleteService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private void InitializeConfig()
4343
{
4444
if (!_initialized)
4545
{
46-
var config = _configService.Load();
46+
var config = _configService.Read();
4747
ApplyAutoCompleteSettings(config);
4848
}
4949
}
@@ -86,7 +86,7 @@ private void HandleIntelliSenseChanged(object sender, IntelliSenseEventArgs e)
8686

8787
private void ConfigServiceSettingsChanged(object sender, ConfigurationChangedEventArgs e)
8888
{
89-
var config = _configService.Load();
89+
var config = _configService.Read();
9090
ApplyAutoCompleteSettings(config);
9191
}
9292

Rubberduck.Core/Common/RubberduckHooks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void HookHotkeys()
4343
Detach();
4444
_hooks.Clear();
4545

46-
var config = _config.Load();
46+
var config = _config.Read();
4747
var settings = config.UserSettings.HotkeySettings;
4848

4949
foreach (var hotkeySetting in settings.Settings.Where(hotkeySetting => hotkeySetting.IsEnabled))

0 commit comments

Comments
 (0)