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

Everything after an open multiline comment gets deleted #760

Closed
mortenpi opened this issue Sep 25, 2023 · 2 comments
Closed

Everything after an open multiline comment gets deleted #760

mortenpi opened this issue Sep 25, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@mortenpi
Copy link

mortenpi commented Sep 25, 2023

If you have something like this

foo() = nothing
#=
...

Then everything after #= gets erased:

(@format) pkg> st
Status `~/.julia/environments/format/Project.toml`
  [98e50ef6] JuliaFormatter v1.0.36

julia> s = """
       foo() = nothing
       #=
       ...
       """
"foo() = nothing\n#=\n...\n"

julia> format_text(s)
"foo() = nothing\n"

This can be pretty bad if you have Format on Save enabled.

@domluna domluna added the bug Something isn't working label Sep 25, 2023
@domluna
Copy link
Owner

domluna commented Sep 25, 2023

assumes there's a closing =#. but could come up if you format before you add it.

@domluna
Copy link
Owner

domluna commented Oct 4, 2023

this might be better filed with CSTParser

┌ Info:
│   t = 1,9-1,15         IDENTIFIER     "nothing"
└   t.val = "nothing"
┌ Info:
│   t = 1,16-2,0         WHITESPACE     "\n"
└   t.val = "\n"
┌ Info:
│   t = 2,1-4,0          ERROR          "#=\na = 10\n"
└   t.val = "#=\na = 10\n"
┌ Info:
│   t = 4,1-4,0          ENDMARKER      ""
└   t.val = ""

t = 2,1-4,0 ERROR "#=\na = 10\n"

it's identified as an ERROR and not a comment. Same thing with JuliaSyntax, but at least JuliaSyntax throws an error

julia> JuliaSyntax.parse(JuliaSyntax.SyntaxNode, s)
ERROR: ParseError:
# Error @ line 2:1
foo() = nothing
┌─
#=
a = 10
#────┘ ── unexpected text after parsing statement
Stacktrace:
 [1] _parse(rule::Symbol, need_eof::Bool, ::Type{…}, text::String, index::Int64; version::VersionNumber, ignore_trivia::Bool, filename::Nothing, first_line::Int64, ignore_errors::Bool, ignore_warnings::Bool, kws::@Kwargs{})
   @ JuliaSyntax ~/.julia/packages/JuliaSyntax/z5WbP/src/parser_api.jl:93
 [2] _parse (repeats 2 times)
   @ JuliaSyntax ~/.julia/packages/JuliaSyntax/z5WbP/src/parser_api.jl:77 [inlined]
 [3] parsestmt(::Type{SyntaxNode}, text::String)
   @ JuliaSyntax ~/.julia/packages/JuliaSyntax/z5WbP/src/parser_api.jl:140
 [4] parse(::Type, ::Vararg{Any}; kwargs::@Kwargs{})
   @ JuliaSyntax ./deprecated.jl:116
 [5] parse(::Type, ::Vararg{Any})
   @ JuliaSyntax ./deprecated.jl:113
 [6] top-level scope
   @ REPL[16]:1
Some type information was truncated. Use `show(err)` to see complete types.

I'm not sure if it's appropriate for JuliaFormatter to throw an error when an ERROR is encountered but I suppose a fix for this specific case could work.

domluna added a commit that referenced this issue Oct 4, 2023
@domluna domluna closed this as completed in f72bcf0 Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants