1010using HaXeContext ;
1111using PluginCore ;
1212using PluginCore . Helpers ;
13- using ScintillaNet ;
1413
1514namespace PostfixCodeCompletion . Helpers
1615{
@@ -19,15 +18,16 @@ 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" ;
30+ internal const string PATTERN_TYPE = "PCCType" ;
3131 public static Settings Settings { get ; set ; }
3232
3333 static readonly List < string > Templates = new List < string >
@@ -38,7 +38,8 @@ static class TemplateUtils
3838 PATTERN_HASH ,
3939 PATTERN_BOOL ,
4040 PATTERN_NUMBER ,
41- PATTERN_STRING
41+ PATTERN_STRING ,
42+ PATTERN_TYPE
4243 } ;
4344
4445 internal static bool GetHasTemplates ( )
@@ -82,7 +83,7 @@ internal static Dictionary<string, string> GetTemplates(string type)
8283 foreach ( var file in Directory . GetFiles ( path , "*.fds" ) )
8384 {
8485 var content = GetFileContent ( file ) ;
85- var marker = "#pcc:" + type ;
86+ var marker = $ "#pcc:{ type } " ;
8687 var startIndex = content . IndexOf ( marker , StringComparison . Ordinal ) ;
8788 if ( startIndex != - 1 )
8889 {
@@ -113,7 +114,11 @@ internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult
113114 {
114115 string type = null ;
115116 var varname = string . Empty ;
116- 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 ;
117122 var member = expr . Member ;
118123 if ( member != null && member . Type != null ) type = member . Type ;
119124 else
@@ -126,7 +131,7 @@ internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult
126131 if ( ! string . IsNullOrEmpty ( word ) && ( string . IsNullOrEmpty ( type ) || Regex . IsMatch ( type , "(<[^]]+>)" ) ) ) word = null ;
127132 if ( ! string . IsNullOrEmpty ( type ) && type == ASContext . Context . Features . voidKey ) type = null ;
128133 if ( string . IsNullOrEmpty ( varname ) ) varname = Reflector . ASGenerator . GuessVarName ( word , type ) ;
129- if ( ! string . IsNullOrEmpty ( varname ) && varname == word && varname . Length == 1 ) varname = varname + " 1";
134+ if ( ! string . IsNullOrEmpty ( varname ) && varname == word ) varname = $ " { varname } 1";
130135 return new KeyValuePair < string , string > ( varname , type ) ;
131136 }
132137
@@ -145,7 +150,7 @@ internal static string ProcessMemberTemplate(string template, ASResult expr)
145150 internal static string ProcessCollectionTemplate ( string template , ASResult expr )
146151 {
147152 var type = expr . Member != null ? expr . Member . Type : expr . Type . QualifiedName ;
148- if ( type . Contains ( "@" ) ) type = type . Replace ( "@" , ".<" ) + " >";
153+ if ( type . Contains ( "@" ) ) type = $ " { type . Replace ( "@" , ".<" ) } >";
149154 type = Regex . Match ( type , "<([^]]+)>" ) . Groups [ 1 ] . Value ;
150155 type = Reflector . ASGenerator . GetShortType ( type ) ;
151156 switch ( PluginBase . MainForm . CurrentDocument . SciControl . ConfigurationLanguage )
0 commit comments