Skip to content

Commit 1370e4f

Browse files
authored
Merge pull request #164 from rubberduck-vba/next
Sync with main repo
2 parents e2cfa3d + 2373066 commit 1370e4f

File tree

7 files changed

+65
-20
lines changed

7 files changed

+65
-20
lines changed

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,26 @@ public void ConfigServiceSettingsChanged(object sender, EventArgs e)
3636

3737
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
3838
{
39-
var saveCommand = _vbe.CommandBars.FindControl(VbeSaveCommandId);
40-
var activeProject = _vbe.ActiveVBProject;
41-
var unsaved = _vbe
42-
.VBProjects
43-
.Where(project => !project.IsSaved && !string.IsNullOrEmpty(project.FileName));
39+
SaveAllUnsavedProjects();
40+
}
4441

45-
foreach (var project in unsaved)
42+
private void SaveAllUnsavedProjects()
4643
{
47-
_vbe.ActiveVBProject = project;
48-
saveCommand.Execute();
44+
var saveCommand = _vbe.CommandBars.FindControl(VbeSaveCommandId);
45+
var activeProject = _vbe.ActiveVBProject;
46+
var unsaved = _vbe
47+
.VBProjects
48+
.Where(project => !project.IsSaved && !string.IsNullOrEmpty(project.FileName));
49+
50+
foreach (var project in unsaved)
51+
{
52+
_vbe.ActiveVBProject = project;
53+
saveCommand.Execute();
54+
}
55+
56+
_vbe.ActiveVBProject = activeProject;
4957
}
5058

51-
_vbe.ActiveVBProject = activeProject;
52-
}
5359

5460
public void Dispose()
5561
{

RetailCoder.VBE/Extension.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ private void InitializeAddIn()
143143
return;
144144
}
145145

146-
var config = new XmlPersistanceService<GeneralSettings>
146+
var configLoader = new XmlPersistanceService<GeneralSettings>
147147
{
148148
FilePath =
149149
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
150150
"Rubberduck", "rubberduck.config")
151151
};
152-
153-
var settings = config.Load(null);
152+
var configProvider = new GeneralConfigProvider(configLoader);
153+
154+
var settings = configProvider.Create();
154155
if (settings != null)
155156
{
156157
try

RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public NonReturningFunctionInspectionResult(IInspection inspection,
1717
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context, target)
1818
{
1919
_quickFixes = isInterfaceImplementation
20-
? new CodeInspectionQuickFix[] { }
20+
? new CodeInspectionQuickFix[]
21+
{
22+
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName),
23+
}
2124
: new CodeInspectionQuickFix[]
2225
{
2326
new ConvertToProcedureQuickFix(Context, QualifiedSelection, target),

Rubberduck.SettingsProvider/XmlPersistanceService.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public T Load(T toDeserialize)
3737

3838
if (!File.Exists(FilePath))
3939
{
40-
return (T)Convert.ChangeType(null, type);
40+
return FailedLoadReturnValue();
4141
}
4242
var doc = GetConfigurationDoc(FilePath);
4343

4444
var node = doc.Descendants().FirstOrDefault(e => e.Name.LocalName.Equals(type.Name));
4545
if (node == null)
4646
{
47-
return (T)Convert.ChangeType(null, type);
47+
return FailedLoadReturnValue();
4848
}
4949

5050
using (var reader = node.CreateReader())
@@ -57,11 +57,17 @@ public T Load(T toDeserialize)
5757
}
5858
catch
5959
{
60-
return (T)Convert.ChangeType(null, type);
60+
return FailedLoadReturnValue();
6161
}
6262
}
6363
}
6464

65+
private static T FailedLoadReturnValue()
66+
{
67+
return (T)Convert.ChangeType(null, typeof(T));
68+
}
69+
70+
6571
public void Save(T toSerialize)
6672
{
6773
var doc = GetConfigurationDoc(FilePath);

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class AbsoluteCodeLine
1414
private static readonly Regex StringReplaceRegex = new Regex(StringPlaceholder);
1515
private static readonly Regex LineNumberRegex = new Regex(@"^(?<number>\d+)\s+(?<code>.*)", RegexOptions.ExplicitCapture);
1616
private static readonly Regex EndOfLineCommentRegex = new Regex(@"^(?!(Rem\s)|('))(?<code>.*)(\s(?<comment>'.*))$", RegexOptions.ExplicitCapture);
17-
private static readonly Regex ProcedureStartRegex = new Regex(@"^(Public\s|Private\s|Friend\s)?(Static\s)?(Sub|Function|Property\s(Let|Get|Set))");
17+
private static readonly Regex ProcedureStartRegex = new Regex(@"^(Public\s|Private\s|Friend\s)?(Static\s)?(Sub|Function|Property\s(Let|Get|Set))\s");
1818
private static readonly Regex ProcedureStartIgnoreRegex = new Regex(@"^[LR]?Set\s|^Let\s|^(Public|Private)\sDeclare\s(Function|Sub)");
1919
private static readonly Regex ProcedureEndRegex = new Regex(@"^End\s(Sub|Function|Property)");
2020
private static readonly Regex TypeEnumStartRegex = new Regex(@"^(Public\s|Private\s)?(Enum\s|Type\s)");

RubberduckTests/Inspections/NonReturningFunctionInspectionTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public void GivenParameterizedPropertyGetter_QuickFixKeepsParameter()
477477

478478
[TestMethod]
479479
[TestCategory("Inspections")]
480-
public void NonReturningFunction_ReturnsResult_InterfaceImplementation_NoQuickFix()
480+
public void NonReturningFunction_ReturnsResult_InterfaceImplementation_OnlyIgnoreOnceQuickFix()
481481
{
482482
//Input
483483
const string inputCode1 =
@@ -507,7 +507,8 @@ Function IClass1_Foo() As Boolean
507507
var inspection = new NonReturningFunctionInspection(parser.State);
508508
var inspectionResults = inspection.GetInspectionResults();
509509

510-
Assert.AreEqual(0, inspectionResults.First().QuickFixes.Count());
510+
Assert.IsTrue(inspectionResults.First().QuickFixes.Any()
511+
&& inspectionResults.First().QuickFixes.All(quickfix => quickfix.Description == InspectionsUI.IgnoreOnce));
511512
}
512513

513514
[TestMethod]

RubberduckTests/SmartIndenter/MiscAndCornerCaseTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,33 @@ public void OverIndentationLeftAligns()
435435
var actual = indenter.Indent(code, string.Empty);
436436
Assert.IsTrue(expected.SequenceEqual(actual));
437437
}
438+
439+
//http://chat.stackexchange.com/transcript/message/33575758#33575758
440+
[TestMethod]
441+
[TestCategory("Indenter")]
442+
public void SubFooTokenIsNotInterpretedAsProcedureStart()
443+
{
444+
var code = new[]
445+
{
446+
"Public Sub Test()",
447+
"If Subject = 0 Then",
448+
"Subject = 1",
449+
"End If",
450+
"End Sub"
451+
};
452+
453+
var expected = new[]
454+
{
455+
"Public Sub Test()",
456+
" If Subject = 0 Then",
457+
" Subject = 1",
458+
" End If",
459+
"End Sub"
460+
};
461+
462+
var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
463+
var actual = indenter.Indent(code, string.Empty);
464+
Assert.IsTrue(expected.SequenceEqual(actual));
465+
}
438466
}
439467
}

0 commit comments

Comments
 (0)