diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs index d47ebefff7..d1e189648a 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs @@ -107,13 +107,14 @@ namespace CSharpBinding if (textSource == null) return; if (searchScope.SearchTerm != null) { - // TODO: do a fast check with IndexOf() + if (textSource.IndexOf(searchScope.SearchTerm, 0, textSource.TextLength, StringComparison.Ordinal) < 0) + return; } ParseInformation parseInfo = ParserService.Parse(fileName, textSource); if (parseInfo == null) return; - ParsedFile parsedFile = parseInfo.ParsedFile as ParsedFile; + CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile; CompilationUnit cu = parseInfo.Annotation(); if (parsedFile == null || cu == null) return; diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs index 0f8b5b9ae0..6fe3b485f1 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs @@ -80,7 +80,7 @@ namespace CSharpBinding.Parser } TypeSystemConvertVisitor cv = new TypeSystemConvertVisitor(projectContent, fileName); - ParsedFile file = cv.Convert(cu); + CSharpParsedFile file = cv.Convert(cu); ParseInformation info = new ParseInformation(file, fullParseInformationRequested); if (fullParseInformationRequested) @@ -103,7 +103,7 @@ namespace CSharpBinding.Parser CompilationUnit cu = parseInfo.Annotation(); if (cu == null) throw new ArgumentException("Parse info does not have CompilationUnit"); - ParsedFile parsedFile = parseInfo.ParsedFile as ParsedFile; + CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile; if (parsedFile == null) throw new ArgumentException("Parse info does not have a C# ParsedFile"); diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/RopeTextSource.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/RopeTextSource.cs index 3e96099c05..0ec6bbe9ef 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/RopeTextSource.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/RopeTextSource.cs @@ -110,5 +110,15 @@ namespace ICSharpCode.AvalonEdit.Document { return rope.ToString(segment.Offset, segment.Length); } + + public int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType) + { + return rope.IndexOf(searchText, startIndex, count, comparisonType); + } + + public int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType) + { + return rope.LastIndexOf(searchText, startIndex, count, comparisonType); + } } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs index 8388a69a25..fc28bc0474 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs @@ -156,12 +156,27 @@ namespace ICSharpCode.AvalonEdit.Document return GetText(segment.Offset, segment.Length); } - int ITextSource.IndexOfAny(char[] anyOf, int startIndex, int count) + /// + public int IndexOfAny(char[] anyOf, int startIndex, int count) { DebugVerifyAccess(); // frequently called (NewLineFinder), so must be fast in release builds return rope.IndexOfAny(anyOf, startIndex, count); } + /// + public int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType) + { + DebugVerifyAccess(); + return rope.IndexOf(searchText, startIndex, count, comparisonType); + } + + /// + public int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType) + { + DebugVerifyAccess(); + return rope.LastIndexOf(searchText, startIndex, count, comparisonType); + } + /// public char GetCharAt(int offset) { diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/CharRope.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/CharRope.cs index 2903cb680b..10b9251ad7 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/CharRope.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/CharRope.cs @@ -168,5 +168,39 @@ namespace ICSharpCode.AvalonEdit.Utils } return -1; } + + /// + /// Gets the index of the first occurrence of the search text. + /// + public static int IndexOf(this Rope rope, string searchText, int startIndex, int length, StringComparison comparisonType) + { + if (rope == null) + throw new ArgumentNullException("rope"); + if (searchText == null) + throw new ArgumentNullException("searchText"); + rope.VerifyRange(startIndex, length); + int pos = rope.ToString(startIndex, length).IndexOf(searchText, startIndex, length, comparisonType); + if (pos < 0) + return -1; + else + return pos + startIndex; + } + + /// + /// Gets the index of the last occurrence of the search text. + /// + public static int LastIndexOf(this Rope rope, string searchText, int startIndex, int length, StringComparison comparisonType) + { + if (rope == null) + throw new ArgumentNullException("rope"); + if (searchText == null) + throw new ArgumentNullException("searchText"); + rope.VerifyRange(startIndex, length); + int pos = rope.ToString(startIndex, length).LastIndexOf(searchText, startIndex, length, comparisonType); + if (pos < 0) + return -1; + else + return pos + startIndex; + } } }