Skip to content

Commit 54bdb08

Browse files
committed
Update
with all the suggestions
1 parent 9022ff5 commit 54bdb08

File tree

5 files changed

+115
-121
lines changed

5 files changed

+115
-121
lines changed

External/Plugins/ASCompletion/Completion/ASComplete.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,10 @@ private static void ClearResolvedContext()
860860
NotifyContextChanged();
861861
}
862862

863-
public static void NotifyContextChanged()
863+
private static void NotifyContextChanged()
864864
{
865-
OnResolvedContextChanged?.Invoke(CurrentResolvedContext);
865+
if (OnResolvedContextChanged != null)
866+
OnResolvedContextChanged.Invoke(CurrentResolvedContext);
866867
}
867868

868869
/// <summary>

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public class ASGenerator
4444

4545
static List<ICompletionListItem> known;
4646

47-
public static List<ICompletionListItem> KnownList => known;
48-
4947
static private bool isHaxe
5048
{
5149
get { return ASContext.Context.CurrentModel.haXe; }
@@ -59,18 +57,18 @@ static public bool HandleGeneratorCompletion(ScintillaControl Sci, bool autoHide
5957
return false;
6058
}
6159

62-
static public void ContextualGenerator(ScintillaControl Sci)
60+
public static List<ICompletionListItem> ContextualGenerator(ScintillaControl Sci)
6361
{
6462
known = new List<ICompletionListItem>();
6563

6664
if (ASContext.Context is ASContext) (ASContext.Context as ASContext).UpdateCurrentFile(false); // update model
67-
if ((ASContext.Context.CurrentClass.Flags & (FlagType.Enum | FlagType.TypeDef)) > 0) return;
65+
if ((ASContext.Context.CurrentClass.Flags & (FlagType.Enum | FlagType.TypeDef)) > 0) return known;
6866

6967
lookupPosition = -1;
7068
int position = Sci.CurrentPos;
7169
int style = Sci.BaseStyleAt(position);
7270
if (style == 19) // on keyword
73-
return;
71+
return known;
7472

7573
bool isNotInterface = (ASContext.Context.CurrentClass.Flags & FlagType.Interface) == 0;
7674
int line = Sci.LineFromPosition(position);
@@ -85,8 +83,8 @@ static public void ContextualGenerator(ScintillaControl Sci)
8583
{
8684
if (style == 4 || style == 6 || style == 7)
8785
{
88-
ShowConvertToConst(found, style);
89-
return;
86+
ShowConvertToConst(found);
87+
return known;
9088
}
9189
}
9290

@@ -109,21 +107,21 @@ static public void ContextualGenerator(ScintillaControl Sci)
109107
{
110108
contextParam = resolve.Type.Type;
111109
ShowImplementInterface(found);
112-
return;
110+
return known;
113111
}
114112

115113
if (resolve.Member != null && !ASContext.Context.CurrentClass.IsVoid()
116114
&& (resolve.Member.Flags & FlagType.LocalVar) > 0) // promote to class var
117115
{
118116
contextMember = resolve.Member;
119117
ShowPromoteLocalAndAddParameter(found);
120-
return;
118+
return known;
121119
}
122120
}
123121

124122
if (contextToken != null && resolve.Member == null) // import declaration
125123
{
126-
if ((resolve.Type == null || resolve.Type.IsVoid() || !ASContext.Context.IsImported(resolve.Type, line)) && CheckAutoImport(found)) return;
124+
if ((resolve.Type == null || resolve.Type.IsVoid() || !ASContext.Context.IsImported(resolve.Type, line)) && CheckAutoImport(found)) return known;
127125
if (resolve.Type == null)
128126
{
129127
suggestItemDeclaration = ASComplete.IsTextStyle(Sci.BaseStyleAt(position - 1));
@@ -142,10 +140,10 @@ static public void ContextualGenerator(ScintillaControl Sci)
142140
contextMatch = m;
143141
ClassModel type = ASContext.Context.ResolveType(contextToken, ASContext.Context.CurrentModel);
144142
if (type.IsVoid() && CheckAutoImport(found))
145-
return;
143+
return known;
146144
}
147145
ShowGetSetList(found);
148-
return;
146+
return known;
149147
}
150148
// inside a function
151149
else if ((found.member.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) > 0
@@ -161,14 +159,14 @@ static public void ContextualGenerator(ScintillaControl Sci)
161159
contextMatch = m;
162160
contextParam = CheckEventType(m.Groups["event"].Value);
163161
ShowEventList(found);
164-
return;
162+
return known;
165163
}
166164
m = Regex.Match(text, String.Format(patternAS2Delegate, contextToken), RegexOptions.IgnoreCase);
167165
if (m.Success)
168166
{
169167
contextMatch = m;
170168
ShowDelegateList(found);
171-
return;
169+
return known;
172170
}
173171
// suggest delegate
174172
if (ASContext.Context.Features.hasDelegates)
@@ -183,7 +181,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
183181
contextMember = ResolveDelegate(resolve.Member.Type, resolve.InFile);
184182
contextMatch = m;
185183
ShowDelegateList(found);
186-
return;
184+
return known;
187185
}
188186
}
189187
}
@@ -202,7 +200,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
202200
contextParam = CheckEventType(m.Groups["event"].Value);
203201
ShowEventList(found);
204202
}
205-
return;
203+
return known;
206204
}
207205

208206
// insert default delegate name, then "generate delegate" suggestion
@@ -226,7 +224,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
226224
contextMatch = m;
227225
ShowDelegateList(found);
228226
}
229-
return;
227+
return known;
230228
}
231229
}
232230
}
@@ -241,7 +239,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
241239
{
242240
contextMember = resolve.Member;
243241
ShowFieldFromParameter(found);
244-
return;
242+
return known;
245243
}
246244

247245
// "add to interface" suggestion
@@ -279,7 +277,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
279277
if (interfaces.Count > 0)
280278
{
281279
ShowAddInterfaceDefList(found, interfaces);
282-
return;
280+
return known;
283281
}
284282
}
285283

@@ -290,7 +288,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
290288
&& ln.Length <= Sci.CurrentPos - Sci.PositionFromLine(curLine)) // cursor at end of line
291289
{
292290
ShowAssignStatementToVarList(found);
293-
return;
291+
return known;
294292
}
295293
}
296294

@@ -311,7 +309,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
311309
if (!hasConstructor || !hasToString)
312310
{
313311
ShowConstructorAndToStringList(found, hasConstructor, hasToString);
314-
return;
312+
return known;
315313
}
316314
}
317315

@@ -338,7 +336,7 @@ static public void ContextualGenerator(ScintillaControl Sci)
338336
{
339337
contextParam = eventResolve.Type.QualifiedName;
340338
ShowEventMetatagList(found);
341-
return;
339+
return known;
342340
}
343341
aType = aType.Extends;
344342
}
@@ -402,7 +400,8 @@ static public void ContextualGenerator(ScintillaControl Sci)
402400
}
403401
}
404402
}
405-
// TODO: Empty line, show generators list?
403+
// TODO: Empty line, show generators list? yep
404+
return known;
406405
}
407406

408407
private static MemberModel ResolveDelegate(string type, FileModel inFile)
@@ -599,10 +598,10 @@ private static void ShowPromoteLocalAndAddParameter(FoundDeclaration found)
599598
known.Add(new GeneratorItem(labelParam, GeneratorJobType.AddAsParameter, found.member, found.inClass));
600599
}
601600

602-
private static void ShowConvertToConst(FoundDeclaration found, int style)
601+
private static void ShowConvertToConst(FoundDeclaration found)
603602
{
604603
string label = TextHelper.GetString("ASCompletion.Label.ConvertToConst");
605-
known.Add(new GeneratorItem(label, GeneratorJobType.ConvertToConst, found.member, found.inClass, style));
604+
known.Add(new GeneratorItem(label, GeneratorJobType.ConvertToConst, found.member, found.inClass));
606605
}
607606

608607
private static void ShowImplementInterface(FoundDeclaration found)
@@ -1100,7 +1099,7 @@ static public void GenerateJob(GeneratorJobType job, MemberModel member, ClassMo
11001099
Sci.BeginUndoAction();
11011100
try
11021101
{
1103-
ConvertToConst(inClass, Sci, member, detach, (int) data);
1102+
ConvertToConst(inClass, Sci, member, detach);
11041103
}
11051104
finally
11061105
{
@@ -1363,7 +1362,7 @@ private static void EventMetatag(ClassModel inClass, ScintillaControl Sci, Membe
13631362
InsertCode(position, template);
13641363
}
13651364

1366-
private static void ConvertToConst(ClassModel inClass, ScintillaControl Sci, MemberModel member, bool detach, int style)
1365+
private static void ConvertToConst(ClassModel inClass, ScintillaControl Sci, MemberModel member, bool detach)
13671366
{
13681367
String suggestion = "NEW_CONST";
13691368
String label = TextHelper.GetString("ASCompletion.Label.ConstName");
@@ -1381,6 +1380,7 @@ private static void ConvertToConst(ClassModel inClass, ScintillaControl Sci, Mem
13811380
suggestion = (string)info["suggestion"];
13821381

13831382
int position = Sci.CurrentPos;
1383+
int style = Sci.BaseStyleAt(position);
13841384
MemberModel latest = null;
13851385

13861386
int wordPosEnd = position + 1;
@@ -1430,9 +1430,6 @@ private static void ConvertToConst(ClassModel inClass, ScintillaControl Sci, Mem
14301430
case 7:
14311431
m.Type = features.stringKey;
14321432
break;
1433-
default:
1434-
m.Type = features.dynamicKey ?? features.objectKey;
1435-
break;
14361433
}
14371434

14381435
m.Value = word;
@@ -4495,35 +4492,6 @@ public Object Data
44954492
}
44964493
}
44974494

4498-
class RefactorItem : ICompletionListItem
4499-
{
4500-
ToolStripItem value;
4501-
string label;
4502-
Bitmap icon;
4503-
4504-
public RefactorItem(ToolStripItem item)
4505-
{
4506-
value = item;
4507-
label = Regex.Replace(item.Text, "[&.]", string.Empty);
4508-
icon = new Bitmap(item.Image ?? PluginBase.MainForm.FindImage("452")); //452, 473
4509-
}
4510-
4511-
public string Description => TextHelper.GetString("Info.GeneratorTemplate");
4512-
4513-
public Bitmap Icon => icon;
4514-
4515-
public string Label => label;
4516-
4517-
public string Value
4518-
{
4519-
get
4520-
{
4521-
value.PerformClick();
4522-
return null;
4523-
}
4524-
}
4525-
}
4526-
45274495
class FoundDeclaration
45284496
{
45294497
public MemberModel member;

External/Plugins/ASCompletion/PluginMain.cs

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
477477
case EventType.Command:
478478
de = e as DataEvent;
479479
string command = de.Action ?? "";
480-
if (command.StartsWith("ASCompletion."))
480+
if (command.StartsWith("ASCompletion.", StringComparison.Ordinal))
481481
{
482482
string cmdData = de.Data as string;
483483
// run MTASC
@@ -534,9 +534,10 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
534534
{
535535
if (ASContext.HasContext && ASContext.Context.IsFileValid)
536536
{
537-
ASGenerator.ContextualGenerator(ASContext.CurSciControl);
538-
AddRefactorMenus(ASGenerator.KnownList, de.Data as ToolStripMenuItem);
539-
CompletionList.Show(ASGenerator.KnownList, false);
537+
var options = ASGenerator.ContextualGenerator(ASContext.CurSciControl);
538+
var dataEvent = new DataEvent(EventType.Command, "ASCompletion.ContextualGenerator.AddOptions", options);
539+
EventManager.DispatchEvent(this, dataEvent);
540+
CompletionList.Show(options, false);
540541
}
541542
}
542543
}
@@ -963,59 +964,6 @@ private void ContextChanged()
963964
SetItemsEnabled(enableItems, ASContext.Context.CanBuild);
964965
}
965966
#endregion
966-
967-
#region Contextual Code Generation Utilities
968-
969-
void AddRefactorMenus(List<ICompletionListItem> list, ToolStripMenuItem menu)
970-
{
971-
if (list == null)
972-
return;
973-
974-
ASComplete.NotifyContextChanged();
975-
Type RefactorMenu = menu.GetType();
976-
977-
var RenameMenuItem = GetItem(RefactorMenu, menu, "RenameMenuItem");
978-
var ExtractMethodMenuItem = GetItem(RefactorMenu, menu, "ExtractMethodMenuItem");
979-
var ExtractLocalVariableMenuItem = GetItem(RefactorMenu, menu, "ExtractLocalVariableMenuItem");
980-
var DelegateMenuItem = GetItem(RefactorMenu, menu, "DelegateMenuItem");
981-
982-
if (RenameMenuItem.Enabled) list.Add(new RefactorItem(RenameMenuItem));
983-
if (ExtractMethodMenuItem.Enabled) list.Add(new RefactorItem(ExtractMethodMenuItem));
984-
if (ExtractLocalVariableMenuItem.Enabled) list.Add(new RefactorItem(ExtractLocalVariableMenuItem));
985-
if (DelegateMenuItem.Enabled) list.Add(new RefactorItem(DelegateMenuItem));
986-
987-
var features = ASContext.Context.Features;
988-
989-
if (!features.hasImports)
990-
return;
991-
992-
var sci = ASContext.CurSciControl;
993-
string line = sci.GetLine(sci.CurrentLine).TrimStart();
994-
995-
if (line.StartsWith(features.importKey, StringComparison.Ordinal)
996-
|| !string.IsNullOrEmpty(features.importKeyAlt) && line.StartsWith(features.importKeyAlt, StringComparison.Ordinal))
997-
{
998-
var OrganizeMenuItem = GetItem(RefactorMenu, menu, "OrganizeMenuItem");
999-
1000-
if (OrganizeMenuItem.Enabled)
1001-
list.Add(new RefactorItem(OrganizeMenuItem));
1002-
1003-
if (features.hasImportsWildcard)
1004-
{
1005-
var TruncateMenuItem = GetItem(RefactorMenu, menu, "TruncateMenuItem");
1006-
1007-
if (TruncateMenuItem.Enabled)
1008-
list.Add(new RefactorItem(TruncateMenuItem));
1009-
}
1010-
}
1011-
}
1012-
1013-
ToolStripMenuItem GetItem(Type type, ToolStripMenuItem menu, string item)
1014-
{
1015-
return type.GetProperty(item).GetValue(menu, null) as ToolStripMenuItem;
1016-
}
1017-
1018-
#endregion
1019967
}
1020968

1021969
}

0 commit comments

Comments
 (0)