Skip to content
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

Formatter #258

Closed
SubhadityaMukherjee opened this issue Aug 6, 2020 · 8 comments
Closed

Formatter #258

SubhadityaMukherjee opened this issue Aug 6, 2020 · 8 comments
Labels
backend Concerning the julia server and runtime enhancement New feature or request one day Closed because we won't work on it soon, will be opened again later. other packages Integration with other Julia packages

Comments

@SubhadityaMukherjee
Copy link

Okay so heads up, I am not sure if this is possible but just a thought.
I came across this package JuliaFormatter and it seems to support string as well as file formatting.
Since Pluto works so well in terms of presentation, maybe code formatting could also be something really cool? Without actually breaking the minimalism because I feel this is the only code editor which isn’t bogged down by a million things.
Just a thought.

I will test it out and see if it works without messing up Pluto files and let you know just in case.

@fonsp
Copy link
Owner

fonsp commented Aug 6, 2020

Do you mean formatting cells after you submit them, or formatting the whole file and reopening the notebook?

I appreciate your worries about breaking the minimalism, but isn’t that what adding this feature will do?

@fonsp fonsp added backend Concerning the julia server and runtime enhancement New feature or request labels Aug 7, 2020
@ilyagr
Copy link

ilyagr commented Aug 14, 2020

I would like pressing "Ctrl+Alt+F" to run the contents of the cell I'm editing through JuliaFormatter.format(). Ideally (but optionally), if there's an error during formatting, it would also be displayed to me.

@fonsp
Copy link
Owner

fonsp commented Aug 16, 2020

The formatter can error?

@fonsp fonsp added the other packages Integration with other Julia packages label Aug 16, 2020
@ilyagr
Copy link

ilyagr commented Aug 17, 2020

Yes, mainly on syntax errors.

julia> JuliaFormatter.format_text("2+2")
"2 + 2"

julia> JuliaFormatter.format_text("2+")
ERROR: Parsing error for input:

2+
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] format_text(::String, ::JuliaFormatter.DefaultStyle, ::JuliaFormatter.Options) at /home/ilyagr/.julia/packages/JuliaFormatter/7belo/src/JuliaFormatter.jl:269
 [3] #format_text#124 at /home/ilyagr/.julia/packages/JuliaFormatter/7belo/src/JuliaFormatter.jl:264 [inlined]
 [4] format_text(::String) at /home/ilyagr/.julia/packages/JuliaFormatter/7belo/src/JuliaFormatter.jl:248
 [5] top-level scope at REPL[188]:1
 [6] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088

I looked at JuliaFormatter source, and it seems that currently the error doesn't come with any details (such as which line it occurred on, or what is wrong). I guess that would be blocked on julia-vscode/CSTParser.jl#87.

@fonsp
Copy link
Owner

fonsp commented Aug 17, 2020

That's fine, you can get the error with try Meta.parse(str) catch err; sprint(showerror, err) end

@fonsp fonsp added the one day Closed because we won't work on it soon, will be opened again later. label Aug 18, 2020
@fonsp fonsp closed this as completed Aug 18, 2020
@max-sixty
Copy link

Re-upping this if that's OK!

In Jupyter I use https://github.com/dnanhkhoa/nb_black — it's a really simple extension that formats the code after running the cell. It means I don't have to worry about formatting at all — just type away and it'll look good when it's run. Having code well-formatted makes it easier to see its structure, including loops.

I have the same thing when working in VSCode with Julia, but not with Julia in Pluto. Pluto takes care of so much mental overhead around state, but it adds back some of that with having to think about formatting.

IIUC there was a concern about whether the formatter can error above. I don't think that should be a blocking concern — the formatter errors when the code is invalid Julia — so I would imagine Pluto could just ignore those errors, and we'd see the error picked up by the current Julia parser, just as it does now. Or am I missing something?

Thank you for the superb app!

@fonsp
Copy link
Owner

fonsp commented Feb 24, 2022

Experiments in #1531

@taooceros
Copy link

any news

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Concerning the julia server and runtime enhancement New feature or request one day Closed because we won't work on it soon, will be opened again later. other packages Integration with other Julia packages
Projects
None yet
Development

No branches or pull requests

5 participants