-
Notifications
You must be signed in to change notification settings - Fork 93
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
"No newline at end of file" after formatting file in VS Code #462
Comments
You might want to turn on I'll take a closer look at the document formatting provider then. |
Thanks for looking into this! Just know that |
FWIW: The reason why styler ensures always exactly one trailing empty line (when the input is a file, e.g. not in |
Other people have experienced this while formatting on save: |
This seems to be a major headache for some people. Can we fix it? |
Let me take a look into this. |
Looks like it is caused by how styler uses cache and how it handles empty line are not consistent. First, clear the styler cache. rm -rf ~/.cache/R/R.cache/styler Then try the following: > str(styler::style_text(c("print(1)", "")))
'vertical' chr "print(1)"
> str(styler::style_text(c("print(1)", "")))
'vertical' chr [1:2] "print(1)" ""
> str(styler::style_text(c("print(1)", "")))
'vertical' chr [1:2] "print(1)" ""
> str(styler::style_text(c("print(2)", "")))
'vertical' chr "print(2)"
> str(styler::style_text(c("print(2)", "")))
'vertical' chr [1:2] "print(2)" ""
> str(styler::style_text(c("print(2)", "")))
'vertical' chr [1:2] "print(2)" ""
> str(styler::style_text(c("print(3)", "")))
'vertical' chr "print(3)"
> str(styler::style_text(c("print(3)", "")))
'vertical' chr [1:2] "print(3)" ""
> str(styler::style_text(c("print(3)", "")))
'vertical' chr [1:2] "print(3)" "" Looks like it should be fixed in styler where inconsistent results are returned? @lorenzwalthert |
Ugh, you are right @renkun-ken. Thanks for looking into it. I will have a look and Open an issue in styler. |
Seems like it's fixed in dev version of {styler}. Should we just ask people to install the dev version of {styler} or do we need a fix here too? You could check for |
In any case, I think once I release a {styler} update, there should be a minimal version requirement for {styler}. |
@lorenzwalthert Do you think #509 should work with both CRAN release and latest dev of styler? @bersbersbers Does #509 work for you? |
@nealrichardson @assignUser, with dev styler and dev languageserver, formatting should now be more consistent with regard to trailing blank line. Let us know if it works now for you. |
@lorenzwalthert seems to be working for me now--thanks a lot! |
Yep perfect, thanks! |
Thanks a lot. It worked |
bug.R
containting this line:styler::style_file("bug.R")
(no newline at end of file).Rscript bug.R
.Rprofile
ignores the last line if it does not end in a newline, see https://yihui.org/en/2018/04/rprofile-trailing-newline/I think the above establishes that a file should end in a newline character.
Now, the R language server seems to remove that newline character - inconsistently!
Note especially how with
"editor.formatOnSave": true
, it takes me 5 tries to reproduce the problem.The text was updated successfully, but these errors were encountered: