Skip to content

Commit 366eb68

Browse files
authored
Merge pull request #142 from rubberduck-vba/next
sync with main repo
2 parents 6f8ed99 + 1a0ddf4 commit 366eb68

28 files changed

+335
-292
lines changed

RetailCoder.VBE/API/ParserState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void Initialize(VBE vbe)
6868

6969
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(vbe.Version, CultureInfo.InvariantCulture));
7070
_attributeParser = new AttributeParser(new ModuleExporter(), preprocessorFactory);
71-
_parser = new RubberduckParser(vbe, _state, _attributeParser, preprocessorFactory,
71+
_parser = new RubberduckParser(_state, _attributeParser, preprocessorFactory,
7272
new List<ICustomDeclarationLoader> { new DebugDeclarations(_state), new FormEventDeclarations(_state) });
7373
}
7474

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ public void Detach()
173173

174174
private void hook_MessageReceived(object sender, HookEventArgs e)
175175
{
176-
var active = User32.GetForegroundWindow();
177-
if (active != _mainWindowHandle)
178-
{
179-
return;
180-
}
181-
182176
var hotkey = sender as IHotkey;
183177
if (hotkey != null)
184178
{
@@ -207,6 +201,16 @@ private IntPtr WindowProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam)
207201
case WM.SETFOCUS:
208202
Attach();
209203
break;
204+
case WM.RUBBERDUCK_CHILD_FOCUS:
205+
if (lParam == IntPtr.Zero)
206+
{
207+
Detach();
208+
}
209+
else
210+
{
211+
Attach();
212+
}
213+
return IntPtr.Zero;
210214
case WM.NCACTIVATE:
211215
if (wParam == IntPtr.Zero)
212216
{
@@ -235,14 +239,11 @@ private bool HandleHotkeyMessage(IntPtr wParam)
235239
var processed = false;
236240
try
237241
{
238-
if (User32.IsVbeWindowActive(_mainWindowHandle))
242+
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
243+
if (hook != null)
239244
{
240-
var hook = Hooks.OfType<Hotkey>().SingleOrDefault(k => k.HotkeyInfo.HookId == wParam);
241-
if (hook != null)
242-
{
243-
hook.OnMessageReceived();
244-
processed = true;
245-
}
245+
hook.OnMessageReceived();
246+
processed = true;
246247
}
247248
}
248249
catch (Exception exception)

RetailCoder.VBE/Common/WinAPI/User32.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ public static class User32
180180
[DllImport("user32.dll", SetLastError = true)]
181181
internal static extern bool UnregisterDeviceNotification(IntPtr handle);
182182

183+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
184+
internal static extern IntPtr SendMessage(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam);
185+
183186
/// <summary>
184187
/// A helper function that returns <c>true</c> when the specified handle is that of the foreground window.
185188
/// </summary>

RetailCoder.VBE/Common/WinAPI/WM.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,11 @@ public enum WM : uint
922922
/// </summary>
923923
SYSTIMER = 0x118,
924924

925+
/// <summary>
926+
/// Private message to signal focus set/lost for a DockableWindowHost. Set wParam to the DockableWindowHost hWnd, lParam to zero for lost focus, non-zero for gained focus.
927+
/// </summary>
928+
RUBBERDUCK_CHILD_FOCUS = USER + 0x0F00,
929+
925930
/// <summary>
926931
/// The accessibility state has changed.
927932
/// </summary>

RetailCoder.VBE/Inspections/IInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Rubberduck.Inspections
88
{
99
public interface IInspector
1010
{
11-
List<ICodeInspectionResult> FindIssuesAsync(RubberduckParserState state, CancellationToken token);
11+
Task<IEnumerable<ICodeInspectionResult>> FindIssuesAsync(RubberduckParserState state, CancellationToken token);
1212
}
1313

1414
public class InspectorIssuesFoundEventArg : EventArgs

RetailCoder.VBE/Inspections/InspectionResultBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public int CompareTo(object obj)
121121
public object[] ToArray()
122122
{
123123
var module = QualifiedSelection.QualifiedName;
124-
return new object[] { Inspection.Severity.ToString(), module.ProjectTitle, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
124+
return new object[] { Inspection.Severity.ToString(), module.ProjectName, module.ComponentName, Description, QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.StartColumn };
125125
}
126126

127127
public string ToCsvString()

RetailCoder.VBE/Inspections/Inspector.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ private void UpdateInspectionSeverity()
4848
}
4949
}
5050

51-
public List<ICodeInspectionResult> FindIssuesAsync(RubberduckParserState state, CancellationToken token)
51+
public async Task<IEnumerable<ICodeInspectionResult>> FindIssuesAsync(RubberduckParserState state, CancellationToken token)
5252
{
5353
if (state == null || !state.AllUserDeclarations.Any())
5454
{
55-
return new List<ICodeInspectionResult>();
55+
return new ICodeInspectionResult[] { };
5656
}
5757

5858
state.OnStatusMessageUpdate(RubberduckUI.CodeInspections_Inspecting);
@@ -78,11 +78,11 @@ public List<ICodeInspectionResult> FindIssuesAsync(RubberduckParserState state,
7878
{
7979
allIssues.Add(inspectionResult);
8080
}
81-
}, token)).ToArray();
81+
})).ToList();
8282

83-
Task.WaitAll(inspections);
83+
await Task.WhenAll(inspections);
8484
state.OnStatusMessageUpdate(RubberduckUI.ResourceManager.GetString("ParserState_" + state.Status, UI.Settings.Settings.Culture)); // should be "Ready"
85-
return allIssues.ToList();
85+
return allIssues;
8686
}
8787

8888
private ParseTreeResults GetParseTreeResults(RubberduckParserState state)

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using Antlr4.Runtime;
34
using Rubberduck.Parsing.Grammar;
45
using Rubberduck.Parsing.Symbols;
@@ -90,7 +91,25 @@ private string DeclareExplicitVariant(VBAParser.ArgContext context, out string i
9091
}
9192

9293
instruction = context.GetText();
93-
return instruction + ' ' + Tokens.As + ' ' + Tokens.Variant;
94+
if (!context.children.Select(s => s.GetType()).Contains(typeof(VBAParser.ArgDefaultValueContext)))
95+
{
96+
return instruction + ' ' + Tokens.As + ' ' + Tokens.Variant;
97+
}
98+
99+
var fix = string.Empty;
100+
var hasArgDefaultValue = false;
101+
foreach (var child in context.children)
102+
{
103+
if (child.GetType() == typeof(VBAParser.ArgDefaultValueContext))
104+
{
105+
fix += Tokens.As + ' ' + Tokens.Variant + ' ';
106+
hasArgDefaultValue = true;
107+
}
108+
109+
fix += child.GetText();
110+
}
111+
112+
return hasArgDefaultValue ? fix : fix + ' ' + Tokens.As + ' ' + Tokens.Variant;
94113
}
95114

96115
private string DeclareExplicitVariant(VBAParser.ConstSubStmtContext context, out string instruction)

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
5-
using System.Windows.Input;
65
using Microsoft.Vbe.Interop;
76
using NLog;
87
using Rubberduck.Navigation.Folders;
@@ -87,17 +86,6 @@ public CodeExplorerItemViewModel SelectedItem
8786
_selectedItem = value;
8887
OnPropertyChanged();
8988

90-
if (_selectedItem is CodeExplorerProjectViewModel)
91-
{
92-
var vbe = _selectedItem.GetSelectedDeclaration().Project.VBE;
93-
var project = vbe.VBProjects.Cast<VBProject>().FirstOrDefault(f => f.HelpFile == _selectedItem.GetSelectedDeclaration().Project.HelpFile);
94-
95-
if (project != null)
96-
{
97-
vbe.ActiveVBProject = project;
98-
}
99-
}
100-
10189
// ReSharper disable ExplicitCallerInfoArgument
10290
OnPropertyChanged("CanExecuteIndenterCommand");
10391
OnPropertyChanged("CanExecuteRenameCommand");
@@ -189,25 +177,27 @@ public string PanelTitle
189177
return string.Empty;
190178
}
191179

192-
if (SelectedItem is CodeExplorerProjectViewModel)
180+
if (!(SelectedItem is ICodeExplorerDeclarationViewModel))
193181
{
194-
var node = (CodeExplorerProjectViewModel)SelectedItem;
195-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
182+
return SelectedItem.Name;
196183
}
197184

198-
if (SelectedItem is CodeExplorerComponentViewModel)
199-
{
200-
var node = (CodeExplorerComponentViewModel)SelectedItem;
201-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
202-
}
185+
var declaration = SelectedItem.GetSelectedDeclaration();
186+
187+
var nameWithDeclarationType = declaration.IdentifierName +
188+
string.Format(" - ({0})", RubberduckUI.ResourceManager.GetString(
189+
"DeclarationType_" + declaration.DeclarationType, UI.Settings.Settings.Culture));
203190

204-
if (SelectedItem is CodeExplorerMemberViewModel)
191+
if (string.IsNullOrEmpty(declaration.AsTypeName))
205192
{
206-
var node = (CodeExplorerMemberViewModel)SelectedItem;
207-
return node.Declaration.IdentifierName + string.Format(" - ({0})", node.Declaration.DeclarationType);
193+
return nameWithDeclarationType;
208194
}
209195

210-
return SelectedItem.Name;
196+
var typeName = declaration.HasTypeHint
197+
? Declaration.TypeHintToTypeName[declaration.TypeHint]
198+
: declaration.AsTypeName;
199+
200+
return nameWithDeclarationType + ": " + typeName;
211201
}
212202
}
213203

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@
374374
CommandParameter="{Binding SelectedItem}" />
375375
<Separator />
376376
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_OpenProjectProperties}"
377-
Command="{Binding OpenProjectPropertiesCommand}" />
377+
Command="{Binding OpenProjectPropertiesCommand}"
378+
CommandParameter="{Binding SelectedItem}" />
378379
<Separator />
379380
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Add}">
380381
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_AddTestModuleText}"
@@ -740,8 +741,8 @@
740741

741742
<Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="DimGray">
742743

743-
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
744-
<StackPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
744+
<ScrollViewer Background="WhiteSmoke" VerticalScrollBarVisibility="Auto">
745+
<WrapPanel Orientation="Vertical" MinHeight="48" Background="WhiteSmoke">
745746

746747
<Grid Margin="4" HorizontalAlignment="Stretch">
747748
<Grid.ColumnDefinitions>
@@ -776,7 +777,7 @@
776777
CommandParameter="{Binding SelectedItem}"
777778
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_FindAllReferencesText}" />
778779
</WrapPanel>
779-
</StackPanel>
780+
</WrapPanel>
780781
</ScrollViewer>
781782
</Border>
782783
</Grid>

0 commit comments

Comments
 (0)