Skip to content

Commit 750cce0

Browse files
author
Slava Buynov
committed
Merge branch 'release/tip'
2 parents c003a3d + 3c33e9f commit 750cce0

File tree

14 files changed

+125
-163
lines changed

14 files changed

+125
-163
lines changed

PostfixCodeCompletion.Tests/Completion/PostfixGeneratorTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,31 @@ public IEnumerable<TestCaseData> Foreach
206206
yield return
207207
GetTestCaseFromArray("foreach")
208208
.Returns(ReadCode("AfterGenerateForeach_fromArray"))
209-
.SetName("foreach from array.|");
209+
.SetName("array.foreach|");
210210
yield return
211211
GetTestCaseFromArrayInitializer("foreach")
212212
.Returns(ReadCode("AfterGenerateForeach_fromArrayInitializer"))
213-
.SetName("foreach from [].|");
213+
.SetName("[].foreach|");
214214
yield return
215215
GetTestCaseFromObject("foreach")
216216
.Returns(ReadCode("AfterGenerateForeach_fromObject"))
217-
.SetName("foreach from object.|");
217+
.SetName("object.foreach|");
218218
yield return
219219
GetTestCaseFromObjectInitializer("foreach")
220220
.Returns(ReadCode("AfterGenerateForeach_fromObjectInitializer"))
221-
.SetName("foreach from {}.|");
221+
.SetName("{}.foreach|");
222222
yield return
223223
GetTestCaseFromDictionary("foreach")
224224
.Returns(ReadCode("AfterGenerateForeach_fromDictionary"))
225-
.SetName("foreach from dictionary.|");
225+
.SetName("dictionary.foreach|");
226226
yield return
227227
GetTestCaseFromVector("foreach")
228228
.Returns(ReadCode("AfterGenerateForeach_fromVector"))
229-
.SetName("foreach from vector.|");
229+
.SetName("vector.foreach|");
230+
yield return
231+
GetTestCaseFromString("foreach")
232+
.Returns(ReadCode("AfterGenerateString.foreach"))
233+
.SetName("'string'.foreach|");
230234
}
231235
}
232236

PostfixCodeCompletion.Tests/PostfixCodeCompletion.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<ItemGroup>
5151
<Reference Include="NSubstitute, Version=2.0.3.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
5252
<HintPath>..\..\..\..\packages\NSubstitute.2.0.3\lib\net40\NSubstitute.dll</HintPath>
53-
<Private>True</Private>
53+
<Private>True</Private>
5454
</Reference>
5555
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
5656
<HintPath>..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
@@ -87,7 +87,6 @@
8787
<EmbeddedResource Include="Test Snippets\as3\postfixgenerators\var.fds" />
8888
<EmbeddedResource Include="Test Snippets\as3\postfixgenerators\while.fds" />
8989
<EmbeddedResource Include="Test Snippets\as3\postfixgenerators\trace.fds" />
90-
<EmbeddedResource Include="Test Snippets\haxe\postfixgenerators\code.fds" />
9190
<EmbeddedResource Include="Test Snippets\haxe\postfixgenerators\dowhile.fds" />
9291
<EmbeddedResource Include="Test Snippets\haxe\postfixgenerators\else.fds" />
9392
<EmbeddedResource Include="Test Snippets\haxe\postfixgenerators\for.fds" />
@@ -173,13 +172,14 @@
173172
<EmbeddedResource Include="Test Files\generated\as3\AfterGenerateFor_fromVectorInitializer.as" />
174173
<EmbeddedResource Include="Test Files\generated\as3\AfterGenerateString.for.as" />
175174
<EmbeddedResource Include="Test Files\generated\as3\AfterGenerateString.forr.as" />
175+
<EmbeddedResource Include="Test Files\generated\as3\AfterGenerateString.foreach.as" />
176176
</ItemGroup>
177177
<ItemGroup />
178178
<ItemGroup>
179179
<ProjectReference Include="..\..\..\..\PluginCore\PluginCore.csproj">
180180
<Project>{61885F70-B4DC-4B44-852D-5D6D03F2A734}</Project>
181181
<Name>PluginCore</Name>
182-
<Private>False</Private>
182+
<Private>False</Private>
183183
</ProjectReference>
184184
<ProjectReference Include="..\..\..\..\Tests\External\Plugins\ASCompletion.Tests\ASCompletion.Tests.csproj">
185185
<Project>{ABC71D26-295C-4C6C-B6DE-320AD49EEF79}</Project>
@@ -188,7 +188,7 @@
188188
<ProjectReference Include="..\..\ASCompletion\ASCompletion.csproj">
189189
<Project>{4EBF2653-9654-4E40-880E-0046B3D6210E}</Project>
190190
<Name>ASCompletion</Name>
191-
<Private>False</Private>
191+
<Private>False</Private>
192192
</ProjectReference>
193193
<ProjectReference Include="..\PostfixCodeCompletion\PostfixCodeCompletion.csproj">
194194
<Project>{e511b03b-81fd-4c39-b587-211f2a1603a1}</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package {
2+
public class Main {
3+
public function Main() {
4+
for (var i:int = 0; i < "".length; i++) {
5+
var char:String = "".charAt(i);
6+
7+
}
8+
}
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
for each (var item:$(CollectionItemType) in $(PCCCollection|PCCHash)) $(CSLB){
22
$(EntryPoint)
3+
}
4+
#pcc:PCCString
5+
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(PCCString).length; $(ItmUniqueVar)++) $(CSLB){
6+
var char:String = $(PCCString).charAt($(ItmUniqueVar));
7+
$(EntryPoint)
38
}

PostfixCodeCompletion.Tests/Test Snippets/haxe/postfixgenerators/code.fds

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
for (it in $(PCCCollection|PCCHash)) $(CSLB){
22
$(EntryPoint)
33
}
4+
#pcc:PCCString
5+
for ($(ItmUniqueVar) in 0...$(PCCString).length) $(CSLB){
6+
var char = $(PCCString).charAt($(EntryPoint));
7+
$(EntryPoint)
8+
}

PostfixCodeCompletion/Completion/Complete.cs

Lines changed: 44 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.IO;
54
using System.Linq;
@@ -54,11 +53,11 @@ internal static void Stop()
5453

5554
internal static bool OnCharAdded(int value) => current?.OnCharAdded(value) ?? false;
5655

57-
internal static void UpdateCompletionList() => current?.UpdateCompletionList();
56+
internal static void UpdateCompletionList(IList<ICompletionListItem> options) => current?.UpdateCompletionList(options);
5857

59-
internal static void UpdateCompletionList(ASResult expr) => current?.UpdateCompletionList(expr);
58+
internal static void UpdateCompletionList(ASResult expr, IList<ICompletionListItem> options) => current?.UpdateCompletionList(expr, options);
6059

61-
internal static void UpdateCompletionList(MemberModel target, ASResult expr) => current?.UpdateCompletionList(target, expr);
60+
internal static void UpdateCompletionList(MemberModel target, ASResult expr, IList<ICompletionListItem> options) => current?.UpdateCompletionList(target, expr, options);
6261
}
6362

6463
public interface IPCCComplete
@@ -67,9 +66,9 @@ public interface IPCCComplete
6766
void Stop();
6867
bool OnShortcut(Keys keys);
6968
bool OnCharAdded(int value);
70-
void UpdateCompletionList();
71-
bool UpdateCompletionList(ASResult expr);
72-
void UpdateCompletionList(MemberModel target, ASResult expr);
69+
void UpdateCompletionList(IList<ICompletionListItem> options);
70+
bool UpdateCompletionList(ASResult expr, IList<ICompletionListItem> options);
71+
void UpdateCompletionList(MemberModel target, ASResult expr, IList<ICompletionListItem> options);
7372
}
7473

7574
public class PCCComplete : IPCCComplete
@@ -86,122 +85,89 @@ public virtual void Stop()
8685

8786
public virtual bool OnCharAdded(int value) => false;
8887

89-
public virtual void UpdateCompletionList() => UpdateCompletionList(CompleteHelper.GetCurrentExpressionType());
88+
public virtual void UpdateCompletionList(IList<ICompletionListItem> options) => UpdateCompletionList(CompleteHelper.GetCurrentExpressionType(), options);
9089

91-
public virtual bool UpdateCompletionList(ASResult expr) => false;
90+
public virtual bool UpdateCompletionList(ASResult expr, IList<ICompletionListItem> options) => false;
9291

93-
public virtual void UpdateCompletionList(MemberModel target, ASResult expr)
92+
public virtual void UpdateCompletionList(MemberModel target, ASResult expr, IList<ICompletionListItem> options)
9493
{
9594
}
9695
}
9796

98-
public class PCCASComplete : PCCComplete
97+
public class PCCASComplete : PCCComplete, IEventHandler
9998
{
100-
static int completionListItemCount;
99+
public override void Start() => EventManager.AddEventHandler(this, EventType.Command);
101100

102-
public override void Start()
103-
{
104-
var completionList = Reflector.CompletionList.CompletionList;
105-
completionList.VisibleChanged -= OnCompletionListVisibleChanged;
106-
completionList.VisibleChanged += OnCompletionListVisibleChanged;
107-
}
108-
109-
public override void Stop()
110-
{
111-
var completionList = Reflector.CompletionList.CompletionList;
112-
completionList.VisibleChanged -= OnCompletionListVisibleChanged;
113-
completionList.SelectedValueChanged -= OnCompletionListSelectedValueChanged;
114-
}
101+
public override void Stop() => EventManager.RemoveEventHandler(this);
115102

116103
public override bool OnShortcut(Keys keys)
117104
{
118-
if (keys != (Keys.Control | Keys.Space)) return false;
119-
var completionList = Reflector.CompletionList.CompletionList;
120-
if (CompletionList.Active) return false;
105+
if (CompletionList.Active || keys != (Keys.Control | Keys.Space)) return false;
121106
var expr = CompleteHelper.GetCurrentExpressionType();
122107
if (expr == null || expr.IsNull()) return false;
123108
var result = ASComplete.OnShortcut(keys, PluginBase.MainForm.CurrentDocument.SciControl);
124-
completionList.VisibleChanged -= OnCompletionListVisibleChanged;
125-
UpdateCompletionList(expr);
126-
completionList.VisibleChanged += OnCompletionListVisibleChanged;
109+
UpdateCompletionList(expr, new List<ICompletionListItem>());
127110
return result;
128111
}
129112

130113
public override bool OnCharAdded(int value)
131114
{
115+
if (CompletionList.Active) return false;
132116
if ((char) value != '.' || !TemplateUtils.GetHasTemplates()) return false;
133117
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
134118
if (sci.PositionIsOnComment(sci.CurrentPos)) return false;
135-
if (ASComplete.OnChar(sci, value, false))
136-
{
137-
if (Reflector.CompletionList.CompletionList.Visible) UpdateCompletionList();
138-
return false;
139-
}
140-
if (!Reflector.ASComplete.HandleDotCompletion(sci, true) || CompletionList.Active) return false;
119+
if (ASComplete.OnChar(sci, value, false) || Reflector.ASComplete.HandleDotCompletion(sci, true)) return false;
141120
var expr = CompleteHelper.GetCurrentExpressionType();
142121
if (expr == null || expr.IsNull()) return false;
143-
Reflector.CompletionList.CompletionList.VisibleChanged -= OnCompletionListVisibleChanged;
144-
UpdateCompletionList(expr);
145-
Reflector.CompletionList.CompletionList.VisibleChanged += OnCompletionListVisibleChanged;
122+
UpdateCompletionList(expr, new List<ICompletionListItem>());
146123
return true;
147124
}
148125

149-
public override bool UpdateCompletionList(ASResult expr)
126+
public override bool UpdateCompletionList(ASResult expr, IList<ICompletionListItem> options)
150127
{
151128
if (expr == null || expr.IsNull()) return false;
152129
var target = CompleteHelper.GetCompletionTarget(expr);
153130
if (target == null) return false;
154-
UpdateCompletionList(target, expr);
131+
UpdateCompletionList(target, expr, options);
155132
return true;
156133
}
157134

158-
public override void UpdateCompletionList(MemberModel target, ASResult expr)
135+
public override void UpdateCompletionList(MemberModel target, ASResult expr, IList<ICompletionListItem> options)
159136
{
160137
if (target == null || !TemplateUtils.GetHasTemplates()) return;
138+
var labels = new HashSet<string>();
139+
foreach (var item in options)
140+
{
141+
if (item is PostfixCompletionItem) labels.Add(item.Label);
142+
}
161143
var items = CompleteHelper.GetCompletionItems(target, expr);
162-
var allItems = Reflector.CompletionList.AllItems;
163-
if (allItems != null)
144+
foreach (var item in items)
164145
{
165-
var labels = new HashSet<string>();
166-
foreach (var item in allItems)
167-
{
168-
if (item is PostfixCompletionItem) labels.Add(item.Label);
169-
}
170-
foreach (var item in items)
171-
{
172-
if (!labels.Contains(item.Label)) allItems.Add(item);
173-
}
174-
items = allItems;
146+
if (!labels.Contains(item.Label)) options.Add(item);
175147
}
148+
if (CompletionList.Active) return;
176149
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
177150
var word = sci.GetWordLeft(sci.CurrentPos - 1, false);
178151
if (!string.IsNullOrEmpty(word))
179152
{
180-
items = items.FindAll(it =>
153+
options = options.Where(it =>
181154
{
182155
var score = CompletionList.SmartMatch(it.Label, word, word.Length);
183156
return score > 0 && score < 6;
184-
});
157+
}).ToList();
185158
}
186-
CompletionList.Show(items, false, word);
187-
var list = Reflector.CompletionList.CompletionList;
188-
completionListItemCount = list.Items.Count;
189-
list.SelectedValueChanged -= OnCompletionListSelectedValueChanged;
190-
list.SelectedValueChanged += OnCompletionListSelectedValueChanged;
191-
}
192-
193-
protected void OnCompletionListVisibleChanged(object o, EventArgs args)
194-
{
195-
var list = Reflector.CompletionList.CompletionList;
196-
if (list.Visible) UpdateCompletionList();
197-
else list.SelectedValueChanged -= OnCompletionListSelectedValueChanged;
159+
CompletionList.Show((List<ICompletionListItem>) options, false, word);
198160
}
199161

200-
protected void OnCompletionListSelectedValueChanged(object sender, EventArgs args)
162+
public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority)
201163
{
202-
var list = Reflector.CompletionList.CompletionList;
203-
list.SelectedValueChanged -= OnCompletionListSelectedValueChanged;
204-
if (completionListItemCount != list.Items.Count) UpdateCompletionList();
164+
switch (e.Type)
165+
{
166+
case EventType.Command:
167+
var de = (DataEvent)e;
168+
if (de.Action == "ASCompletion.DotCompletion") UpdateCompletionList((IList<ICompletionListItem>) de.Data);
169+
break;
170+
}
205171
}
206172
}
207173

@@ -227,9 +193,9 @@ public override void Stop()
227193
completionModeHandler = null;
228194
}
229195

230-
public override bool UpdateCompletionList(ASResult expr)
196+
public override bool UpdateCompletionList(ASResult expr, IList<ICompletionListItem> options)
231197
{
232-
var result = base.UpdateCompletionList(expr);
198+
var result = base.UpdateCompletionList(expr, options);
233199
if (result) return true;
234200
if (expr == null || expr.IsNull() || expr.Context == null || completionModeHandler == null) return false;
235201
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
@@ -285,22 +251,19 @@ void OnFunctionTypeResult(HaxeComplete hc, HaxeCompleteResult result, HaxeComple
285251
if (hc.AutoHide) CompletionList.Hide();
286252
break;
287253
case HaxeCompleteStatus.Type:
288-
var list = Reflector.CompletionList.CompletionList;
289-
list.VisibleChanged -= OnCompletionListVisibleChanged;
290254
var expr = hc.Expr;
291255
if (result.Type is ClassModel)
292256
{
293257
expr.Type = (ClassModel) result.Type;
294258
expr.Member = null;
295-
UpdateCompletionList(expr.Type, expr);
259+
UpdateCompletionList(expr.Type, expr, Reflector.CompletionList.AllItems);
296260
}
297261
else
298262
{
299263
expr.Type = ASContext.Context.ResolveType(result.Type.Type, result.Type.InFile);
300264
expr.Member = result.Type;
301-
UpdateCompletionList(expr.Member, expr);
265+
UpdateCompletionList(expr.Member, expr, Reflector.CompletionList.AllItems);
302266
}
303-
list.VisibleChanged += OnCompletionListVisibleChanged;
304267
break;
305268
}
306269
}

PostfixCodeCompletion/Helpers/Reflector.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using System.Diagnostics;
33
using System.Reflection;
4-
using System.Windows.Forms;
54
using ASCompletion.Completion;
65
using ASCompletion.Context;
76
using ASCompletion.Model;
@@ -20,16 +19,6 @@ internal static class Reflector
2019

2120
internal class CompletionListReflector
2221
{
23-
internal ListBox CompletionList
24-
{
25-
get
26-
{
27-
var fieldInfo = typeof(CompletionList).GetField("completionList", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
28-
Debug.Assert(fieldInfo != null, "fieldInfo is null");
29-
return (ListBox) fieldInfo.GetValue(typeof(ListBox));
30-
}
31-
}
32-
3322
internal List<ICompletionListItem> AllItems
3423
{
3524
get

0 commit comments

Comments
 (0)