Skip to content

Commit 325ef89

Browse files
cominternretailcoder
authored andcommitted
Indenter.BallOfMud = new MuchSmallerBallOfMud(); Changed Assembly load to host context. (#1624)
* Change assembly loading to run in the host context, fixes weird IO errors in XDocument. * Massive Indenter refactor, added Indenter unit tests. * Removed indentation from preview sample code, removed hungarian notation, and tweaked so settings changes are more visible. * Made ToDoListSettings ignore duplicates, number new placeholders in settings window. * Undo changes from PRs #1549 and #1601
1 parent f02f029 commit 325ef89

19 files changed

+2696
-881
lines changed

RetailCoder.VBE/Extension.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object
5555

5656
Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
5757
{
58-
string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
59-
string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
58+
var folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
59+
var assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
6060
if (!File.Exists(assemblyPath))
6161
{
6262
return null;
6363
}
64-
Assembly assembly = Assembly.LoadFrom(assemblyPath);
64+
65+
var assembly = Assembly.LoadFile(assemblyPath);
6566
return assembly;
6667
}
6768

RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private void GeneratePreview(IExtractMethodModel extractMethodModel,IExtractMeth
8585
*/
8686
var extractedMethod = extractMethodProc.createProc(extractMethodModel);
8787
var code = extractedMethod.Split(new[]{Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
88-
_indenter.Indent(code, "Preview", false);
88+
code = _indenter.Indent(code, "Preview", false).ToArray();
8989
_view.Preview = string.Join(Environment.NewLine, code);
9090
}
9191
}

RetailCoder.VBE/Settings/ToDoListSettings.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Xml.Serialization;
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Xml.Serialization;
24
using Rubberduck.UI;
35

46
namespace Rubberduck.Settings
@@ -11,8 +13,18 @@ interface IToDoListSettings
1113
[XmlType(AnonymousType = true)]
1214
public class ToDoListSettings : IToDoListSettings
1315
{
16+
private IEnumerable<ToDoMarker> _markers;
17+
1418
[XmlArrayItem("ToDoMarker", IsNullable = false)]
15-
public ToDoMarker[] ToDoMarkers { get; set; }
19+
public ToDoMarker[] ToDoMarkers
20+
{
21+
get { return _markers.ToArray(); }
22+
set
23+
{
24+
//Only take the first marker if there are duplicates.
25+
_markers = value.GroupBy(m => m.Text).Select(marker => marker.First()).ToArray();
26+
}
27+
}
1628

1729
public ToDoListSettings()
1830
{
@@ -23,9 +35,9 @@ public ToDoListSettings()
2335
ToDoMarkers = new[] { note, todo, bug };
2436
}
2537

26-
public ToDoListSettings(ToDoMarker[] markers)
38+
public ToDoListSettings(IEnumerable<ToDoMarker> markers)
2739
{
28-
ToDoMarkers = markers;
40+
_markers = markers;
2941
}
3042
}
3143
}

RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using Rubberduck.Settings;
34
using Rubberduck.SmartIndenter;
45

@@ -267,34 +268,34 @@ public int IndentSpaces
267268
@"' Example Procedure
268269
Sub ExampleProc()
269270
270-
' SMART INDENTER
271-
' Original VB6 code graciously offered to Rubberduck by Stephen Bullen & Rob Bovey
272-
'@ 2016 by Rubberduck VBA.
271+
' SMART INDENTER
272+
' Original VB6 code graciously offered to Rubberduck by Stephen Bullen & Rob Bovey
273+
' @ 2016 by Rubberduck VBA.
273274
274-
Dim iCount As Integer
275-
Static sName As String
275+
Dim count As Integer
276+
Static name As String
276277
277-
If YouLikeRubberduck Then
278-
' Star us on GitHub http://github.com/rubberduck-vba/Rubberduck
279-
' Follow us on Twitter @rubberduck-vba/contributors
280-
' Visit http://rubberduckvba.com for news and updates
278+
If YouLikeRubberduck Then
279+
' Star us on GitHub http://github.com/rubberduck-vba/Rubberduck
280+
' Follow us on Twitter @rubberduck-vba/contributors
281+
' Visit http://rubberduckvba.com for news and updates
281282
282-
Select Case X
283-
Case ""A""
284-
' If you have any comments or suggestions, _
285-
or find valid VBA code that isn't indented correctly,
283+
Select Case X
284+
Case ""A""
285+
' If you have any comments or suggestions, _
286+
or find valid VBA code that isn't indented correctly,
286287
287-
#If VBA6 Then
288-
MsgBox ""Contact contact@rubberduck-vba.com""
289-
#End If
288+
#If VBA6 Then
289+
MsgBox ""Contact contact@rubberduck-vba.com""
290+
#End If
290291
291-
Case ""Continued strings and parameters can be"" _
292-
& ""lined up for easier reading, optionally ignoring"" _
293-
, ""any operators (&+, etc) at the start of the line.""
292+
Case ""Continued strings and parameters can be"" _
293+
& ""lined up for easier reading, optionally ignoring"" _
294+
& ""any operators (&+, etc) at the start of the line.""
294295
295-
Debug.Print ""X<>1""
296-
End Select 'Case X
297-
End If 'More Tools?
296+
Debug.Print ""X<>1""
297+
End Select 'Case X
298+
End If 'More Tools?
298299
299300
End Sub
300301
";
@@ -305,8 +306,8 @@ public string PreviewSampleCode
305306
{
306307
var indenter = new Indenter(null, GetCurrentSettings);
307308

308-
var lines = _previewSampleCode.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
309-
indenter.Indent(lines, "TestModule", false);
309+
var lines = _previewSampleCode.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
310+
lines = indenter.Indent(lines, "TestModule", false).ToArray();
310311
return string.Join(Environment.NewLine, lines);
311312
}
312313
}

RetailCoder.VBE/UI/Settings/TodoSettingsViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.ObjectModel;
2+
using System.Globalization;
23
using System.Linq;
34
using System.Windows.Input;
45
using Rubberduck.Settings;
@@ -41,7 +42,10 @@ public ICommand AddTodoCommand
4142
}
4243
return _addTodoCommand = new DelegateCommand(_ =>
4344
{
44-
TodoSettings.Add(new ToDoMarker("PLACEHOLDER "));
45+
var placeholder = TodoSettings.Count(m => m.Text.StartsWith("PLACEHOLDER")) + 1;
46+
TodoSettings.Add(
47+
new ToDoMarker(string.Format("PLACEHOLDER{0} ",
48+
placeholder == 1 ? string.Empty : placeholder.ToString(CultureInfo.InvariantCulture))));
4549
});
4650
}
4751
}

Rubberduck.Parsing/Symbols/ReferencedDeclarationsCollector.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ private enum REGKIND
7878
{VarEnum.VT_R8, "Double"},
7979
};
8080

81-
[DllImport("kernel32.dll")]
82-
public static extern bool IsBadReadPtr(IntPtr lp, uint ucb);
83-
8481
private string GetTypeName(TYPEDESC desc, ITypeInfo info)
8582
{
8683
var vt = (VarEnum)desc.vt;
@@ -89,11 +86,6 @@ private string GetTypeName(TYPEDESC desc, ITypeInfo info)
8986
switch (vt)
9087
{
9188
case VarEnum.VT_PTR:
92-
if (IsBadReadPtr(desc.lpValue, (uint) IntPtr.Size))
93-
{
94-
Debug.WriteLine("Bad read pointer; returning fallback 'Object' type name.");
95-
return "Object";
96-
}
9789
tdesc = (TYPEDESC)Marshal.PtrToStructure(desc.lpValue, typeof(TYPEDESC));
9890
return GetTypeName(tdesc, info);
9991
case VarEnum.VT_USERDEFINED:
@@ -191,7 +183,6 @@ public IEnumerable<Declaration> GetDeclarationsForReference(Reference reference)
191183
info.GetTypeAttr(out typeAttributesPointer);
192184

193185
var typeAttributes = (TYPEATTR)Marshal.PtrToStructure(typeAttributesPointer, typeof(TYPEATTR));
194-
info.ReleaseTypeAttr(typeAttributesPointer);
195186

196187
var attributes = new Attributes();
197188
if (typeAttributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FPREDECLID))
@@ -277,7 +268,6 @@ private Declaration CreateMemberDeclaration(out FUNCDESC memberDescriptor, TYPEK
277268
IntPtr memberDescriptorPointer;
278269
info.GetFuncDesc(memberIndex, out memberDescriptorPointer);
279270
memberDescriptor = (FUNCDESC)Marshal.PtrToStructure(memberDescriptorPointer, typeof(FUNCDESC));
280-
info.ReleaseFuncDesc(memberDescriptorPointer);
281271

282272
if (memberDescriptor.callconv != CALLCONV.CC_STDCALL)
283273
{
@@ -411,7 +401,6 @@ private Declaration CreateFieldDeclaration(ITypeInfo info, int fieldIndex, Decla
411401
info.GetVarDesc(fieldIndex, out ppVarDesc);
412402

413403
var varDesc = (VARDESC)Marshal.PtrToStructure(ppVarDesc, typeof(VARDESC));
414-
info.ReleaseVarDesc(ppVarDesc);
415404

416405
var names = new string[255];
417406
int namesArrayLength;

0 commit comments

Comments
 (0)