Skip to content

Commit 82a83f5

Browse files
committed
Merge pull request #145 from retailcoder/config
ConfigurationLoader automatically adds newly implemented Code Inspections to Config
2 parents ea34c53 + 1a4cdb2 commit 82a83f5

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

RetailCoder.VBE/Config/ConfigurationLoader.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void SaveConfiguration<T>(T toSerialize)
2727
}
2828

2929
/// <summary> Loads the configuration from Rubberduck.config xml file. </summary>
30-
/// <remarks> If an IOException occurs returns a default configuration.</remarks>
30+
/// <remarks> If an IOException occurs, returns a default configuration.</remarks>
3131
public Configuration LoadConfiguration()
3232
{
3333
try
@@ -49,7 +49,11 @@ public Configuration LoadConfiguration()
4949
config.UserSettings.CodeInspectionSettings = new CodeInspectionSettings(GetDefaultCodeInspections());
5050
}
5151

52-
//todo: check for implemented inspections that aren't in config file
52+
var implementedInspections = GetImplementedCodeInspections();
53+
var configInspections = config.UserSettings.CodeInspectionSettings.CodeInspections.ToList();
54+
55+
configInspections = MergeImplementedInspectionsNotInConfig(configInspections, implementedInspections);
56+
config.UserSettings.CodeInspectionSettings.CodeInspections = configInspections.ToArray();
5357

5458
return config;
5559
}
@@ -80,6 +84,29 @@ public Configuration LoadConfiguration()
8084
}
8185
}
8286

87+
private List<CodeInspection> MergeImplementedInspectionsNotInConfig(List<CodeInspection> configInspections, IList<IInspection> implementedInspections)
88+
{
89+
bool found;
90+
foreach (var implementedInspection in implementedInspections)
91+
{
92+
found = false;
93+
foreach (var configInspection in configInspections)
94+
{
95+
if (implementedInspection.Name == configInspection.Name)
96+
{
97+
found = true;
98+
break;
99+
}
100+
}
101+
102+
if (!found)
103+
{
104+
configInspections.Add(new CodeInspection(implementedInspection));
105+
}
106+
}
107+
return configInspections;
108+
}
109+
83110
public Configuration GetDefaultConfiguration()
84111
{
85112
var userSettings = new UserSettings(

RetailCoder.VBE/Config/IConfigurationService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Collections.Generic;
34

45
namespace Rubberduck.Config
56
{
@@ -9,8 +10,8 @@ public interface IConfigurationService
910
CodeInspection[] GetDefaultCodeInspections();
1011
Configuration GetDefaultConfiguration();
1112
ToDoMarker[] GetDefaultTodoMarkers();
12-
System.Collections.Generic.IList<Rubberduck.Inspections.IInspection> GetImplementedCodeInspections();
13-
System.Collections.Generic.List<Rubberduck.VBA.Parser.Grammar.ISyntax> GetImplementedSyntax();
13+
IList<Rubberduck.Inspections.IInspection> GetImplementedCodeInspections();
14+
List<Rubberduck.VBA.Parser.Grammar.ISyntax> GetImplementedSyntax();
1415
Configuration LoadConfiguration();
1516
void SaveConfiguration<T>(T toSerialize);
1617
}

0 commit comments

Comments
 (0)