julia-vscode / DocumentFormat.jl

Auto-formatter for Julia
Other
62 stars 18 forks source link

Formatter foxed by `\n` within function documentation. #61

Closed PGS62 closed 2 years ago

PGS62 commented 5 years ago

The Format Document command fails to work correctly if I include \n in the documentation section for a function. For example, the code below will be correctly formatted by the formatter:

"""
   `function testfunction(x,y)`

returns the sum of `x` and `y`
"""
function testfunction(x,y)
x+y
end

But the code below is not formatted correctly - indentation does not happen, though spaces are inserted around the + operator and after the comma.

"""
   `function testfunction(x,y)`\n
returns the sum of `x` and `y`
"""
function testfunction(x,y)
x+y
end
PGS62 commented 5 years ago

I have found a second example of the formatter not working: if the function header contains non-breaking spaces, ascii 160. This happened when I was cutting and pasting text from another application into the vscode editor.

I think the editor's normal behaviour is to display non-breaking spaces in a way that distinguishes them from ordinary spaces. Somehow I managed to circumvent that, which made tracking down the cause of the formatter's failure a bit harder!

Here's an example. Make sure that those spaces are indeed non-breaking after cutting and pasting to vscode.

"""
   `function addemup(x,y)`
The spaces in this sentence are all non-breaking, ascii 160.
"""
function addemup(x,y)
x+y
end
xgdgsc commented 4 years ago

I often see extra 4 space before "function", don' t know if related. It often happens if I forget to put end in the first place and saved once. Then adding end for function doesn' t make it work correctly.