-
Notifications
You must be signed in to change notification settings - Fork 185
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
Rojo unexpectedly trims trailing newline characters when syncing to Studio. #899
Comments
Just to clarify, are you running Rojo 7.4.1? If so, would it be possible for you to check if this happens on 7.4.0? I think this is probably related to #854, but it's surprising behavior for the implementation we're using so I'd like to make sure. |
This is indeed related to a detail of Lines 299 to 304 in b2f133e
When the iterator encounters a lone newline, it returns an empty string: Rust playground. We can probably resolve this by doing something like pub fn read_to_string_lf_normalized<P: AsRef<Path>>(&self, path: P) -> io::Result<Arc<String>> {
let path = path.as_ref();
let contents = self.inner.lock().unwrap().read_to_string(path)?;
- Ok(contents.lines().collect::<Vec<&str>>().join("\n").into())
+ Ok(contents.replace("\r\n", "\n").into())
} |
Yes, I'm using 7.4.1. I'm pretty new to Rojo so I'm not sure how to downgrade. Could you link me to a resource to learn how? |
There's no need to do so now (Ken has identified that this is indeed an issue with our implementation). For future reference though, it depends upon how you installed Rojo. If you used a toolchain manager like Aftman or Foreman, you'd just change the version in the relevant configuration file. Otherwise you'd have to go to the releases page and download an earlier version from there. |
Sounds like a good idea to me, though I'd be worried about performance. The underlying implementation for |
I benchmarked the two approaches, and on my machine, the Here is the code I used to benchmark: use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
pub fn benchmark_string_normalization(c: &mut Criterion) {
let mut group = c.benchmark_group("Line Ending Normalization");
for i in [
("lf_input", "Oh My Goodness\n".repeat(2000).as_str()),
("crlf_input", "Oh My Goodness\r\n".repeat(2000).as_str()),
] {
group.bench_with_input(BenchmarkId::new("string_replace", i.0), i.1, |b, s| {
b.iter_batched(
|| s.to_string(),
|s| {
let _ = s.replace("\r\n", "\n");
},
BatchSize::SmallInput,
)
});
group.bench_with_input(BenchmarkId::new("string_lines", i.0), i.1, |b, s| {
b.iter_batched(
|| s.to_string(),
|s| {
s.lines().collect::<Vec<&str>>().join("\n");
},
BatchSize::SmallInput,
)
});
}
group.finish();
}
criterion_group!(benches, benchmark_string_normalization);
criterion_main!(benches); |
I guess that actually makes sense, but it's good to see the data on it. In that case I have no qualms about just using |
My code in Visual Studio Code:
![image](https://private-user-images.githubusercontent.com/32988106/319846220-9fb1e4fb-e0ce-4652-98c9-a5fbc9bfdbc5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1Nzg4MTcsIm5iZiI6MTczOTU3ODUxNywicGF0aCI6Ii8zMjk4ODEwNi8zMTk4NDYyMjAtOWZiMWU0ZmItZTBjZS00NjUyLTk4YzktYTVmYmM5YmZkYmM1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDAwMTUxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ2YmY0YzFmMGJhZGE1OTEyNWU2MTMxZjRmZWJjMWQxOWFjMzkzODU2NmRkMjY1Yzg0MjRiZWFlZjRhZmE1YjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.qrcpp_tYuF9NXfDpsjoIycJ5iHamMLDwMBgHyiePk8E)
Note that there are two lines in the document, with the second one being blank.
My code when synced to Roblox Studio:
Note that there is only one line in the document. The blank line is missing.
This makes doing a comparison between
script.source
s a problem in some cases such as mine. Some may argue there shouldn't be a trailing newline here, but more predictable behavior would be more ideal to me. It is up to the developer to follow good programming practices.Workaround:
Add a second trailing empty line in Visual Studio Code so there will be at least one in Roblox Studio.
Let me know if I put this in the wrong place.
The text was updated successfully, but these errors were encountered: