diff --git a/README.md b/README.md index d7319d3a2a..f0a87036d2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -![Rubberduck](http://i.stack.imgur.com/vmqXM.png) + -| Branch | Build Status | -|------------|--------------| -| **master** | ![master branch build status][masterBuildStatus] | -| **next** | ![next branch build status][nextBuildStatus] | +Branch | Description | Build Status | +|------------|---|--------------| +| **master** | The last released build | ![master branch build status][masterBuildStatus] | +| **next** | The current build (dev) | ![next branch build status][nextBuildStatus] | [nextBuildStatus]:https://ci.appveyor.com/api/projects/status/we3pdnkeebo4nlck/branch/next?svg=true [masterBuildStatus]:https://ci.appveyor.com/api/projects/status/we3pdnkeebo4nlck/branch/master?svg=true diff --git a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs index d4c7b03c2a..ff98d1dd76 100644 --- a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs +++ b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspection.cs @@ -43,10 +43,9 @@ public UntypedFunctionUsageInspection(RubberduckParserState state) public override IEnumerable GetInspectionResults() { var declarations = BuiltInDeclarations - // note: these *should* be functions, but somehow they're not defined as such .Where(item => _tokens.Any(token => item.IdentifierName == token || item.IdentifierName == "_B_var_" + token) && - item.References.Any(reference => _tokens.Contains(reference.IdentifierName))); + item.Scope.StartsWith("VBE7.DLL;")); return declarations.SelectMany(declaration => declaration.References .Where(item => _tokens.Contains(item.IdentifierName)) diff --git a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs index 102c094ba5..20e25002e3 100644 --- a/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs +++ b/RetailCoder.VBE/Inspections/UntypedFunctionUsageInspectionResult.cs @@ -67,7 +67,8 @@ public override void Fix() var module = Selection.QualifiedName.Component.CodeModule; var lines = module.Lines[selection.StartLine, selection.LineCount]; - var result = lines.Replace(originalInstruction, newInstruction); + var result = lines.Remove(Context.Start.Column, originalInstruction.Length) + .Insert(Context.Start.Column, newInstruction); module.ReplaceLine(selection.StartLine, result); } diff --git a/Rubberduck.Parsing/Rubberduck.Parsing.csproj b/Rubberduck.Parsing/Rubberduck.Parsing.csproj index 6d36ceabd0..3f81f5dfd8 100644 --- a/Rubberduck.Parsing/Rubberduck.Parsing.csproj +++ b/Rubberduck.Parsing/Rubberduck.Parsing.csproj @@ -134,6 +134,7 @@ + diff --git a/Rubberduck.Parsing/Symbols/AliasDeclarations.cs b/Rubberduck.Parsing/Symbols/AliasDeclarations.cs new file mode 100644 index 0000000000..005a425a60 --- /dev/null +++ b/Rubberduck.Parsing/Symbols/AliasDeclarations.cs @@ -0,0 +1,444 @@ +using System.Collections.Generic; +using Rubberduck.Parsing.VBA; +using Rubberduck.VBEditor; +using System.Linq; +using Rubberduck.Parsing.Annotations; + +namespace Rubberduck.Parsing.Symbols +{ + public class AliasDeclarations : ICustomDeclarationLoader + { + private readonly RubberduckParserState _state; + + public AliasDeclarations(RubberduckParserState state) + { + _state = state; + } + + public IReadOnlyList Load() + { + return AddAliasDeclarations(); + } + + private static readonly string[] Tokens = { + Grammar.Tokens.Error, + Grammar.Tokens.Hex, + Grammar.Tokens.Oct, + Grammar.Tokens.Str, + Grammar.Tokens.CurDir, + Grammar.Tokens.Command, + Grammar.Tokens.Environ, + Grammar.Tokens.Chr, + Grammar.Tokens.ChrW, + Grammar.Tokens.Format, + Grammar.Tokens.LCase, + Grammar.Tokens.Left, + Grammar.Tokens.LeftB, + Grammar.Tokens.LTrim, + Grammar.Tokens.Mid, + Grammar.Tokens.MidB, + Grammar.Tokens.Trim, + Grammar.Tokens.Right, + Grammar.Tokens.RightB, + Grammar.Tokens.RTrim, + Grammar.Tokens.UCase + }; + + private IReadOnlyList AddAliasDeclarations() + { + var conversionModule = _state.AllDeclarations.SingleOrDefault( + item => item.IdentifierName == "Conversion" && item.Scope == "VBE7.DLL;VBA.Conversion"); + + var fileSystemModule = _state.AllDeclarations.SingleOrDefault( + item => item.IdentifierName == "FileSystem" && item.Scope == "VBE7.DLL;VBA.FileSystem"); + + var interactionModule = _state.AllDeclarations.SingleOrDefault( + item => item.IdentifierName == "Interaction" && item.Scope == "VBE7.DLL;VBA.Interaction"); + + var stringsModule = _state.AllDeclarations.SingleOrDefault( + item => item.IdentifierName == "Interaction" && item.Scope == "VBE7.DLL;VBA.Interaction"); + + // all these modules are all part of the same project--only need to check one + if (conversionModule == null) + { + return new List(); + } + + var functions = _state.AllDeclarations.Where(s => s.DeclarationType == DeclarationType.Function && + s.Scope.StartsWith("VBE") && + Tokens.Any(token => s.IdentifierName == "_B_var_" + token)) + .ToList(); + + var errorFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Conversion"), "Error"), + conversionModule, + conversionModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var hexFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Conversion"), "Hex"), + conversionModule, + conversionModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var octFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Conversion"), "Oct"), + conversionModule, + conversionModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var strFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Conversion"), "Str"), + conversionModule, + conversionModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var curDirFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "FileSystem"), "CurDir"), + fileSystemModule, + fileSystemModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var commandFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Interaction"), "Command"), + interactionModule, + interactionModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var environFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Interaction"), "Environ"), + interactionModule, + interactionModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var chrFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "Chr"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var chrwFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "ChrW"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var formatFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "Format"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var lcaseFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "LCase"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var leftFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "Left"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var leftbFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "LeftB"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var ltrimFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "LTrim"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var midFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "Mid"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var midbFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "MidB"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var trimFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "Trim"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var rightFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "Right"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var rightbFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "RightB"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var rtrimFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "RTrim"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var ucaseFunction = new FunctionDeclaration( + new QualifiedMemberName( + new QualifiedModuleName("VBA", "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA7.1\\VBE7.DLL", "Strings"), "UCase"), + stringsModule, + stringsModule, + "Variant", + null, + string.Empty, + Accessibility.Global, + null, + new Selection(), + false, + true, + new List(), + new Attributes()); + + var functionAliases = new List { + errorFunction, + hexFunction, + octFunction, + strFunction, + curDirFunction, + commandFunction, + environFunction, + chrFunction, + chrwFunction, + formatFunction, + lcaseFunction, + leftFunction, + leftbFunction, + ltrimFunction, + midFunction, + midbFunction, + trimFunction, + rightFunction, + rightbFunction, + rtrimFunction, + ucaseFunction + }; + + // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop + foreach (FunctionDeclaration alias in functionAliases) + { + foreach (var parameter in ((FunctionDeclaration)functions.Single(s => s.IdentifierName == "_B_var_" + alias.IdentifierName)).Parameters) + { + alias.AddParameter(parameter); + } + } + + return functionAliases; + } + } +} \ No newline at end of file diff --git a/Rubberduck.Parsing/Symbols/FormEventDeclarations.cs b/Rubberduck.Parsing/Symbols/FormEventDeclarations.cs index 8087f860e2..e511f2d52a 100644 --- a/Rubberduck.Parsing/Symbols/FormEventDeclarations.cs +++ b/Rubberduck.Parsing/Symbols/FormEventDeclarations.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using NLog; using Rubberduck.Parsing.VBA; using Rubberduck.VBEditor; @@ -8,7 +7,6 @@ namespace Rubberduck.Parsing.Symbols public class FormEventDeclarations : ICustomDeclarationLoader { private readonly RubberduckParserState _state; - private readonly Logger _logger = LogManager.GetCurrentClassLogger(); public FormEventDeclarations(RubberduckParserState state) { @@ -103,7 +101,7 @@ private IReadOnlyList AddHiddenMSFormDeclarations(Declaration paren null, string.Empty, false, - false); + true); var userFormQueryCloseEventCloseModeParameter = new ParameterDeclaration( new QualifiedMemberName( @@ -115,7 +113,7 @@ private IReadOnlyList AddHiddenMSFormDeclarations(Declaration paren null, string.Empty, false, - false); + true); var userFormResizeEvent = new Declaration( new QualifiedMemberName( diff --git a/Rubberduck.Parsing/VBA/RubberduckParser.cs b/Rubberduck.Parsing/VBA/RubberduckParser.cs index 13b9602c09..1ae18ef52c 100644 --- a/Rubberduck.Parsing/VBA/RubberduckParser.cs +++ b/Rubberduck.Parsing/VBA/RubberduckParser.cs @@ -246,9 +246,6 @@ private void ParseAll() } } - SyncComReferences(State.Projects); - AddBuiltInDeclarations(); - if (toParse.Count == 0) { if (componentsRemoved) // trigger UI updates @@ -264,11 +261,9 @@ private void ParseAll() { State.SetModuleState(component, ParserState.Pending); } - foreach (var component in unchanged) - { - // note: seting to 'Parsed' would include them in the resolver walk. 'Ready' excludes them. - State.SetModuleState(component, ParserState.Ready); - } + + SyncComReferences(State.Projects); + AddBuiltInDeclarations(); // invalidation cleanup should go into ParseAsync? foreach (var key in _componentAttributes.Keys)