-
Notifications
You must be signed in to change notification settings - Fork 185
Optimisations and Bookmark Trigger on Static Files #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hirogen
merged 21 commits into
Development
from
112-bug-bookmarks-are-not-working-for-highlight-triggers
Apr 11, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
515021c
update BufferedDataGridView
cbce537
removed no longer used functions
c07c688
updated comment
32d426d
chore: update plugin hashes [skip ci]
github-actions[bot] 0b161b8
bookmarks per trigger, with static files
cbd67e1
Merge branch '112-bug-bookmarks-are-not-working-for-highlight-trigger…
a05f28f
binary search? what? who needs that ;D
787a744
powers of 2 strides optimizations
926609e
span and hotpath optimisations
57fb89b
more bookmark painting, manuel / auto display
357f8fd
Merge branch 'Development' into 112-bug-bookmarks-are-not-working-for…
Hirogen 739305e
chore: update plugin hashes [skip ci]
github-actions[bot] 5cb1d60
bookmarks are now also set when a static file is loaded
e1672e8
Merge branch '112-bug-bookmarks-are-not-working-for-highlight-trigger…
af81f8b
chore: update plugin hashes [skip ci]
github-actions[bot] e675362
resources and optimisations
ecc71c1
Merge branch '112-bug-bookmarks-are-not-working-for-highlight-trigger…
6a5d893
chore: update plugin hashes [skip ci]
github-actions[bot] 47b67f9
optimisations
481048e
Merge branch '112-bug-bookmarks-are-not-working-for-highlight-trigger…
f45fa97
chore: update plugin hashes [skip ci]
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
src/LogExpert.Core/Classes/Bookmark/HighlightBookmarkScanner.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| using System.Text; | ||
|
|
||
| using ColumnizerLib; | ||
|
|
||
| using LogExpert.Core.Classes.Highlight; | ||
|
|
||
| namespace LogExpert.Core.Classes.Bookmark; | ||
|
|
||
| /// <summary> | ||
| /// Scans all lines of a log file against highlight entries that have <see cref="HighlightEntry.IsSetBookmark"/> set, | ||
| /// producing a list of auto-generated bookmarks. This is a pure computation unit with no UI dependencies. | ||
| /// </summary> | ||
| public static class HighlightBookmarkScanner | ||
| { | ||
| /// <summary> | ||
| /// Scans lines [0..lineCount) for highlight matches and returns bookmarks for matching lines. | ||
| /// </summary> | ||
| /// <param name="lineCount">Total number of lines in the file.</param> | ||
| /// <param name="getLine"> | ||
| /// Delegate that returns the log line at a given index. May return null for unavailable lines. | ||
| /// </param> | ||
| /// <param name="entries"> | ||
| /// The highlight entries to check. Only entries with <see cref="HighlightEntry.IsSetBookmark"/> == true produce | ||
| /// bookmarks. | ||
| /// </param> | ||
| /// <param name="fileName"> | ||
| /// The file name, passed to <see cref="ParamParser"/> for bookmark comment template resolution. | ||
| /// </param> | ||
| /// <param name="progressBarModulo"> | ||
| /// Interval of lines for reporting progress via the <paramref name="progress"/> callback. | ||
| /// </param> | ||
| /// <param name="cancellationToken">Token to support cooperative cancellation.</param> | ||
| /// <param name="progress"> | ||
| /// Optional progress callback receiving the current line index (for progress reporting). | ||
| /// </param> | ||
| /// <returns>List of auto-generated bookmarks for all matched lines.</returns> | ||
| public static List<Entities.Bookmark> Scan (int lineCount, Func<int, ILogLineMemory> getLine, IList<HighlightEntry> entries, string fileName, int progressBarModulo = 1000, IProgress<int> progress = null, CancellationToken cancellationToken = default) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(getLine); | ||
|
|
||
| List<Entities.Bookmark> result = []; | ||
|
|
||
| // Pre-filter: only entries with IsSetBookmark matter | ||
| var bookmarkEntries = entries.Where(e => e.IsSetBookmark).ToList(); | ||
| if (bookmarkEntries.Count == 0) | ||
| { | ||
| return result; | ||
| } | ||
|
|
||
| for (var i = 0; i < lineCount; i++) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| var line = getLine(i); | ||
| if (line == null) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var (setBookmark, bookmarkComment, sourceHighlightText) = GetBookmarkAction(line, bookmarkEntries); | ||
|
|
||
| if (setBookmark) | ||
| { | ||
| var comment = ResolveComment(bookmarkComment, line, i, fileName); | ||
| result.Add(Entities.Bookmark.CreateAutoGenerated(i, comment, sourceHighlightText)); | ||
| } | ||
|
|
||
| if (i % progressBarModulo == 0) | ||
| { | ||
| progress?.Report(i); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks a single line against the bookmark-producing highlight entries. Returns whether a bookmark should be set, | ||
| /// the concatenated comment template, and the source highlight text. | ||
| /// </summary> | ||
| private static (bool SetBookmark, string BookmarkComment, string SourceHighlightText) GetBookmarkAction (ITextValueMemory line, List<HighlightEntry> bookmarkEntries) | ||
| { | ||
| var setBookmark = false; | ||
| var bookmarkCommentBuilder = new StringBuilder(); | ||
| var sourceHighlightText = string.Empty; | ||
|
|
||
| foreach (var entry in bookmarkEntries.Where(entry => CheckHighlightEntryMatch(entry, line))) | ||
| { | ||
| setBookmark = true; | ||
| sourceHighlightText = entry.SearchText; | ||
|
|
||
| if (!string.IsNullOrEmpty(entry.BookmarkComment)) | ||
| { | ||
| _ = bookmarkCommentBuilder.Append(entry.BookmarkComment).Append("\r\n"); | ||
| } | ||
| } | ||
|
|
||
| return (setBookmark, bookmarkCommentBuilder.ToString().TrimEnd('\r', '\n'), sourceHighlightText); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Matches a highlight entry against a line. Replicates the logic from LogWindow.CheckHighlightEntryMatch so the | ||
| /// scanner works identically to the existing tail-mode matching. | ||
| /// </summary> | ||
| private static bool CheckHighlightEntryMatch (HighlightEntry entry, ITextValueMemory column) | ||
| { | ||
| if (entry.IsRegex) | ||
| { | ||
| if (entry.Regex.IsMatch(column.Text.ToString())) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (entry.IsCaseSensitive) | ||
| { | ||
| if (column.Text.Span.Contains(entry.SearchText.AsSpan(), StringComparison.Ordinal)) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (column.Text.Span.Contains(entry.SearchText.AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resolves the bookmark comment template using ParamParser, matching SetBookmarkFromTrigger behavior. | ||
| /// </summary> | ||
| private static string ResolveComment (string commentTemplate, ILogLineMemory line, int lineNum, string fileName) | ||
| { | ||
| if (string.IsNullOrEmpty(commentTemplate)) | ||
| { | ||
| return commentTemplate; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var paramParser = new ParamParser(commentTemplate); | ||
| return paramParser.ReplaceParams(line, lineNum, fileName); | ||
| } | ||
| catch (ArgumentException) | ||
| { | ||
| // Invalid regex in template — return raw template (matches SetBookmarkFromTrigger behavior) | ||
| return commentTemplate; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.