Skip to content

Commit 4fd1d17

Browse files
author
SlavaRa
committed
Merge pull request #34 from SlavaRa/develop
Closes #33
2 parents bffd2d9 + 09c3455 commit 4fd1d17

33 files changed

+67
-53
lines changed

PostfixCodeCompletion/Helpers/Reflector.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,25 @@ internal string GetShortType(string type)
6666
return (string)methodInfo.Invoke(null, new object[] { type });
6767
}
6868

69-
internal ASResult GetStatementReturnType(ScintillaControl sci, string line, int positionFromLine)
69+
internal StatementReturnType GetStatementReturnType(ScintillaControl sci, string line, int positionFromLine)
7070
{
7171
var methodInfo = typeof(ASGenerator).GetMethod("GetStatementReturnType", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
7272
var returnType = methodInfo.Invoke(null, new object[] { sci, ASContext.Context.CurrentClass, line, positionFromLine });
73-
var expr = returnType != null
74-
? (ASResult) returnType.GetType().GetField("resolve").GetValue(returnType)
75-
: null;
76-
return expr;
73+
if (returnType == null) return null;
74+
var result = new StatementReturnType
75+
{
76+
Resolve = (ASResult) returnType.GetType().GetField("resolve").GetValue(returnType),
77+
Position = (int) returnType.GetType().GetField("position").GetValue(returnType),
78+
Word = (string) returnType.GetType().GetField("word").GetValue(returnType)
79+
};
80+
return result;
7781
}
7882
}
83+
84+
internal class StatementReturnType
85+
{
86+
public ASResult Resolve;
87+
public int Position;
88+
public string Word;
89+
}
7990
}

PostfixCodeCompletion/Helpers/TemplateUtils.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using HaXeContext;
1111
using PluginCore;
1212
using PluginCore.Helpers;
13-
using ScintillaNet;
1413

1514
namespace PostfixCodeCompletion.Helpers
1615
{
@@ -19,15 +18,15 @@ static class TemplateUtils
1918
public const string PATTERN_BLOCK = @"\$\([^\)]*{0}.*?\)";
2019
public const string PATTERN_T_BLOCK = @"[^\$]*?\$\({0}\)";
2120
internal const string POSTFIX_GENERATORS = "PostfixGenerators";
22-
internal const string PATTERN_MEMBER = "Member";
23-
internal const string PATTERN_NULLABLE = "Nullable";
24-
internal const string PATTERN_COLLECTION = "Collection";
21+
internal const string PATTERN_MEMBER = "PCCMember";
22+
internal const string PATTERN_NULLABLE = "PCCNullable";
23+
internal const string PATTERN_COLLECTION = "PCCCollection";
2524
internal const string PATTERN_COLLECTION_KEY_TYPE = "$(CollectionKeyType)";
2625
internal const string PATTERN_COLLECTION_ITEM_TYPE = "$(CollectionItemType)";
27-
internal const string PATTERN_HASH = "Hash";
28-
internal const string PATTERN_BOOL = "Boolean";
29-
internal const string PATTERN_NUMBER = "Number";
30-
internal const string PATTERN_STRING = "String";
26+
internal const string PATTERN_HASH = "PCCHash";
27+
internal const string PATTERN_BOOL = "PCCBoolean";
28+
internal const string PATTERN_NUMBER = "PCCNumber";
29+
internal const string PATTERN_STRING = "PCCString";
3130
internal const string PATTERN_TYPE = "PCCType";
3231
public static Settings Settings { get; set; }
3332

@@ -115,7 +114,11 @@ internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult
115114
{
116115
string type = null;
117116
var varname = string.Empty;
118-
var word = string.Empty;
117+
var sci = PluginBase.MainForm.CurrentDocument.SciControl;
118+
var lineNum = sci.CurrentLine;
119+
var line = sci.GetLine(lineNum);
120+
var returnType = Reflector.ASGenerator.GetStatementReturnType(sci, line, sci.PositionFromLine(lineNum));
121+
var word = returnType?.Word;
119122
var member = expr.Member;
120123
if (member != null && member.Type != null) type = member.Type;
121124
else
@@ -128,7 +131,7 @@ internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult
128131
if (!string.IsNullOrEmpty(word) && (string.IsNullOrEmpty(type) || Regex.IsMatch(type, "(<[^]]+>)"))) word = null;
129132
if (!string.IsNullOrEmpty(type) && type == ASContext.Context.Features.voidKey) type = null;
130133
if (string.IsNullOrEmpty(varname)) varname = Reflector.ASGenerator.GuessVarName(word, type);
131-
if (!string.IsNullOrEmpty(varname) && varname == word && varname.Length == 1) varname = varname + "1";
134+
if (!string.IsNullOrEmpty(varname) && varname == word) varname = $"{varname}1";
132135
return new KeyValuePair<string, string>(varname, type);
133136
}
134137

@@ -147,7 +150,7 @@ internal static string ProcessMemberTemplate(string template, ASResult expr)
147150
internal static string ProcessCollectionTemplate(string template, ASResult expr)
148151
{
149152
var type = expr.Member != null ? expr.Member.Type : expr.Type.QualifiedName;
150-
if (type.Contains("@")) type = type.Replace("@", ".<") + ">";
153+
if (type.Contains("@")) type = $"{type.Replace("@", ".<")}>";
151154
type = Regex.Match(type, "<([^]]+)>").Groups[1].Value;
152155
type = Reflector.ASGenerator.GetShortType(type);
153156
switch (PluginBase.MainForm.CurrentDocument.SciControl.ConfigurationLanguage)

PostfixCodeCompletion/PluginMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static ASResult GetPostfixCompletionExpr()
235235
var line = sci.GetLine(currentLine).Trim();
236236
line = line.Remove(position);
237237
line = line.Insert(position, ";");
238-
return Reflector.ASGenerator.GetStatementReturnType(sci, line, positionFromLine);
238+
return Reflector.ASGenerator.GetStatementReturnType(sci, line, positionFromLine).Resolve;
239239
}
240240

241241
static MemberModel GetPostfixCompletionTarget(ASResult expr)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const $(EntryPoint)$(Name)<<:$(Type)>> = $(Member);
1+
const $(EntryPoint)$(Name)<<:$(Type)>> = $(PCCMember);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
do $(CSLB){
22
$(EntryPoint)
3-
} while ($(Boolean|Nullable))
3+
} while ($(PCCBoolean|PCCNullable))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
if (!$(Boolean)) $(CSLB){
1+
if (!$(PCCBoolean)) $(CSLB){
22
$(EntryPoint)
33
}

Snippets/as3/postfixgenerators/for.fds

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#pcc:Collection
2-
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(Collection).length; $(ItmUniqueVar)++) $(CSLB){
1+
#pcc:PCCCollection
2+
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(PCCCollection).length; $(ItmUniqueVar)++) $(CSLB){
33
$(EntryPoint)
44
}
5-
#pcc:Number
6-
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(Number); $(ItmUniqueVar)++) $(CSLB){
5+
#pcc:PCCNumber
6+
for (var $(ItmUniqueVar):int = 0; $(ItmUniqueVar) < $(PCCNumber); $(ItmUniqueVar)++) $(CSLB){
77
$(EntryPoint)
88
}
99
#pcc:int
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
for each (var item:$(CollectionItemType) in $(Collection|Hash)) $(CSLB){
1+
for each (var item:$(CollectionItemType) in $(PCCCollection|PCCHash)) $(CSLB){
22
$(EntryPoint)
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
for (var key:$(CollectionKeyType) in $(Collection|Hash)) $(CSLB){
1+
for (var key:$(CollectionKeyType) in $(PCCCollection|PCCHash)) $(CSLB){
22
$(EntryPoint)
33
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
for (var $(ItmUniqueVar):int = $(Collection).length - 1; $(ItmUniqueVar) >= 0; $(ItmUniqueVar)--) $(CSLB){
1+
for (var $(ItmUniqueVar):int = $(PCCCollection).length - 1; $(ItmUniqueVar) >= 0; $(ItmUniqueVar)--) $(CSLB){
22
$(EntryPoint)
33
}
4-
#pcc:Number
5-
for (var $(ItmUniqueVar):int = $(Number); $(ItmUniqueVar) >= 0; $(ItmUniqueVar)--) $(CSLB){
4+
#pcc:PCCNumber
5+
for (var $(ItmUniqueVar):int = $(PCCNumber); $(ItmUniqueVar) >= 0; $(ItmUniqueVar)--) $(CSLB){
66
$(EntryPoint)
77
}

0 commit comments

Comments
 (0)