This is a Julia language formatter using the
JuliaFormatter.jl
package. The
Julia extension
uses the DocumentFormat
package. They differ by some decisions.
-
Though this extension will try to install it, we still recommend that you install
JuliaFormatter.jl
before installing this extension. To do this, open the REPL and type]add JuliaFormatter
It is better to install the latest version of
JuliaFormatter
, since some settings require that.
This extension contributes the following settings:
juliaFormatter.overwriteFlags
: Whether to overwrite the settings of the specified style with theJuliaFormatter
flags specified in vs-code's settings.false
by default.juliaFormatter.style
: Formatting styles. Choose from:'default'
,'yas'
, and'blue'
.juliaFormatter.compile
: Control the compilation level of Julia. Available values are'min'
or'all'
.juliaFormatter.margin
: The maximum number of characters of code on a single line. Lines over the limit will be wrapped if possible. There are cases where lines cannot be wrapped and they will still end up wider than the requested margin.92
by default.juliaFormatter.indent
: The number of spaces used for an indentation.4
by default.juliaFormatter.alwaysForIn
: Always replaces=
within
forfor
loops. For example,for i = 1:10
will be transformed tofor i in 1:10
.false
by default.juliaFormatter.whitespaceTypedefs
: Iftrue
, whitespace is added for type definitions. Make thistrue
if you preferUnion{A <: B, C}
toUnion{A<:B,C}
.juliaFormatter.whitespaceOpsInIndices
: Iftrue
, whitespace is added for binary operations in indices. Make thistrue
if you preferarr[a + b]
toarr[a+b]
.juliaFormatter.removeExtraNewlines
: Iftrue
, superflous newlines will be removed.juliaFormatter.importToUsing
: Iftrue
,import
expressions are rewritten tousing
expressions.juliaFormatter.pipeToFunctionCall
: Iftrue
,x |> f
is rewritten tof(x)
.juliaFormatter.shortToLongFunctionDef
: Transforms a short function definition to a long function definition.juliaFormatter.alwaysUseReturn
: Iftrue
,return
will be prepended to the last expression where applicable in function definitions, macro definitions, and do blocks.juliaFormatter.whitespaceInKwargs
: Iftrue
,=
in keyword arguments will be surrounded by whitespace.juliaFormatter.annotateUntypedFieldsWithAny
: Iftrue
, Annotates fields in a type definitions with::Any
if no type annotation is provided (RequiresJuliaFormatter.jl v0.6.3
).juliaFormatter.formatDocstrings
: Iftrue
, format code docstrings with the same options used for the code source.juliaFormatter.alignAssignment
: Iftrue
, align the=
-like operators. This covers variable assignments and short definition functions.juliaFormatter.alignStructField
: Iftrue
, align struct field definitions to::
or=
, whichever has higher precedence.juliaFormatter.alignConditional
: Iftrue
, align conditional expressions to either?
,:
, or both.juliaFormatter.alignPairArrow
: Iftrue
, align pair arrows (=>
).juliaFormatter.conditionalToIf
: If the conditionalE ? A : B
exceeds the maximum margin converts it into the equivalentif
block.juliaFormatter.normalizeLineEndings
: Normalize line endings.juliaFormatter.systemImagePath
: The path to the sysimage to use when launching the Julia process that will format a file. If empty, no sysimage will be used. Read the PackageCompiler.jl documentation to learn why and how to create a sysimage. (Tl;dr a sysimage is a snapshot of the compiled functions in a Julia session, which can be reused to nearly eliminate the long compilation times Julia tends to suffer from. Using a sysimage can vastly reduce the time it takes to format files.)
For more detailed explanation of these settings, please go to its official docs.
It is recommended to use this extension with the Format in context menus extension (not an ad!). It allows formatting multiple files at a time.
If you want to use this extension instead of the Julia extension to format your file, you may want to put
"[julia]": {
"editor.defaultFormatter": "singularitti.vscode-julia-formatter"
},
in the editor's settings.json
.
See CHANGELOG.md for release notes.