-
Notifications
You must be signed in to change notification settings - Fork 0
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
Position is counted incorrectly when reading a file with mixed EOL #4
Comments
vscode automatically normalizes line endings when you open a file |
Thank you very much for the detailed report. This extension does absolutely nothing custom in regards of reading/parsing a file to secure offsets. It exclusively uses vscodes built-in api's. This is the entirety of the logic this extension requires in that respect: vscode-jump-to-character-position/src/extension.ts Lines 55 to 59 in 852c509
The API method here: So I assume this is assuming you know what the index is with eol taken in consideration. So if anything, this should be passed to the vscode team to resolve, unless it is resolved in a newer api version. For now, until I can sit down and think about what options I have to accommodate, you can go to your command palette and type:
And then select |
I have done some light review locally and here is my analysis so far:
So this clearly points to vscode's api as the culprit. That method I linked above should be passed to the vscode team to rectify this shortcoming. Even if this becomes a vscode out-of-box feature, I'm guessing you're going to run into the same problem with the 'built-in' version of this if it's not addressed with them. As mentioned above, because this extension doesn't do anything extravagant with parsing files and relies exclusively on the vscode api this leaves me with few options:
My vote is for #1 at this time. I think that would require some user education, but less education than it requires for #2 and surely #3 Do you have any considerations or suggestions based on that feedback before I commit to something? I would say, if #3 is your option I would at least prefer to create another issue on the vscode project explaining the situation and see what they say before going that route. In the meantime, I will go ahead and create that bug on their project and I'll also add some remarks to your feature request about issues I've ran into they should consider |
I've had time to sit down and do a thorough review. While my initial assessment still stands, I just wanted to check and see if this possible to do from an extension perspective. Yes and no. I'll elaborate vscodes api For my testing I used the following regexps:
Using vscodes built-in api methods:
As demonstrated, vscodes api method calculates a position based on the normalized line endings. You can however read files by way of nodes Using NodeJs
|
When a file contains mixed EOL (i.e.
LF
andCR.LF
) with VS Code , the offset is not computed correctly.In the file below mixing first LF and then CR + LF, in the first part you loose one offset per line with the extension
module2.txt
The correct position for offset 88 should be (like in Notepad++):
If you go to offset 88, you get this in VS Code you are 5 characters before (corresponding to 5 lines before):
Note: tried with VS Code 1.83.0 on Windows 11
The text was updated successfully, but these errors were encountered: