JuliaEditorSupport / JuliaEditorSupport/JuliaFormatter.jl

`variable_call_indent` leaks too much DefaultStyle stuff through

Open
#1,069 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3
Dominant language
Julia
Stars
644
Forks
82
Avg merge
1m
Merged PRs (30d)
3

Description

YASStyle + variable_call_indent is quite largely implemented by deferring to DefaultStyle (this is in both p_call and n_call!). However, this leaks quite a fair bit of DefaultStyle formatting decisions through. For example:

julia> s = "f(a, b)"

julia> ft(s, YASStyle()) |> println
f(a, b)


julia> ft(s, YASStyle(); margin=1) |> println
f(a,
  b)


julia> ft(s, YASStyle(); margin=1, variable_call_indent=["f"]) |> println
f(
  a,
  b,
  )

I would expect the last two to give the same results. The issue here is that DefaultStyle will insert placeholders after the opening paren and before the closing paren:

julia> fs(:fst, s, YASStyle(); margin=1, variable_call_indent=["f"])
TopLevel 1 lines=1-1 indent=0 len=7
nest_behavior=AllowNest extra_margin=0
└── [1] Call 10 lines=1-1 indent=0 len=7
    nest_behavior=AllowNest extra_margin=0
    ├── [1] IDENTIFIER lines=1-1 val="f"
    │       line_offset=1 indent=0
    ├── [2] PUNCTUATION lines=1-1 val="("
    │       line_offset=2 indent=0
    ├── [3] PLACEHOLDER lines=1-1 val=""
    │       line_offset=-1 indent=0
    ├── [4] IDENTIFIER lines=1-1 val="a"
    │       line_offset=3 indent=0
    ├── [5] PUNCTUATION lines=1-1 val=","
    │       line_offset=4 indent=0
    ├── [6] PLACEHOLDER lines=1-1 val=" "
    │       line_offset=-1 indent=0
    ├── [7] IDENTIFIER lines=1-1 val="b"
    │       line_offset=6 indent=0
    ├── [8] TRAILINGCOMMA lines=1-1 val=""
    │       line_offset=-1 indent=0
    ├── [9] PLACEHOLDER lines=1-1 val=""
    │       line_offset=-1 indent=0
    └── [10] PUNCTUATION lines=1-1 val=")"
            line_offset=7 indent=0

whereas plain old YASStyle won't.

julia> fs(:fst, s, YASStyle(); margin=1)
TopLevel 1 lines=1-1 indent=0 len=7
nest_behavior=AllowNest extra_margin=0
└── [1] Call 8 lines=1-1 indent=0 len=7
    nest_behavior=AllowNest extra_margin=0
    ├── [1] IDENTIFIER lines=1-1 val="f"
    │       line_offset=1 indent=0
    ├── [2] PUNCTUATION lines=1-1 val="("
    │       line_offset=2 indent=0
    ├── [3] IDENTIFIER lines=1-1 val="a"
    │       line_offset=3 indent=0
    ├── [4] PUNCTUATION lines=1-1 val=","
    │       line_offset=4 indent=0
    ├── [5] PLACEHOLDER lines=1-1 val=" "
    │       line_offset=-1 indent=0
    ├── [6] IDENTIFIER lines=1-1 val="b"
    │       line_offset=6 indent=0
    ├── [7] TRAILINGCOMMA lines=1-1 val=""
    │       line_offset=-1 indent=0
    └── [8] PUNCTUATION lines=1-1 val=")"
            line_offset=7 indent=0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing YASStyle's variable_call_indent handling through p_call and n_call!, comparing it with the DefaultStyle behavior shown by fs(:fst, s, YASStyle()). Reproduce the margin=1 examples and verify that variable_call_indent no longer introduces DefaultStyle's opening and closing placeholders while preserving the intended multiline indentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.