-
If you have a Julia MCP tool, always run code with that. Don't invoke julia from bash as that is very slow.
-
To investigate formatting with JuliaFormatter, use the
julia_formattool. The first time you run it, you need to specifyformatter_path=...with the local checkout of JulaiFormatter. -
To run generic Julia code, use the
julia_evaltool. Avoid passing a specificenv_pathas that will clutter the user's environment. In the absence of anenv_path, the tool will create a temporary environment for you. In this environment you canPkg.develop(; path=...)the local checkout of JuliaFormatter and add any other packages you need. -
Code changes in the local checkout should be immediately visible without having to reload the session (thanks to Revise.jl). If you encounter any issues with this, try restarting the MCP session.
-
Always use the
JuliaFormatter.Internal.format_to_stagefunction to inspect the output of each stage of the formatting process. Ifsis a string containing the code to be formatted, thenformat_to_stage(stage, s[, style]; options...)will give the output of the specified stage, wherestageis one of::cstgives the CST from JuliaSyntax;:fstgives the initial FST that JuliaFormatter constructs from the CST usingpretty();:nestgives the FST after flattening, alignment, and nesting;:outgives the final formatted string;:printprints the final formatted string.
If
format_textgenerates invalid Julia code, it will throw, which is unhelpful for debugging. In such cases you should useformat_to_stage(:out, ...)as that will show you the actual invalid code.
-
Do NOT run complete segments of the test suite unless explicitly instructed to. Only run specific, targeted tests that are relevant to the changes you are making, using
JuliaFormatter.Internal.test_format(input_string, expected_output[, style]; options...)This function checks that formattinginput_stringproducesexpected_output, and also for idempotence. It also prints helpful information if it fails so that you can easily debug the issue. -
To test whether a string is valid Julia code, you can use
Meta.parse(s)orformat_to_stage(:cst, s). Both throw if the code is invalid.
JuliaFormatter is a complex codebase with many moving parts. Do not assume that other developers will understand terse comments as they do not have the same context as you. For example, when writing function-level comments, it's useful to illustrate your point with a concrete example of code that is being formatted.
-
Do not write off any valid syntactic construct as "pathological" or not worth supporting. ALL valid Julia code should be supported by the formatter, even if it's not common in practice.
-
Do not use fragile heuristics or hacks to achieve the desired formatting. Where possible, you should always try to implement formatting logic at the CST stage (i.e.
pretty()), because the CST has more precise structural information about the code being run.