Browse Source

fix bug in TagComment parsing logic: Mono's C# parser creates comment tokens with wrong line endings in the comment text

pull/80/head
Siegfried Pammer 12 years ago
parent
commit
fa03bcdc10
  1. 20
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  2. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/CharRope.cs
  3. 18
      src/Main/Base/Project/Util/SharpDevelopExtensions.cs

20
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -109,27 +109,29 @@ namespace CSharpBinding.Parser @@ -109,27 +109,29 @@ namespace CSharpBinding.Parser
foreach (var comment in cu.Descendants.OfType<Comment>()) {
if (comment.CommentType == CommentType.InactiveCode)
continue;
int matchLength;
int index = comment.Content.IndexOfAny(TaskListTokens, 0, out matchLength);
if (index > -1) {
string match;
if (comment.Content.ContainsAny(TaskListTokens, 0, out match)) {
if (document == null)
document = new ReadOnlyDocument(fileContent, fileName);
int commentSignLength = comment.CommentType == CommentType.Documentation || comment.CommentType == CommentType.MultiLineDocumentation ? 3 : 2;
int commentEndSignLength = comment.CommentType == CommentType.MultiLine || comment.CommentType == CommentType.MultiLineDocumentation ? 2 : 0;
int commentStartOffset = document.GetOffset(comment.StartLocation) + commentSignLength;
int commentEndOffset = document.GetOffset(comment.EndLocation) - commentEndSignLength;
int endOffset;
int searchOffset = 0;
do {
int absoluteOffset = commentStartOffset + index;
int start = commentStartOffset + searchOffset;
int absoluteOffset = document.IndexOf(match, start, document.TextLength - start, StringComparison.Ordinal);
var startLocation = document.GetLocation(absoluteOffset);
int endOffset = Math.Min(document.GetLineByNumber(startLocation.Line).EndOffset, commentEndOffset);
endOffset = Math.Min(document.GetLineByNumber(startLocation.Line).EndOffset, commentEndOffset);
string content = document.GetText(absoluteOffset, endOffset - absoluteOffset);
if (content.Length < matchLength) {
if (content.Length < match.Length) {
// HACK: workaround parser bug with multi-line documentation comments
break;
}
tagComments.Add(new TagComment(content.Substring(0, matchLength), new DomRegion(cu.FileName, startLocation.Line, startLocation.Column), content.Substring(matchLength)));
index = comment.Content.IndexOfAny(TaskListTokens, endOffset - commentStartOffset, out matchLength);
} while (index > -1);
tagComments.Add(new TagComment(content.Substring(0, match.Length), new DomRegion(cu.FileName, startLocation.Line, startLocation.Column), content.Substring(match.Length)));
searchOffset = endOffset - commentStartOffset;
} while (comment.Content.ContainsAny(TaskListTokens, searchOffset, out match));
}
}
}

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/CharRope.cs

@ -35,6 +35,10 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -35,6 +35,10 @@ namespace ICSharpCode.AvalonEdit.Utils
{
if (rope == null)
throw new ArgumentNullException("rope");
#if DEBUG
if (length < 0)
throw new ArgumentOutOfRangeException("length", length, "Value must be >= 0");
#endif
if (length == 0)
return string.Empty;
char[] buffer = new char[length];

18
src/Main/Base/Project/Util/SharpDevelopExtensions.cs

@ -766,6 +766,24 @@ namespace ICSharpCode.SharpDevelop @@ -766,6 +766,24 @@ namespace ICSharpCode.SharpDevelop
return index;
}
public static bool ContainsAny(this string haystack, IEnumerable<string> needles, int startIndex, out string match)
{
if (haystack == null)
throw new ArgumentNullException("haystack");
if (needles == null)
throw new ArgumentNullException("needles");
int index = -1;
match = null;
foreach (var needle in needles) {
int i = haystack.IndexOf(needle, startIndex, StringComparison.Ordinal);
if (i != -1 && (index == -1 || index > i)) {
index = i;
match = needle;
}
}
return index > -1;
}
/// <summary>
/// Retrieves a hash code for the specified string that is stable across
/// multiple runs of SharpDevelop and .NET upgrades.

Loading…
Cancel
Save