Browse Source

Fixed IsInsideDocComment method.

TODO: Move the detection of comments & string regions to the
IMemberProvider (needs rename) and handle that with a tree on IDE
level.
newNRvisualizers
mike 14 years ago
parent
commit
4499d32fda
  1. 4
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 90
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

4
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -468,7 +468,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -468,7 +468,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var prevToken2 = GetPreviousToken (ref prevTokenIndex, false);
if (prevToken2 == "delegate") // after these always follows a name
return null;
if (identifierStart == null && !string.IsNullOrEmpty (token) && !(IsInsideComment (tokenIndex) || IsInsideString (tokenIndex)) && (prevToken2 == ";" || prevToken2 == "{" || prevToken2 == "}")) {
if (identifierStart == null && !string.IsNullOrEmpty (token) && !IsInsideCommentOrString () && (prevToken2 == ";" || prevToken2 == "{" || prevToken2 == "}")) {
char last = token [token.Length - 1];
if (char.IsLetterOrDigit (last) || last == '_' || token == ">") {
return HandleKeywordCompletion (tokenIndex, token);
@ -752,7 +752,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -752,7 +752,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
bool IsInLinqContext (int offset)
{
string token;
while (null != (token = GetPreviousToken (ref offset, true)) && !IsInsideComment (offset) && !IsInsideString (offset)) {
while (null != (token = GetPreviousToken (ref offset, true)) && !IsInsideCommentOrString ()) {
if (token == "from")
return true;
if (token == ";" || token == "{")

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

@ -171,28 +171,82 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -171,28 +171,82 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return inSingleComment || inString || inVerbatimString || inChar || inMultiLineComment;
}
protected bool IsInsideComment (int offset)
{
var loc = document.GetLocation (offset);
return Unit.GetNodeAt<ICSharpCode.NRefactory.CSharp.Comment> (loc.Line, loc.Column) != null;
}
protected bool IsInsideDocComment ()
{
var loc = document.GetLocation (offset);
var cmt = Unit.GetNodeAt<ICSharpCode.NRefactory.CSharp.Comment> (loc.Line, loc.Column - 1);
return cmt != null && cmt.CommentType == CommentType.Documentation;
}
protected bool IsInsideString (int offset)
{
var text = GetMemberTextToCaret ();
bool inSingleComment = false, inString = false, inVerbatimString = false, inChar = false, inMultiLineComment = false;
bool singleLineIsDoc = 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;
singleLineIsDoc = i + 1 < text.Item1.Length && text.Item1 [i + 1] == '/';
if (singleLineIsDoc) {
i++;
}
}
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;
}
}
var loc = document.GetLocation (offset);
var expr = Unit.GetNodeAt<PrimitiveExpression> (loc.Line, loc.Column);
return expr != null && expr.Value is string;
return inSingleComment && singleLineIsDoc;
}
protected CSharpResolver GetState ()
{
return new CSharpResolver (ctx);

Loading…
Cancel
Save