Skip to content

Commit ba95122

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into Issue2009
2 parents 787429d + 7b71190 commit ba95122

26 files changed

+458
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Which basically means it's a reimplementation of Git in C. It also [happens to b
8585

8686
This library makes localizing WPF applications at runtime using resx files a breeze. Thank you [Grant Frisken](http://www.codeproject.com/script/Membership/View.aspx?mid=1079060)!
8787

88-
> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx).
88+
> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx) with the [author's permission](http://www.codeproject.com/Messages/5272045/Re-License.aspx) to re-release under the GPLv3.
8989
9090
###[Using Raw Input from C# to handle multiple keyboards](http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard)
9191

RetailCoder.VBE/Common/Hotkeys/HotkeyInfo.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using System.Windows.Forms;
4+
using Rubberduck.UI;
45

56
namespace Rubberduck.Common.Hotkeys
67
{
@@ -25,20 +26,21 @@ public override string ToString()
2526
var builder = new StringBuilder();
2627
if (_keys.HasFlag(Keys.Alt))
2728
{
28-
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyAlt);
29+
builder.Append(RubberduckUI.GeneralSettings_HotkeyAlt);
2930
builder.Append('+');
3031
}
3132
if (_keys.HasFlag(Keys.Control))
3233
{
33-
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyCtrl);
34+
builder.Append(RubberduckUI.GeneralSettings_HotkeyCtrl);
3435
builder.Append('+');
3536
}
3637
if (_keys.HasFlag(Keys.Shift))
3738
{
38-
builder.Append(Rubberduck.UI.RubberduckUI.GeneralSettings_HotkeyShift);
39+
builder.Append(RubberduckUI.GeneralSettings_HotkeyShift);
3940
builder.Append('+');
4041
}
41-
builder.Append(_keys & ~Modifiers);
42+
43+
builder.Append(HotkeyDisplayConverter.Convert(_keys & ~Modifiers));
4244
return builder.ToString();
4345
}
4446
}

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Rubberduck.UI.Command;
1414
using Rubberduck.UI.Command.Refactorings;
1515
using NLog;
16+
using Rubberduck.UI;
1617

1718
namespace Rubberduck.Common
1819
{

RetailCoder.VBE/Common/WinAPI/RawInput.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,41 @@ protected override void WndProc(ref Message message)
3939
switch ((WM)message.Msg)
4040
{
4141
case WM.INPUT:
42+
{
43+
if (message.LParam == IntPtr.Zero)
44+
{
45+
break;
46+
}
47+
InputData rawBuffer;
48+
var dwSize = 0;
49+
var res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
50+
if (res != 0)
51+
{
52+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
53+
Logger.Error(ex, "Error sizing the rawinput buffer: {0}", ex.Message);
54+
break;
55+
}
56+
57+
res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, out rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
58+
if (res == -1)
59+
{
60+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
61+
Logger.Error(ex, "Error getting the rawinput buffer: {0}", ex.Message);
62+
break;
63+
}
64+
if (res == dwSize)
4265
{
43-
InputData _rawBuffer;
44-
var dwSize = 0;
45-
User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
46-
int res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, out _rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
47-
if (dwSize != res)
48-
{
49-
var ex = new Win32Exception(Marshal.GetLastWin32Error());
50-
Logger.Error(ex, "Error getting the rawinput buffer: {0}", ex.Message);
51-
return;
52-
}
5366
foreach (var device in _devices)
5467
{
55-
device.ProcessRawInput(_rawBuffer);
68+
device.ProcessRawInput(rawBuffer);
5669
}
5770
}
58-
break;
71+
else
72+
{
73+
//Something is seriously f'd up with Windows - the number of bytes copied does not match the reported buffer size.
74+
}
75+
}
76+
break;
5977
}
6078
base.WndProc(ref message);
6179
}

RetailCoder.VBE/Inspections/IParseTreeInspection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Rubberduck.Parsing;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using Rubberduck.Parsing.Grammar;
45

56
namespace Rubberduck.Inspections
67
{
@@ -17,11 +18,13 @@ public ParseTreeResults()
1718
ObsoleteLetContexts = Enumerable.Empty<QualifiedContext>();
1819
ArgListsWithOneByRefParam = Enumerable.Empty<QualifiedContext>();
1920
EmptyStringLiterals = Enumerable.Empty<QualifiedContext>();
21+
MalformedAnnotations = Enumerable.Empty<QualifiedContext<VBAParser.AnnotationContext>>();
2022
}
2123

2224
public IEnumerable<QualifiedContext> ObsoleteCallContexts;
2325
public IEnumerable<QualifiedContext> ObsoleteLetContexts;
2426
public IEnumerable<QualifiedContext> ArgListsWithOneByRefParam;
2527
public IEnumerable<QualifiedContext> EmptyStringLiterals;
28+
public IEnumerable<QualifiedContext<VBAParser.AnnotationContext>> MalformedAnnotations;
2629
}
2730
}

RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/Inspections/InspectionsUI.resx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -59,7 +59,7 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
6363
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
@@ -555,4 +555,13 @@
555555
<data name="VariableTypeNotDeclaredInspectionResultFormat" xml:space="preserve">
556556
<value>{0} '{1}' is implicitly 'Variant'</value>
557557
</data>
558-
</root>
558+
<data name="MalformedAnnotationInspectionMeta" xml:space="preserve">
559+
<value>An annotation comment is malformed.</value>
560+
</data>
561+
<data name="MalformedAnnotationInspectionName" xml:space="preserve">
562+
<value>Malformed annotation.</value>
563+
</data>
564+
<data name="MalformedAnnotationInspectionResultFormat" xml:space="preserve">
565+
<value>The annotation '{0}' is malformed</value>
566+
</data>
567+
</root>

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Rubberduck.UI;
1010
using Antlr4.Runtime.Tree;
1111
using Rubberduck.Parsing;
12+
using Rubberduck.Parsing.Grammar;
1213

1314
namespace Rubberduck.Inspections
1415
{
@@ -78,7 +79,7 @@ public async Task<IEnumerable<ICodeInspectionResult>> FindIssuesAsync(Rubberduck
7879
{
7980
allIssues.Add(inspectionResult);
8081
}
81-
})).ToList();
82+
}, token)).ToList();
8283

8384
await Task.WhenAll(inspections);
8485
state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status, UI.Settings.Settings.Culture)); // should be "Ready"
@@ -99,12 +100,14 @@ before moving them into the ParseTreeResults after qualifying them
99100
var obsoleteLetStatementListener = new ObsoleteLetStatementInspection.ObsoleteLetStatementListener();
100101
var emptyStringLiteralListener = new EmptyStringLiteralInspection.EmptyStringLiteralListener();
101102
var argListWithOneByRefParamListener = new ProcedureCanBeWrittenAsFunctionInspection.ArgListWithOneByRefParamListener();
103+
var malformedAnnotationListenter = new MalformedAnnotationInspection.MalformedAnnotationStatementListener();
102104

103105
var combinedListener = new CombinedParseTreeListener(new IParseTreeListener[]{
104106
obsoleteCallStatementListener,
105107
obsoleteLetStatementListener,
106108
emptyStringLiteralListener,
107109
argListWithOneByRefParamListener,
110+
malformedAnnotationListenter
108111
});
109112

110113
ParseTreeWalker.Default.Walk(combinedListener, componentTreePair.Value);
@@ -113,6 +116,7 @@ before moving them into the ParseTreeResults after qualifying them
113116
result.EmptyStringLiterals = result.EmptyStringLiterals.Concat(emptyStringLiteralListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
114117
result.ObsoleteLetContexts = result.ObsoleteLetContexts.Concat(obsoleteLetStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
115118
result.ObsoleteCallContexts = result.ObsoleteCallContexts.Concat(obsoleteCallStatementListener.Contexts.Select(context => new QualifiedContext(componentTreePair.Key, context)));
119+
result.MalformedAnnotations = result.MalformedAnnotations.Concat(malformedAnnotationListenter.Contexts.Select(context => new QualifiedContext<VBAParser.AnnotationContext>(componentTreePair.Key, context)));
116120
}
117121
return result;
118122
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Collections.Generic;
2+
using Rubberduck.Parsing;
3+
using Rubberduck.Parsing.Annotations;
4+
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.Parsing.Grammar;
6+
7+
namespace Rubberduck.Inspections
8+
{
9+
public sealed class MalformedAnnotationInspection : InspectionBase, IParseTreeInspection
10+
{
11+
public MalformedAnnotationInspection(RubberduckParserState state)
12+
: base(state, CodeInspectionSeverity.Error)
13+
{
14+
}
15+
16+
public override string Meta { get { return InspectionsUI.MalformedAnnotationInspectionMeta; } }
17+
public override string Description { get { return InspectionsUI.MalformedAnnotationInspectionResultFormat; } }
18+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
19+
public ParseTreeResults ParseTreeResults { get; set; }
20+
21+
public override IEnumerable<InspectionResultBase> GetInspectionResults()
22+
{
23+
if (ParseTreeResults == null)
24+
{
25+
return new InspectionResultBase[] { };
26+
}
27+
28+
var results = new List<MalformedAnnotationInspectionResult>();
29+
30+
foreach (var context in ParseTreeResults.MalformedAnnotations)
31+
{
32+
if (context.Context.annotationName().GetText() == AnnotationType.Ignore.ToString() ||
33+
context.Context.annotationName().GetText() == AnnotationType.Folder.ToString())
34+
{
35+
if (context.Context.annotationArgList() == null)
36+
{
37+
results.Add(new MalformedAnnotationInspectionResult(this,
38+
new QualifiedContext<VBAParser.AnnotationContext>(context.ModuleName,
39+
context.Context)));
40+
}
41+
}
42+
}
43+
44+
return results;
45+
}
46+
47+
public class MalformedAnnotationStatementListener : VBAParserBaseListener
48+
{
49+
private readonly IList<VBAParser.AnnotationContext> _contexts = new List<VBAParser.AnnotationContext>();
50+
public IEnumerable<VBAParser.AnnotationContext> Contexts { get { return _contexts; } }
51+
52+
public override void ExitAnnotation(VBAParser.AnnotationContext context)
53+
{
54+
if (context.annotationName() != null)
55+
{
56+
_contexts.Add(context);
57+
}
58+
}
59+
}
60+
}
61+
62+
public class MalformedAnnotationInspectionResult : InspectionResultBase
63+
{
64+
public MalformedAnnotationInspectionResult(IInspection inspection, QualifiedContext<VBAParser.AnnotationContext> qualifiedContext)
65+
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context)
66+
{
67+
}
68+
69+
public override string Description
70+
{
71+
get { return string.Format(Inspection.Description, ((VBAParser.AnnotationContext)Context).annotationName()); }
72+
}
73+
}
74+
}

RetailCoder.VBE/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.0.4.*")]
35-
[assembly: AssemblyFileVersion("2.0.4.0")]
34+
[assembly: AssemblyVersion("2.0.5.*")]
35+
[assembly: AssemblyFileVersion("2.0.5.0")]

0 commit comments

Comments
 (0)