diff --git a/Rubberduck.Parsing/Annotations/AnnotationType.cs b/Rubberduck.Parsing/Annotations/AnnotationType.cs index 4ca22983b7..f7cecf4df7 100644 --- a/Rubberduck.Parsing/Annotations/AnnotationType.cs +++ b/Rubberduck.Parsing/Annotations/AnnotationType.cs @@ -72,7 +72,9 @@ public enum AnnotationType ModuleAttribute = 1 << 20 | Attribute | ModuleAnnotation, MemberAttribute = 1 << 21 | Attribute | MemberAnnotation | VariableAnnotation, [FlexibleAttributeValueAnnotation("VB_VarDescription", 1)] - VariableDescription = 1 << 13 | Attribute | VariableAnnotation + VariableDescription = 1 << 13 | Attribute | VariableAnnotation, + [FlexibleAttributeValueAnnotation("VB_ProcData.VB_Invoke_Func", 1)] + ExcelHotKey = 1 << 16 | Attribute | MemberAnnotation } [AttributeUsage(AttributeTargets.Field)] diff --git a/Rubberduck.Parsing/Annotations/ExcelHotKeyAnnotation.cs b/Rubberduck.Parsing/Annotations/ExcelHotKeyAnnotation.cs new file mode 100644 index 0000000000..eef87e3559 --- /dev/null +++ b/Rubberduck.Parsing/Annotations/ExcelHotKeyAnnotation.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Rubberduck.Parsing.Grammar; +using Rubberduck.VBEditor; + +namespace Rubberduck.Parsing.Annotations +{ + public sealed class ExcelHotKeyAnnotation : FlexibleAttributeValueAnnotationBase + { + public ExcelHotKeyAnnotation(AnnotationType annotationType, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable attributeValues) : + base(annotationType, qualifiedSelection, context, GetHotKeyAttributeValue(attributeValues)) + { } + + private static IEnumerable GetHotKeyAttributeValue(IEnumerable attributeValues) => + attributeValues.Take(1).Select(StripStringLiteralQuotes).Select(v => v[0] + @"\n14").ToList(); + + private static string StripStringLiteralQuotes(string value) => + value.StartsWith("\"") && value.EndsWith("\"") && value.Length > 2 + ? value.Substring(1, value.Length - 2) + : value; + } +} diff --git a/RubberduckTests/Annotations/AttributeAnnotationProviderTests.cs b/RubberduckTests/Annotations/AttributeAnnotationProviderTests.cs index a3819698aa..0d974ef2b6 100644 --- a/RubberduckTests/Annotations/AttributeAnnotationProviderTests.cs +++ b/RubberduckTests/Annotations/AttributeAnnotationProviderTests.cs @@ -56,6 +56,7 @@ public void ModuleAttributeAnnotationReturnsSpecializedAnnotationsWhereApplicabl AssertEqual(expectedValues, actualValues); } + [TestCase("VB_ProcData.VB_Invoke_Func", "A", AnnotationType.ExcelHotKey, @"A\n14")] [TestCase("VB_Description", "\"SomeDescription\"", AnnotationType.Description, "\"SomeDescription\"")] [TestCase("VB_VarDescription", "\"SomeDescription\"", AnnotationType.VariableDescription, "\"SomeDescription\"")] [TestCase("VB_UserMemId", "0", AnnotationType.DefaultMember)]