Browse Source

Fixed code completion bug.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
3b682d43b1
  1. 81
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  2. 30
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

81
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -225,48 +225,80 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
{ {
var bracketStack = new Stack<Tuple<char, int>> (); var bracketStack = new Stack<Tuple<char, int>> ();
bool isInString = false, isInChar = false; bool inSingleComment = false, inString = false, inVerbatimString = false, inChar = false, inMultiLineComment = false;
bool isInLineComment = false, isInBlockComment = false;
for (int pos = 0; pos < memberText.Length; pos++) { for (int i = 0; i < memberText.Length; i++) {
char ch = memberText [pos]; char ch = memberText [i];
char nextCh = i + 1 < memberText.Length ? memberText [i + 1] : '\0';
switch (ch) { switch (ch) {
case '(': case '(':
case '[': case '[':
case '{': case '{':
if (!isInString && !isInChar && !isInLineComment && !isInBlockComment) if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
bracketStack.Push (Tuple.Create (ch, pos)); break;
bracketStack.Push (Tuple.Create (ch, i));
break; break;
case ')': case ')':
case ']': case ']':
case '}': case '}':
if (!isInString && !isInChar && !isInLineComment && !isInBlockComment) if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
break;
if (bracketStack.Count > 0) if (bracketStack.Count > 0)
bracketStack.Pop (); bracketStack.Pop ();
break; break;
case '\r':
case '\n':
isInLineComment = false;
break;
case '/': case '/':
if (isInBlockComment) { if (inString || inChar || inVerbatimString)
if (pos > 0 && memberText [pos - 1] == '*') break;
isInBlockComment = false; if (nextCh == '/') {
} else if (!isInString && !isInChar && pos + 1 < memberText.Length) { i++;
char nextChar = memberText [pos + 1]; inSingleComment = true;
if (nextChar == '/') }
isInLineComment = true; if (nextCh == '*')
if (!isInLineComment && nextChar == '*') inMultiLineComment = true;
isInBlockComment = true; break;
case '*':
if (inString || inChar || inVerbatimString || inSingleComment)
break;
if (nextCh == '/') {
i++;
inMultiLineComment = false;
} }
break; break;
case '@':
if (inString || inChar || inVerbatimString || inSingleComment || inMultiLineComment)
break;
if (nextCh == '"') {
i++;
inVerbatimString = true;
}
break;
case '\n':
case '\r':
inSingleComment = false;
inString = false;
inChar = false;
break;
case '\\':
if (inString || inChar)
i++;
break;
case '"': case '"':
if (!(isInChar || isInLineComment || isInBlockComment)) if (inSingleComment || inMultiLineComment || inChar)
isInString = !isInString; break;
if (inVerbatimString) {
if (nextCh == '"') {
i++;
break;
}
inVerbatimString = false;
break;
}
inString = !inString;
break; break;
case '\'': case '\'':
if (!(isInString || isInLineComment || isInBlockComment)) if (inSingleComment || inMultiLineComment || inString || inVerbatimString)
isInChar = !isInChar; break;
inChar = !inChar;
break; break;
default : default :
break; break;
@ -369,6 +401,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
} else { } else {
memberLocation = new TextLocation (1, 1); memberLocation = new TextLocation (1, 1);
} }
using (var stream = new System.IO.StringReader (wrapper.ToString ())) { using (var stream = new System.IO.StringReader (wrapper.ToString ())) {
try { try {
var parser = new CSharpParser (); var parser = new CSharpParser ();

30
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -1961,6 +1961,36 @@ class Test
Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found"); Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found");
} }
/// <summary>
/// Bug 3438 - [New Resolver] Local var missing in code completion
/// </summary>
[Test()]
public void Test3438 ()
{
CombinedProviderTest (
@"
using System;
using System.Text;
class C
{
void GetElementXml (int indent)
{
StringBuilder sb = new StringBuilder ();
if (indent == 0)
sb.Append ("" xmlns:android=\""http://schemas.android.com/apk/res/android\"""");
if (indent != 0) {
string data;
$d$
}
}
}", provider => {
Assert.IsNotNull (provider.Find ("data"), "'data' not found.");
});
}
/// <summary> /// <summary>
/// Bug 474199 - Code completion not working for a nested class /// Bug 474199 - Code completion not working for a nested class
/// </summary> /// </summary>

Loading…
Cancel
Save