@@ -15,12 +15,19 @@ function precedence_level(cst::EXPR, loc::Location)
15
15
end
16
16
end
17
17
18
- separator (x:: EXPR{Call} , i:: Integer ) = max (i- 1 , 4 )
18
+ function separator (cst, loc, x:: EXPR{Call} , i)
19
+ length (x. args) == 3 && return " "
20
+ length (x. args) == 4 && return " , "
21
+ charrange (cst, CSTParser. child (loc, max (i- 1 , 4 )))[1 ]
22
+ end
23
+
24
+ function separator (cst, loc, x:: CSTParser.BinaryOpCall , i)
25
+ charrange (cst, CSTParser. child (loc, 2 ))[1 ]
26
+ end
19
27
20
28
function separator (cst:: EXPR , loc:: Location )
21
29
parent = CSTParser. parent (loc)
22
- i = separator (cst[parent], loc. ii[end ])
23
- CSTParser. child (parent, i)
30
+ separator (cst, parent, cst[parent], loc. ii[end ])
24
31
end
25
32
26
33
struct SourceFile
@@ -46,20 +53,24 @@ function replacement(src::SourceFile, p::Insert)
46
53
append = p. idx[end ] > length (expridx (src. ast, p. idx[1 : end - 1 ]). args)
47
54
append && (p. idx[end ] -= 1 )
48
55
loc = expr_location (src. cst, p. idx)
56
+ # TODO handle cases like this more generally
57
+ src. cst[CSTParser. parent (loc)] isa EXPR{Call} && (loc. ii[end ] = max (loc. ii[end ], 2 ))
49
58
span, _ = charrange (src. cst, loc)
50
59
point = append ? span[end ] : span[1 ]- 1
51
- sep = charrange (src. cst, separator (src. cst, loc))[1 ]
60
+ sep = separator (src. cst, loc)
61
+ sep isa AbstractRange && (sep = src. text[sep])
52
62
(1 : 0 ). + point => sprint () do io
53
- append && write (io, src . text[ sep] )
63
+ append && write (io, sep)
54
64
Base. show_unquoted (io, p. tree, 0 , 0 )
55
- append || write (io, src . text[ sep] )
65
+ append || write (io, sep)
56
66
end
57
67
end
58
68
59
69
function replacement (src:: SourceFile , p:: Delete )
60
70
loc = expr_location (src. cst, p. idx)
61
71
span, _ = charrange (src. cst, loc)
62
- sep = charrange (src. cst, separator (src. cst, loc))[1 ]
72
+ sep = separator (src. cst, loc)
73
+ sep isa AbstractRange || (sep = span)
63
74
span = span[1 ] > sep[1 ] ? (sep[1 ]: span[end ]) : (span[1 ]: sep[end ])
64
75
span => " "
65
76
end
0 commit comments