1- using System ;
2- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
32using System . IO ;
43using System . Linq ;
54using System . Text . RegularExpressions ;
1312
1413namespace PostfixCodeCompletion . Helpers
1514{
16- static class TemplateUtils
15+ internal static class TemplateUtils
1716 {
18- public const string PATTERN_BLOCK = @"\$\([^\)]*{0}.*?\)" ;
19- public const string PATTERN_T_BLOCK = @"[^\$]*?\$\({0}\)" ;
20- internal const string POSTFIX_GENERATORS = "PostfixGenerators" ;
21- internal const string PATTERN_MEMBER = "PCCMember" ;
22- internal const string PATTERN_NULLABLE = "PCCNullable" ;
23- internal const string PATTERN_COLLECTION = "PCCCollection" ;
24- internal const string PATTERN_COLLECTION_KEY_TYPE = "$(CollectionKeyType)" ;
25- internal const string PATTERN_COLLECTION_ITEM_TYPE = "$(CollectionItemType)" ;
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" ;
17+ public const string PatternBlock = @"\$\([^\)]*{0}.*?\)" ;
18+ public const string PatternTBlock = @"[^\$]*?\$\({0}\)" ;
19+ internal const string PostfixGenerators = "PostfixGenerators" ;
20+ internal const string PatternMember = "PCCMember" ;
21+ internal const string PatternNullable = "PCCNullable" ;
22+ internal const string PatternCollection = "PCCCollection" ;
23+ internal const string PatternCollectionKeyType = "$(CollectionKeyType)" ;
24+ internal const string PatternCollectionItemType = "$(CollectionItemType)" ;
25+ internal const string PatternHash = "PCCHash" ;
26+ internal const string PatternBool = "PCCBoolean" ;
27+ internal const string PatternNumber = "PCCNumber" ;
28+ internal const string PatternString = "PCCString" ;
29+ internal const string PatternType = "PCCType" ;
3130 public static Settings Settings { get ; set ; }
3231
3332 static readonly List < string > Templates = new List < string >
3433 {
35- PATTERN_MEMBER ,
36- PATTERN_NULLABLE ,
37- PATTERN_COLLECTION ,
38- PATTERN_HASH ,
39- PATTERN_BOOL ,
40- PATTERN_NUMBER ,
41- PATTERN_STRING ,
42- PATTERN_TYPE
34+ PatternMember ,
35+ PatternNullable ,
36+ PatternCollection ,
37+ PatternHash ,
38+ PatternBool ,
39+ PatternNumber ,
40+ PatternString ,
41+ PatternType
4342 } ;
4443
4544 internal static bool GetHasTemplates ( ) => GetHasTemplates ( PluginBase . MainForm . CurrentDocument . SciControl . ConfigurationLanguage . ToLower ( ) ) ;
4645
4746 internal static bool GetHasTemplates ( string language )
4847 {
49- return GetHasTemplates ( PathHelper . SnippetDir , language )
50- || Settings . CustomSnippetDirectories . Any ( it => GetHasTemplates ( it . Path , language ) ) ;
48+ return GetHasTemplates ( PathHelper . SnippetDir , language ) || Settings . CustomSnippetDirectories . Any ( it => GetHasTemplates ( it . Path , language ) ) ;
5149 }
5250
5351 static bool GetHasTemplates ( string snippetPath , string language )
@@ -58,11 +56,11 @@ static bool GetHasTemplates(string snippetPath, string language)
5856
5957 static string GetTemplatesDir ( string snippetPath ) => GetTemplatesDir ( snippetPath , PluginBase . MainForm . CurrentDocument . SciControl . ConfigurationLanguage . ToLower ( ) ) ;
6058
61- static string GetTemplatesDir ( string snippetPath , string language ) => Path . Combine ( Path . Combine ( snippetPath , language ) , POSTFIX_GENERATORS ) ;
59+ static string GetTemplatesDir ( string snippetPath , string language ) => Path . Combine ( Path . Combine ( snippetPath , language ) , PostfixGenerators ) ;
6260
6361 internal static Dictionary < string , string > GetTemplates ( string type )
6462 {
65- var pattern = Templates . Contains ( type ) ? string . Format ( PATTERN_BLOCK , type ) : string . Format ( PATTERN_T_BLOCK , type ) ;
63+ var pattern = Templates . Contains ( type ) ? string . Format ( PatternBlock , type ) : string . Format ( PatternTBlock , type ) ;
6664 var result = new Dictionary < string , string > ( ) ;
6765 var paths = Settings . CustomSnippetDirectories . Select ( it => GetTemplatesDir ( it . Path ) ) . ToList ( ) ;
6866 paths . Add ( GetTemplatesDir ( PathHelper . SnippetDir ) ) ;
@@ -73,13 +71,13 @@ internal static Dictionary<string, string> GetTemplates(string type)
7371 {
7472 var content = GetFileContent ( file ) ;
7573 var marker = $ "#pcc:{ type } ";
76- var startIndex = content . IndexOf ( marker , StringComparison . Ordinal ) ;
74+ var startIndex = content . IndexOfOrdinal ( marker ) ;
7775 if ( startIndex != - 1 )
7876 {
7977 startIndex += marker . Length ;
8078 content = content . Remove ( 0 , startIndex ) ;
8179 }
82- startIndex = content . IndexOf ( "#pcc:" , StringComparison . Ordinal ) ;
80+ startIndex = content . IndexOfOrdinal ( "#pcc:" ) ;
8381 if ( startIndex != - 1 ) content = content . Remove ( startIndex ) ;
8482 if ( ! Regex . IsMatch ( content , pattern , RegexOptions . IgnoreCase | RegexOptions . Multiline ) ) continue ;
8583 result . Add ( file , content . Replace ( "\r \n " , "\n " ) ) ;
@@ -125,7 +123,7 @@ internal static KeyValuePair<string, string> GetVarNameToQualifiedName(ASResult
125123 internal static string ProcessMemberTemplate ( string template , ASResult expr )
126124 {
127125 var varNameToQualifiedName = GetVarNameToQualifiedName ( expr ) ;
128- var name = varNameToQualifiedName . Key . ToLower ( ) ;
126+ var name = varNameToQualifiedName . Key ; // .ToLower();
129127 var type = varNameToQualifiedName . Value ;
130128 template = ASCompletion . Completion . TemplateUtils . ReplaceTemplateVariable ( template , "Name" , name ) ;
131129 if ( ASContext . Context is Context && Settings != null && Settings . DisableTypeDeclaration ) type = null ;
@@ -145,10 +143,10 @@ internal static string ProcessCollectionTemplate(string template, ASResult expr)
145143 case "as2" :
146144 case "as3" :
147145 if ( string . IsNullOrEmpty ( type ) ) type = ASContext . Context . Features . dynamicKey ;
148- template = template . Replace ( PATTERN_COLLECTION_KEY_TYPE , "int" ) ;
146+ template = template . Replace ( PatternCollectionKeyType , "int" ) ;
149147 break ;
150148 }
151- return template . Replace ( PATTERN_COLLECTION_ITEM_TYPE , type ) ;
149+ return template . Replace ( PatternCollectionItemType , type ) ;
152150 }
153151
154152 internal static string ProcessHashTemplate ( string template , ASResult expr )
@@ -163,8 +161,8 @@ internal static string ProcessHashTemplate(string template, ASResult expr)
163161 var objectKey = features . objectKey ;
164162 if ( type == objectKey || type == "Dictionary" )
165163 {
166- template = template . Replace ( PATTERN_COLLECTION_KEY_TYPE , type == objectKey ? features . stringKey : objectKey ) ;
167- template = template . Replace ( PATTERN_COLLECTION_ITEM_TYPE , features . dynamicKey ) ;
164+ template = template . Replace ( PatternCollectionKeyType , type == objectKey ? features . stringKey : objectKey ) ;
165+ template = template . Replace ( PatternCollectionItemType , features . dynamicKey ) ;
168166 }
169167 break ;
170168 }
@@ -180,7 +178,7 @@ internal static string GetDescription(ASResult expr, string template, string pcc
180178 var line = sci . GetLine ( lineNum ) ;
181179 var snippet = line . Substring ( exprStartPosition - sci . PositionFromLine ( lineNum ) , position - exprStartPosition ) ;
182180 var result = template . Replace ( SnippetHelper . BOUNDARY , string . Empty ) ;
183- result = Regex . Replace ( result , string . Format ( PATTERN_BLOCK , pccpattern ) , snippet , RegexOptions . IgnoreCase | RegexOptions . Multiline ) ;
181+ result = Regex . Replace ( result , string . Format ( PatternBlock , pccpattern ) , snippet , RegexOptions . IgnoreCase | RegexOptions . Multiline ) ;
184182 result = ProcessMemberTemplate ( result , expr ) ;
185183 result = ArgsProcessor . ProcessCodeStyleLineBreaks ( result ) ;
186184 result = result . Replace ( SnippetHelper . ENTRYPOINT , "|" ) ;
@@ -196,7 +194,7 @@ internal static void InsertSnippetText(ASResult expr, string template, string pc
196194 sci . ReplaceSel ( string . Empty ) ;
197195 position = ScintillaControlHelper . GetExpressionStartPosition ( sci , sci . CurrentPos , expr ) ;
198196 sci . SetSel ( position , sci . CurrentPos ) ;
199- var snippet = Regex . Replace ( template , string . Format ( PATTERN_BLOCK , pccpattern ) , sci . SelText , RegexOptions . IgnoreCase | RegexOptions . Multiline ) ;
197+ var snippet = Regex . Replace ( template , string . Format ( PatternBlock , pccpattern ) , sci . SelText , RegexOptions . IgnoreCase | RegexOptions . Multiline ) ;
200198 snippet = ProcessMemberTemplate ( snippet , expr ) ;
201199 snippet = ArgsProcessor . ProcessCodeStyleLineBreaks ( snippet ) ;
202200 sci . ReplaceSel ( string . Empty ) ;
0 commit comments