earshinov / vscode-filter-lines

Extension for Visual Studio Code allowing to quickly find all lines matching a string or regular expression
https://marketplace.visualstudio.com/items?itemName=earshinov.filter-lines
MIT License
13 stars 3 forks source link

Filter Lines: Include Lines with Regex and Context + Line Numbers - Off by 1 #26

Closed larray closed 1 year ago

larray commented 1 year ago

Log file - Text being filtered example: 2023-08-08T12:57:07.231Z[00:000000:client-registration] (end of log lines cut off - irrelevant to the issue)

Regex Filter: ((\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{3})Z)[\d{2}:\d{6}:client-registration]

For the example above in the source log - lines that match that pattern appear on line numbers: 47: 2023-08-08THH:MM:SS.mmmZ[00:000000:client-registration] 87: 2023-08-08THH:MM:SS.mmmZ[00:000000:client-registration] 103: 2023-08-08THH:MM:SS.mmmZ[00:000000:client-registration]

When processed through "Filter Lines: Include Lines with Regex and Context" they are presented as being 1 log line reference LOWER. Filtered log output would look like: 46: 2023-08-08THH:MM:SS.mmmZ[00:000000:client-registration] 86: 2023-08-08THH:MM:SS.mmmZ[00:000000:client-registration] 102: 2023-08-08THH:MM:SS.mmmZ[00:000000:client-registration]

larray commented 1 year ago

Original log example with line reference: Filter_Lines_original_log Filter Lines output example: Filter_Lines_Filtered

earshinov commented 1 year ago

Hey! Thank you for the report. This behavior was inherited from the original Sublime Text plugin (https://packagecontrol.io/packages/Filter%20Lines) and I was hesitant to change it. But now that I think about it, 1-based line numbers indeed make more sense and, like page numbers for example, start with line/page 1 much more often than with line/page 0. I will change it soon and release a new version of the extension.

larray commented 1 year ago

Thanks for the consideration and quick response!

I wasn’t sure where it came from and assumed something in the handling made an inadvertent adjustment.

Even having a switch in preferences may make sense - there may be times it is needed (especially if the origin code considers it relevant). For me - when doing log comparison though it was an oddity. I tried to discuss the origin log with a team member and began documenting line numbers after filtering and found all my references to be inaccurate. (Document didn’t match the source)

Fantastic tool though!

earshinov commented 1 year ago

Just published version 1.1.0. You are welcome :)