@@ -68,14 +68,14 @@ def test_adding_missing_pipe
68
68
)
69
69
document . parse
70
70
71
- edits = RubyLsp ::Requests ::OnTypeFormatting . new ( document , { line : 0 , character : 11 } , "|" ) . run
71
+ edits = RubyLsp ::Requests ::OnTypeFormatting . new ( document , { line : 0 , character : 12 } , "|" ) . run
72
72
expected_edits = [
73
73
{
74
- range : { start : { line : 0 , character : 11 } , end : { line : 0 , character : 11 } } ,
74
+ range : { start : { line : 0 , character : 12 } , end : { line : 0 , character : 12 } } ,
75
75
newText : "|" ,
76
76
} ,
77
77
{
78
- range : { start : { line : 0 , character : 11 } , end : { line : 0 , character : 11 } } ,
78
+ range : { start : { line : 0 , character : 12 } , end : { line : 0 , character : 12 } } ,
79
79
newText : "$0" ,
80
80
} ,
81
81
]
@@ -94,10 +94,66 @@ def test_pipe_is_not_added_in_regular_or_pipe
94
94
)
95
95
document . parse
96
96
97
- edits = RubyLsp ::Requests ::OnTypeFormatting . new ( document , { line : 0 , character : 11 } , "|" ) . run
97
+ edits = RubyLsp ::Requests ::OnTypeFormatting . new ( document , { line : 0 , character : 2 } , "|" ) . run
98
98
assert_empty ( T . must ( edits ) )
99
99
end
100
100
101
+ def test_pipe_is_removed_if_user_adds_manually_after_completion
102
+ document = RubyLsp ::Document . new ( source : +"" , version : 1 , uri : "file:///fake.rb" )
103
+
104
+ document . push_edits (
105
+ [ {
106
+ range : { start : { line : 0 , character : 0 } , end : { line : 0 , character : 0 } } ,
107
+ text : "[].each do |" ,
108
+ } ] ,
109
+ version : 2 ,
110
+ )
111
+ document . parse
112
+
113
+ document . push_edits (
114
+ [ {
115
+ range : { start : { line : 0 , character : 12 } , end : { line : 0 , character : 12 } } ,
116
+ text : "|" ,
117
+ } ] ,
118
+ version : 3 ,
119
+ )
120
+ edits = RubyLsp ::Requests ::OnTypeFormatting . new ( document , { line : 0 , character : 12 } , "|" ) . run
121
+ expected_edits = [
122
+ {
123
+ range : { start : { line : 0 , character : 12 } , end : { line : 0 , character : 12 } } ,
124
+ newText : "|" ,
125
+ } ,
126
+ {
127
+ range : { start : { line : 0 , character : 12 } , end : { line : 0 , character : 12 } } ,
128
+ newText : "$0" ,
129
+ } ,
130
+ ]
131
+ assert_equal ( expected_edits . to_json , T . must ( edits ) . to_json )
132
+ assert_equal ( "[].each do ||" , document . source )
133
+
134
+ # Push the third pipe manually after the completion happened
135
+ document . push_edits (
136
+ [ {
137
+ range : { start : { line : 0 , character : 13 } , end : { line : 0 , character : 13 } } ,
138
+ text : "|" ,
139
+ } ] ,
140
+ version : 3 ,
141
+ )
142
+
143
+ edits = RubyLsp ::Requests ::OnTypeFormatting . new ( document , { line : 0 , character : 13 } , "|" ) . run
144
+ expected_edits = [
145
+ {
146
+ range : { start : { line : 0 , character : 13 } , end : { line : 0 , character : 14 } } ,
147
+ newText : "" ,
148
+ } ,
149
+ {
150
+ range : { start : { line : 0 , character : 13 } , end : { line : 0 , character : 13 } } ,
151
+ newText : "$0" ,
152
+ } ,
153
+ ]
154
+ assert_equal ( expected_edits . to_json , T . must ( edits ) . to_json )
155
+ end
156
+
101
157
def test_comment_continuation
102
158
document = RubyLsp ::Document . new ( source : +"" , version : 1 , uri : "file:///fake.rb" )
103
159
0 commit comments