diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-11-02 11:07:30 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-11-02 11:07:30 +0400 |
commit | adae1785619acf32950b044de9be1149630d636d (patch) | |
tree | b7c5136aa4a703cfd0b607450b3bb5a3a9c1bedf /main/contrib | |
parent | e479909eaf11e503514b311554a17abdc257d854 (diff) |
Fixed "Bug 1767 - [New Resolver] Weird tooltip window quickly showing
and hiding when typing comments ".
Diffstat (limited to 'main/contrib')
3 files changed, 88 insertions, 16 deletions
diff --git a/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs b/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs index 043d645028..d660f097d8 100644 --- a/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs +++ b/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs @@ -150,7 +150,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion // Magic key completion
case ':':
case '.':
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return Enumerable.Empty<ICompletionData> ();
var expr = GetExpressionBeforeCursor ();
if (expr == null)
@@ -172,7 +172,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return CreateCompletionData (location, resolveResult.Item1, expr.Item2, resolveResult.Item2);
case '#':
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return null;
return GetDirectiveCompletionData ();
@@ -210,7 +210,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion // Parameter completion
case '(':
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return null;
var invoke = GetInvocationBeforeCursor (true);
if (invoke == null)
@@ -237,7 +237,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion // Completion on space:
case ' ':
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return null;
int tokenIndex = offset;
@@ -395,7 +395,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return keywordCompletion;
// Automatic completion
default:
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return null;
if (IsInLinqContext (offset)) {
tokenIndex = offset;
@@ -741,7 +741,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion IEnumerable<ICompletionData> HandleKeywordCompletion (int wordStart, string word)
{
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return null;
switch (word) {
case "using":
diff --git a/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs b/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs index 25a8d69b72..9f3fe60da3 100644 --- a/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs +++ b/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs @@ -57,6 +57,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion protected void SetOffset (int offset)
{
+ Reset ();
+
this.offset = offset;
this.location = document.GetLocation (offset);
@@ -65,9 +67,74 @@ namespace ICSharpCode.NRefactory.CSharp.Completion }
#region Context helper methods
- protected bool IsInsideComment ()
+ protected bool IsInsideCommentOrString ()
{
- return IsInsideComment (offset);
+ var text = GetMemberTextToCaret ();
+ bool inSingleComment = false, inString = false, inVerbatimString = false, inChar = false, inMultiLineComment = false;
+
+ for (int i = 0; i < text.Item1.Length - 1; i++) {
+ char ch = text.Item1[i];
+ char nextCh = text.Item1[i + 1];
+
+ switch (ch) {
+ case '/':
+ if (inString || inChar || inVerbatimString)
+ break;
+ if (nextCh == '/') {
+ i++;
+ inSingleComment = true;
+ }
+ if (nextCh == '*')
+ inMultiLineComment = true;
+ break;
+ case '*':
+ if (inString || inChar || inVerbatimString || inSingleComment)
+ break;
+ if (nextCh == '/') {
+ i++;
+ inMultiLineComment = false;
+ }
+ 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 '"':
+ if (inSingleComment || inMultiLineComment || inChar)
+ break;
+ if (inVerbatimString) {
+ if (nextCh == '"') {
+ i++;
+ break;
+ }
+ inVerbatimString = false;
+ break;
+ }
+ inString = !inString;
+ break;
+ case '\'':
+ if (inSingleComment || inMultiLineComment || inString || inVerbatimString)
+ break;
+ inChar = !inChar;
+ break;
+ }
+ }
+
+ return inSingleComment || inString || inVerbatimString || inChar || inMultiLineComment;
}
protected bool IsInsideComment (int offset)
@@ -83,11 +150,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion return cmt != null && cmt.CommentType == CommentType.Documentation;
}
- protected bool IsInsideString ()
- {
- return IsInsideString (offset);
- }
-
protected bool IsInsideString (int offset)
{
@@ -240,6 +302,13 @@ namespace ICSharpCode.NRefactory.CSharp.Completion }
}
+ string cachedText = null;
+
+ protected virtual void Reset ()
+ {
+ cachedText = null;
+ }
+
protected Tuple<string, bool> GetMemberTextToCaret ()
{
int startOffset;
@@ -250,9 +319,12 @@ namespace ICSharpCode.NRefactory.CSharp.Completion } else {
startOffset = 0;
}
- return Tuple.Create (document.GetText (startOffset, offset - startOffset), startOffset != 0);
+ if (cachedText == null)
+ cachedText = document.GetText (startOffset, offset - startOffset);
+
+ return Tuple.Create (cachedText, startOffset != 0);
}
-
+
protected Tuple<CSharpParsedFile, AstNode, CompilationUnit> GetInvocationBeforeCursor (bool afterBracket)
{
CompilationUnit baseUnit;
diff --git a/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs b/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs index f0b2e913b7..c946dba60b 100644 --- a/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs +++ b/main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs @@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion char completionChar = document.GetCharAt (offset - 1);
if (completionChar != '(' && completionChar != '<' && completionChar != '[')
return null;
- if (IsInsideComment () || IsInsideString ())
+ if (IsInsideCommentOrString ())
return null;
var invoke = GetInvocationBeforeCursor (true) ?? GetIndexerBeforeCursor ();
|