Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: icsharpcode/NRefactory
base: 03407fd
...
head fork: icsharpcode/NRefactory
compare: fa5e7e5
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 26, 2011
@mkrueger mkrueger Fixed completion inside try ... catch bodies. c498bc8
@mkrueger mkrueger Fixed potential resolve issue.
Note: That doesn't really fix the problem - only 90% of the cases. The
partial class representation could need a change.
fa5e7e5
View
4 ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
@@ -1217,7 +1217,9 @@ public ITypeDefinition GetTypeFromContext (ITypeDefinition type)
{
if (type == null || type.DeclaringType != null)
return type;
- var result = ctx.GetTypeDefinition (type.Namespace, type.Name, type.TypeParameterCount, StringComparer.Ordinal);
+ var result = ctx.GetTypeDefinition (type.Namespace, type.Name, type.TypeParameterCount, StringComparer.Ordinal) ?? type;
+ if (result.GetParts ().Count == 1)
+ return type;
// Console.WriteLine ("result:"+ result);
return result;
}
View
26 ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
@@ -90,6 +90,7 @@ protected bool IsInsideString ()
protected bool IsInsideString (int offset)
{
+
var loc = document.GetLocation (offset);
var expr = Unit.GetNodeAt<PrimitiveExpression> (loc.Line, loc.Column);
return expr != null && expr.Value is string;
@@ -99,7 +100,7 @@ protected bool IsInsideString (int offset)
#region Basic parsing/resolving functions
protected void AppendMissingClosingBrackets (StringBuilder wrapper, string memberText, bool appendSemicolon)
{
- var bracketStack = new Stack<char> ();
+ var bracketStack = new Stack<Tuple<char, int>> ();
bool isInString = false, isInChar = false;
bool isInLineComment = false, isInBlockComment = false;
@@ -111,7 +112,7 @@ protected void AppendMissingClosingBrackets (StringBuilder wrapper, string membe
case '[':
case '{':
if (!isInString && !isInChar && !isInLineComment && !isInBlockComment)
- bracketStack.Push (ch);
+ bracketStack.Push (Tuple.Create (ch, pos));
break;
case ')':
case ']':
@@ -152,7 +153,8 @@ protected void AppendMissingClosingBrackets (StringBuilder wrapper, string membe
char lastBracket = '\0';
while (bracketStack.Count > 0) {
- switch (bracketStack.Pop ()) {
+ var t = bracketStack.Pop ();
+ switch (t.Item1) {
case '(':
wrapper.Append (')');
didAppendSemicolon = false;
@@ -169,12 +171,28 @@ protected void AppendMissingClosingBrackets (StringBuilder wrapper, string membe
lastBracket = '>';
break;
case '{':
+ int o = t.Item2 - 1;
if (!didAppendSemicolon) {
didAppendSemicolon = true;
wrapper.Append (';');
}
- wrapper.Append ('}');
+ bool didAppendCatch = false;
+ while (o >= "try".Length) {
+ char ch = memberText[o];
+ Console.WriteLine (ch);
+
+ if (!char.IsWhiteSpace (ch)) {
+ if (ch == 'y' && memberText[o - 1] == 'r' && memberText[o - 2] == 't') {
+ wrapper.Append ("} catch {}");
+ didAppendCatch = true;
+ }
+ break;
+ }
+ o--;
+ }
+ if (!didAppendCatch)
+ wrapper.Append ('}');
break;
}
}
View
20 ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
@@ -3577,5 +3577,25 @@ public static void Main (string[] args)
Assert.IsNotNull (provider.Find ("B"), "class 'B' not found.");
Assert.IsNotNull (provider.Find ("C"), "class 'C' not found.");
}
+
+ [Test()]
+ public void TestCompletionInTryCatch ()
+ {
+ CompletionDataList provider = CreateProvider (
+@"class Test { public void TM1 () {} public void TM2 () {} public int TF1; }
+class CCTest {
+void TestMethod ()
+{
+ Test t;
+ try {
+ $t.$
+}
+}
+");
+ Assert.IsNotNull (provider);
+ Assert.IsNotNull (provider.Find ("TM1"));
+ Assert.IsNotNull (provider.Find ("TM2"));
+ Assert.IsNotNull (provider.Find ("TF1"));
+ }
}
}

No commit comments for this range

Something went wrong with that request. Please try again.