@ -90,7 +90,6 @@ namespace Grunwald.BooBinding.CodeCompletion
inText = SimplifyCode ( inText , offset ) ;
inText = SimplifyCode ( inText , offset ) ;
if ( inText = = null ) {
if ( inText = = null ) {
LoggingService . Debug ( "SimplifyCode returned null (cursor is in comment/string???)" ) ;
return new ExpressionResult ( null ) ;
return new ExpressionResult ( null ) ;
}
}
// inText now has no comments or string literals, but the same meaning in
// inText now has no comments or string literals, but the same meaning in
@ -162,34 +161,35 @@ namespace Grunwald.BooBinding.CodeCompletion
// state = -1 : accepting current identifier
// state = -1 : accepting current identifier
// state >= 0 : accepting brackets/parenthesis
// state >= 0 : accepting brackets/parenthesis
Stack < int > bracketStack = new Stack < int > ( ) ;
Stack < int > bracketStack = new Stack < int > ( ) ;
for ( int i = offset + 1 ; i < inText . Length ; i + + ) {
int i ;
for ( i = offset + 1 ; i < inText . Length ; i + + ) {
char c = inText [ i ] ;
char c = inText [ i ] ;
if ( state = = - 1 ) {
if ( char . IsLetterOrDigit ( c ) | | c = = '_' ) {
if ( char . IsLetterOrDigit ( c ) | | c = = '_' ) {
// continue reading identifier
// continue reading identifier
} else {
} else {
state = 0 ;
state = 0 ;
break ;
}
}
}
if ( state > = 0 ) {
}
state = FeedStateMachine ( state , c ) ;
i - = 1 ;
if ( IsInNormalCode ( state ) ) {
while ( state > = 0 ) {
int bracket = _ openingBrackets . IndexOf ( c ) ;
state = FindNextCodeCharacter ( state , inText , ref i ) ;
if ( bracket > = 0 ) {
if ( state < 0 ) break ;
bracketStack . Push ( bracket ) ;
char c = inText [ i ] ;
} else {
int bracket = _ openingBrackets . IndexOf ( c ) ;
if ( bracketStack . Count = = 0 ) {
if ( bracket > = 0 ) {
result . Expression = b . ToString ( ) ;
bracketStack . Push ( bracket ) ;
return result ;
} else {
}
if ( bracketStack . Count = = 0 ) {
}
b . Append ( inText , offset + 1 , i - offset - 1 ) ;
bracket = _ closingBrackets . IndexOf ( c ) ;
result . Expression = b . ToString ( ) ;
if ( bracket > = 0 ) {
return result ;
while ( bracketStack . Count > 0 & & bracketStack . Pop ( ) > bracket ) ;
}
}
}
}
}
b . Append ( c ) ;
bracket = _ closingBrackets . IndexOf ( c ) ;
if ( bracket > = 0 ) {
while ( bracketStack . Count > 0 & & bracketStack . Pop ( ) > bracket ) ;
}
}
}
return new ExpressionResult ( null ) ;
return new ExpressionResult ( null ) ;
}
}
@ -276,6 +276,34 @@ namespace Grunwald.BooBinding.CodeCompletion
return action ;
return action ;
}
}
/// <summary>
/// Goes to the next position in "text" that is code (not comment, string etc.).
/// Returns a state that has be passed in as <paramref name="state"/> on the
/// next call.
/// </summary>
public int FindNextCodeCharacter ( int state , string text , ref int pos )
{
ResetStateMachine ( ) ;
do {
pos + = 1 ;
if ( pos > = text . Length )
return - 1 ;
char c = text [ pos ] ;
state = FeedStateMachine ( state , c ) ;
if ( state = = 1 2 ) {
// after / could be a regular expression, do a special check for that
int regexEnd = SkipRegularExpression ( text , pos , text . Length - 1 ) ;
if ( regexEnd > 0 ) {
pos = regexEnd ;
} else if ( regexEnd = = - 1 ) {
// cursor is in regex
return - 1 ;
} // else: regexEnd is 0 if its not a regex
}
} while ( ! IsInNormalCode ( state ) ) ;
return state ;
}
/// <summary>This method makes boo source code "simpler" by removing all comments
/// <summary>This method makes boo source code "simpler" by removing all comments
/// and replacing all string litarals through string.Empty.
/// and replacing all string litarals through string.Empty.
/// Regular expressions literals are replaced with the simple regex /a/</summary>
/// Regular expressions literals are replaced with the simple regex /a/</summary>
@ -311,7 +339,7 @@ namespace Grunwald.BooBinding.CodeCompletion
}
}
}
}
if ( state = = 2 | | ( state > = 6 & & state < = 1 1 ) )
if ( state = = 2 | | ( state > = 6 & & state < = 1 1 ) )
result . Append ( "string.Empty " ) ;
result . Append ( "'' " ) ;
if ( IsInNormalCode ( state ) )
if ( IsInNormalCode ( state ) )
result . Append ( c ) ;
result . Append ( c ) ;
state = action ;
state = action ;