@@ -184,7 +184,8 @@ static public bool OnChar(ScintillaControl Sci, int Value, bool autoHide)
184
184
if ( features . hasGenerics && position > 2 )
185
185
{
186
186
char c0 = ( char ) Sci . CharAt ( position - 2 ) ;
187
- if ( c0 == '.' /*|| Char.IsLetterOrDigit(c0)*/ )
187
+ //TODO: We should check if we are actually on a generic type
188
+ if ( ( ASContext . Context . CurrentModel . Version == 3 && c0 == '.' ) || Char . IsLetterOrDigit ( c0 ) )
188
189
return HandleColonCompletion ( Sci , "" , autoHide ) ;
189
190
return false ;
190
191
}
@@ -2206,6 +2207,7 @@ static private bool HandleColonCompletion(ScintillaControl Sci, string tail, boo
2206
2207
2207
2208
private static ComaExpression GetFunctionContext ( ScintillaControl Sci , bool autoHide )
2208
2209
{
2210
+ ContextFeatures features = ASContext . Context . Features ;
2209
2211
ComaExpression coma = ComaExpression . None ;
2210
2212
int position = Sci . CurrentPos - 1 ;
2211
2213
char c = ' ' ;
@@ -2222,7 +2224,7 @@ private static ComaExpression GetFunctionContext(ScintillaControl Sci, bool auto
2222
2224
// var declaration
2223
2225
GetWordLeft ( Sci , ref position ) ;
2224
2226
string keyword = ( c == ':' ) ? GetWordLeft ( Sci , ref position ) : null ;
2225
- if ( keyword == ASContext . Context . Features . varKey || keyword == ASContext . Context . Features . constKey )
2227
+ if ( keyword == features . varKey || ( features . constKey != null && keyword == features . constKey ) )
2226
2228
coma = ComaExpression . VarDeclaration ;
2227
2229
// function return type
2228
2230
else if ( ( char ) Sci . CharAt ( position ) == ')' )
@@ -2244,7 +2246,6 @@ private static ComaExpression GetFunctionContext(ScintillaControl Sci, bool auto
2244
2246
}
2245
2247
}
2246
2248
keyword = GetWordLeft ( Sci , ref position ) ;
2247
- ContextFeatures features = ASContext . Context . Features ;
2248
2249
if ( keyword == "" && Sci . CharAt ( position ) == '>' && features . hasGenerics )
2249
2250
{
2250
2251
int groupCount = 1 ;
@@ -2267,6 +2268,9 @@ private static ComaExpression GetFunctionContext(ScintillaControl Sci, bool auto
2267
2268
keyword = GetWordLeft ( Sci , ref position ) ;
2268
2269
if ( keyword == features . functionKey || keyword == features . getKey || keyword == features . setKey )
2269
2270
coma = ComaExpression . FunctionDeclaration ;
2271
+ else if ( ASContext . Context . CurrentModel . haXe && keyword == features . varKey &&
2272
+ ( ASContext . Context . CurrentMember == null || ( ASContext . Context . CurrentMember . Flags & FlagType . Function ) == 0 ) )
2273
+ coma = ComaExpression . VarDeclaration ; // Haxe Properties
2270
2274
}
2271
2275
}
2272
2276
// needs more guessing
@@ -3484,7 +3488,7 @@ static private ASExpr GetExpression(ScintillaControl Sci, int position, bool ign
3484
3488
/// Find out in what context is a coma-separated expression
3485
3489
/// </summary>
3486
3490
/// <returns></returns>
3487
- private static ComaExpression DisambiguateComa ( ScintillaControl Sci , int position , int minPos )
3491
+ internal static ComaExpression DisambiguateComa ( ScintillaControl Sci , int position , int minPos )
3488
3492
{
3489
3493
ContextFeatures features = ASContext . Context . Features ;
3490
3494
// find block start '(' or '{'
@@ -3531,6 +3535,7 @@ private static ComaExpression DisambiguateComa(ScintillaControl Sci, int positio
3531
3535
string word1 = GetWordLeft ( Sci , ref position ) ;
3532
3536
if ( word1 == "" && Sci . CharAt ( position ) == '>' && features . hasGenerics )
3533
3537
{
3538
+ // Generic function: function generic<K>(arg:K)
3534
3539
int groupCount = 1 ;
3535
3540
position -- ;
3536
3541
while ( position >= 0 && groupCount > 0 )
@@ -3569,7 +3574,17 @@ private static ComaExpression DisambiguateComa(ScintillaControl Sci, int positio
3569
3574
if ( ":,(=" . IndexOf ( c ) >= 0 )
3570
3575
{
3571
3576
string line = Sci . GetLine ( Sci . LineFromPosition ( position ) ) ;
3577
+ //TODO: Very limited check, the case|default could be in a previous line, or it could be something else in the same line
3572
3578
if ( Regex . IsMatch ( line , @"\b(case|default)\b.*:" ) ) break ; // case: code block
3579
+ if ( c == ':' && Sci . ConfigurationLanguage == "haxe" )
3580
+ {
3581
+ // Anonymous structures
3582
+ ComaExpression coma = DisambiguateComa ( Sci , position , minPos ) ;
3583
+ if ( coma == ComaExpression . FunctionDeclaration || coma == ComaExpression . VarDeclaration )
3584
+ {
3585
+ return ComaExpression . VarDeclaration ;
3586
+ }
3587
+ }
3573
3588
return ComaExpression . AnonymousObjectParam ;
3574
3589
}
3575
3590
else if ( c != ')' && c != '}' && ! Char . IsLetterOrDigit ( c ) ) return ComaExpression . AnonymousObject ;
@@ -3580,7 +3595,28 @@ private static ComaExpression DisambiguateComa(ScintillaControl Sci, int positio
3580
3595
{
3581
3596
braceCount ++ ;
3582
3597
}
3583
- else if ( c == '?' ) return ComaExpression . AnonymousObject ;
3598
+ else if ( c == '?' )
3599
+ {
3600
+ //TODO: Change to ASContext.Context.CurrentModel
3601
+ if ( Sci . ConfigurationLanguage == "haxe" ) // Haxe optional fields
3602
+ {
3603
+ ComaExpression coma = DisambiguateComa ( Sci , position - 1 , minPos ) ;
3604
+ if ( coma == ComaExpression . FunctionDeclaration )
3605
+ {
3606
+ // Function optional argument
3607
+ return coma ;
3608
+ }
3609
+ else if ( coma == ComaExpression . VarDeclaration )
3610
+ {
3611
+ // Possible anonymous structure optional field. Check we are not in a ternary operator
3612
+ position -- ;
3613
+ string word1 = GetWordLeft ( Sci , ref position ) ;
3614
+ c = ( word1 . Length > 0 ) ? word1 [ word1 . Length - 1 ] : ( char ) Sci . CharAt ( position ) ;
3615
+ if ( c == ',' || c == '{' ) return coma ;
3616
+ }
3617
+ }
3618
+ return ComaExpression . AnonymousObject ;
3619
+ }
3584
3620
position -- ;
3585
3621
}
3586
3622
return ComaExpression . None ;
0 commit comments