-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Range info is off for \r\n line endings #127
Comments
What's happening here is that Now, depending on your use case, there are a couple of ways to get the ranges to match what you're expecting: For the simplest thing, if you set the If that's not enough, the CST output has a method const src = `- 1\r\n- 2\r\n`
const cst = YAML.parseCST(src)
cst.setOrigRanges() // return indicates if orig* have been set
const doc = new YAML.Document({ keepCstNodes: true }).parse(cst[0])
const { items } = doc.contents
expect(items[1].cstNode.range).toMatchObject({
start: 6, end: 7, origStart: 7, origEnd: 8
}) So that works, but it's admittedly rather clumsy and a bit obscure. The reason for that is that you're the first one to ask after this feature, and I've not bothered to do anything about it pre-emptively. If you think the ergonomics of the API ought to be improved, could you elaborate a bit on how you're planning on using this functionality? |
Thanks for replying. What I'm doing, is use this library as parsing library for https://github.com/terwoord/azure-pipelines-overview. It's used for parsing the yaml and providing a way to navigate to nodes. I worked around it by counting the amount of |
Closing this as won't-fix, given that workarounds exist. Happy to reconsider later if/when this becomes an issue again. |
I also ran in to this issue https://github.com/vscode-contrib/vscode-versionlens/issues/193 function getRangeFromCstNode(cstNode, opts) {
const crLfLineOffset = opts.hasCrLf ?
cstNode.rangeAsLinePos.start.line : 0;
const start = cstNode.range.start + crLfLineOffset;
const end = cstNode.range.end + crLfLineOffset;
return { start, end }
} |
I'm parsing YAML files, made on Windows with
\r\n
line endings. Parsing works fine (usingYAML.parseDocument(string)
, except that range positions are off. It seems that somehow\r\n
is only counted as a single character.The following tests show the problem:
The text was updated successfully, but these errors were encountered: