Skip to content

Commit 8513b48

Browse files
committed
closes #4507 - introduces MaxLogicalLineLineCount setting
1 parent 0197465 commit 8513b48

File tree

9 files changed

+80
-50
lines changed

9 files changed

+80
-50
lines changed

Rubberduck.Core/AutoComplete/Service/SelfClosingPairHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Rubberduck.AutoComplete.Service
1010
{
1111
public class SelfClosingPairHandler : AutoCompleteHandlerBase
1212
{
13+
private const int MaximumLines = 25;
14+
1315
private readonly IReadOnlyList<SelfClosingPair> _selfClosingPairs;
1416
private readonly IDictionary<char, SelfClosingPair> _scpInputLookup;
1517
private readonly SelfClosingPairCompletionService _scpService;
@@ -41,9 +43,10 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
4143
}
4244

4345
var original = CodePaneHandler.GetCurrentLogicalLine(e.Module);
44-
if (original == null)
46+
if (original == null || original.Lines.Length == MaximumLines)
4547
{
46-
// selection spans more than a single logical line
48+
// selection spans more than a single logical line, or
49+
// logical line somehow spans more than the maximum number of physical lines in a logical line of code (25).
4750
return false;
4851
}
4952

Rubberduck.Core/AutoComplete/Service/SmartConcatenationHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
2525
}
2626

2727
var currentContent = CodePaneHandler.GetCurrentLogicalLine(e.Module);
28-
if (!currentContent?.IsInsideStringLiteral ?? true)
28+
if ((!currentContent?.IsInsideStringLiteral ?? true)
29+
|| currentContent.Lines.Length >= settings.SmartConcat.MaxLogicalLineLineCount)
2930
{
30-
// selection spans more than a single logical line
31+
// selection spans more than a single logical line, or spans too many lines to be legal;
32+
// too many line continuations throws COMException if we attempt to modify.
3133
return false;
3234
}
3335

Rubberduck.Core/Properties/Settings.settings

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -268,26 +268,13 @@
268268
</Setting>
269269
<Setting Name="AutoCompleteSettings" Type="Rubberduck.Settings.AutoCompleteSettings" Scope="Application">
270270
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
271-
&lt;AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IsEnabled="false" CompleteBlockOnTab="true" CompleteBlockOnEnter="true" EnableSmartConcat="true"&gt;
272-
&lt;AutoCompletes&gt;
273-
&lt;AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" /&gt;
274-
&lt;AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" /&gt;
275-
&lt;AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" /&gt;
276-
&lt;AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" /&gt;
277-
&lt;AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" /&gt;
278-
&lt;AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" /&gt;
279-
&lt;AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" /&gt;
280-
&lt;AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" /&gt;
281-
&lt;AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" /&gt;
282-
&lt;AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" /&gt;
283-
&lt;AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" /&gt;
284-
&lt;AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" /&gt;
285-
&lt;AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" /&gt;
286-
&lt;AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" /&gt;
287-
&lt;AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" /&gt;
288-
&lt;AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" /&gt;
289-
&lt;AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" /&gt;
290-
&lt;/AutoCompletes&gt;
271+
&lt;AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" IsEnabled="false"&gt;
272+
&lt;SmartConcat&gt;
273+
&lt;IsEnabled&gt;false&lt;/IsEnabled&gt;
274+
&lt;ConcatVbNewLineModifier&gt;None&lt;/ConcatVbNewLineModifier&gt;
275+
&lt;/SmartConcat&gt;
276+
&lt;SelfClosingPairs IsEnabled="false" /&gt;
277+
&lt;BlockCompletion IsEnabled="false" CompleteOnEnter="false" CompleteOnTab="false" /&gt;
291278
&lt;/AutoCompleteSettings&gt;</Value>
292279
</Setting>
293280
</Settings>

Rubberduck.Core/Settings/AutoCompleteSettings.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,36 @@ public AutoCompleteSettings()
5757

5858
public class SmartConcatSettings : IEquatable<SmartConcatSettings>
5959
{
60+
private int _maxLogicalLineLineCount;
61+
private const int MaximumLines = 25; // more than that wouldn't compile
62+
63+
[XmlAttribute]
6064
public bool IsEnabled { get; set; }
6165
public ModifierKeySetting ConcatVbNewLineModifier { get; set; }
6266

67+
public int MaxLogicalLineLineCount
68+
{
69+
get => _maxLogicalLineLineCount;
70+
set
71+
{
72+
if (value > MaximumLines)
73+
{
74+
value = MaximumLines;
75+
}
76+
77+
if (value < 5)
78+
{
79+
value = 5; // completely arbitrary magical value.
80+
}
81+
_maxLogicalLineLineCount = value;
82+
}
83+
}
84+
6385
public bool Equals(SmartConcatSettings other)
6486
=> other != null &&
6587
other.IsEnabled == IsEnabled &&
66-
other.ConcatVbNewLineModifier == ConcatVbNewLineModifier;
88+
other.ConcatVbNewLineModifier == ConcatVbNewLineModifier &&
89+
other.MaxLogicalLineLineCount == MaxLogicalLineLineCount;
6790
}
6891

6992
public class SelfClosingPairSettings : IEquatable<SelfClosingPairSettings>

Rubberduck.Core/UI/Settings/AutoCompleteSettings.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
IsChecked="{Binding ConcatVbNewLine}"
112112
Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletesPage, Key=ConcatVbNewLine}" />
113113

114+
<Label Margin="15,0,15,0" Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletesPage, Key=ConcatMaxLines}" />
115+
<controls:NumberPicker Margin="15,0,15,0" NumValue="{Binding ConcatMaxLines}" />
116+
114117
<Label Margin="10"
115118
Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletesPage, Key=BlockCompletion}"
116119
FontWeight="Bold" />

Rubberduck.Core/UI/Settings/AutoCompleteSettingsViewModel.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void UpdateConfig(Configuration config)
2929
config.UserSettings.AutoCompleteSettings.SmartConcat.IsEnabled = EnableSmartConcat;
3030
config.UserSettings.AutoCompleteSettings.SmartConcat.ConcatVbNewLineModifier =
3131
ConcatVbNewLine ? ModifierKeySetting.CtrlKey : ModifierKeySetting.None;
32-
32+
config.UserSettings.AutoCompleteSettings.SmartConcat.MaxLogicalLineLineCount = ConcatMaxLines;
3333
config.UserSettings.AutoCompleteSettings.BlockCompletion.IsEnabled = EnableBlockCompletion;
3434
config.UserSettings.AutoCompleteSettings.BlockCompletion.CompleteOnTab = CompleteBlockOnTab;
3535
config.UserSettings.AutoCompleteSettings.BlockCompletion.CompleteOnEnter = CompleteBlockOnEnter;
@@ -43,6 +43,7 @@ private void TransferSettingsToView(Rubberduck.Settings.AutoCompleteSettings toL
4343

4444
EnableSmartConcat = toLoad.SmartConcat.IsEnabled;
4545
ConcatVbNewLine = toLoad.SmartConcat.ConcatVbNewLineModifier == ModifierKeySetting.CtrlKey;
46+
ConcatMaxLines = toLoad.SmartConcat.MaxLogicalLineLineCount;
4647

4748
EnableBlockCompletion = toLoad.BlockCompletion.IsEnabled;
4849
CompleteBlockOnTab = toLoad.BlockCompletion.CompleteOnTab;
@@ -108,6 +109,20 @@ public bool ConcatVbNewLine
108109
}
109110
}
110111

112+
private int _concatMaxLines;
113+
public int ConcatMaxLines
114+
{
115+
get { return _concatMaxLines; }
116+
set
117+
{
118+
if (_concatMaxLines != value)
119+
{
120+
_concatMaxLines = value;
121+
OnPropertyChanged();
122+
}
123+
}
124+
}
125+
111126
private bool _enableBlockCompletion;
112127

113128
public bool EnableBlockCompletion

Rubberduck.Core/app.config

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -395,27 +395,13 @@
395395
<setting name="AutoCompleteSettings" serializeAs="Xml">
396396
<value>
397397
<AutoCompleteSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
398-
xmlns:xsd="http://www.w3.org/2001/XMLSchema" IsEnabled="false"
399-
CompleteBlockOnTab="true" CompleteBlockOnEnter="true" EnableSmartConcat="true">
400-
<AutoCompletes>
401-
<AutoComplete Key="AutoCompleteClosingBrace" IsEnabled="true" />
402-
<AutoComplete Key="AutoCompleteClosingBracket" IsEnabled="true" />
403-
<AutoComplete Key="AutoCompleteClosingParenthese" IsEnabled="true" />
404-
<AutoComplete Key="AutoCompleteClosingString" IsEnabled="true" />
405-
<AutoComplete Key="AutoCompleteDoBlock" IsEnabled="true" />
406-
<AutoComplete Key="AutoCompleteEnumBlock" IsEnabled="true" />
407-
<AutoComplete Key="AutoCompleteForBlock" IsEnabled="true" />
408-
<AutoComplete Key="AutoCompleteFunctionBlock" IsEnabled="true" />
409-
<AutoComplete Key="AutoCompleteIfBlock" IsEnabled="true" />
410-
<AutoComplete Key="AutoCompleteOnErrorResumeNextBlock" IsEnabled="true" />
411-
<AutoComplete Key="AutoCompletePrecompilerIfBlock" IsEnabled="true" />
412-
<AutoComplete Key="AutoCompletePropertyBlock" IsEnabled="true" />
413-
<AutoComplete Key="AutoCompleteSelectBlock" IsEnabled="true" />
414-
<AutoComplete Key="AutoCompleteSubBlock" IsEnabled="true" />
415-
<AutoComplete Key="AutoCompleteTypeBlock" IsEnabled="true" />
416-
<AutoComplete Key="AutoCompleteWhileBlock" IsEnabled="true" />
417-
<AutoComplete Key="AutoCompleteWithBlock" IsEnabled="true" />
418-
</AutoCompletes>
398+
xmlns:xsd="http://www.w3.org/2001/XMLSchema" IsEnabled="false">
399+
<SmartConcat IsEnabled="false">
400+
<ConcatVbNewLineModifier>None</ConcatVbNewLineModifier>
401+
<MaxLogicalLineLineCount>25</MaxLogicalLineLineCount>
402+
</SmartConcat>
403+
<SelfClosingPairs IsEnabled="false" />
404+
<BlockCompletion IsEnabled="false" CompleteOnEnter="false" CompleteOnTab="false" />
419405
</AutoCompleteSettings>
420406
</value>
421407
</setting>

Rubberduck.VBEEditor/SourceCodeHandling/CodePaneSourceCodeHandler.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Rubberduck.VBEditor.ComManagement;
55
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
66
using System.Reflection;
7+
using System.Diagnostics;
78

89
namespace Rubberduck.VBEditor.SourceCodeHandling
910
{
@@ -54,8 +55,15 @@ public void SetSelection(ICodeModule module, Selection selection)
5455

5556
public void SubstituteCode(ICodeModule module, CodeString newCode)
5657
{
57-
module.DeleteLines(newCode.SnippetPosition);
58-
module.InsertLines(newCode.SnippetPosition.StartLine, newCode.Code);
58+
try
59+
{
60+
module.DeleteLines(newCode.SnippetPosition);
61+
module.InsertLines(newCode.SnippetPosition.StartLine, newCode.Code);
62+
}
63+
catch
64+
{
65+
Debug.Assert(false, "too many line continuations. we shouldn't even be here.");
66+
}
5967
}
6068

6169
public void SubstituteCode(QualifiedModuleName module, CodeString newCode)
@@ -197,7 +205,7 @@ public CodeString GetCurrentLogicalLine(ICodeModule module)
197205
var pEndLine = lines[lines.Count - 1].pLine;
198206
var snippetPosition = new Selection(pStartLine, 1, pEndLine, 1);
199207

200-
if (lines[0].pLine < pSelection.StartLine || lines.Last().pLine > pSelection.EndLine)
208+
if (pStartLine > pSelection.StartLine || pEndLine > pSelection.EndLine)
201209
{
202210
// selection spans more than a single logical line
203211
return null;

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/CodeModule.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public void InsertLines(int line, string content)
130130
{
131131
// "too many line continuations" is one possible cause for a COMException here.
132132
_logger.Error(e);
133+
throw;
133134
}
134135
}
135136

@@ -148,6 +149,7 @@ public void DeleteLines(int startLine, int count = 1)
148149
{
149150
// "too many line continuations" is one possible cause for a COMException here.
150151
_logger.Error(e);
152+
throw;
151153
}
152154
}
153155
}
@@ -175,6 +177,7 @@ public void ReplaceLine(int line, string content)
175177
{
176178
// "too many line continuations" is one possible cause for a COMException here.
177179
_logger.Error(e);
180+
throw;
178181
}
179182
}
180183

0 commit comments

Comments
 (0)