Skip to content

Commit a8cd387

Browse files
committed
Hopefully last lint
1 parent 89f6211 commit a8cd387

File tree

2 files changed

+62
-57
lines changed

2 files changed

+62
-57
lines changed

Diff for: pylsp/text_edit.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def merge_sort_text_edits(text_edits):
6161
return text_edits
6262

6363

64+
class OverLappingTextEditException(Exception):
65+
"""
66+
Text edits are expected to be sorted
67+
and compressed instead of overlapping.
68+
This error is raised when two edits
69+
are overlapping.
70+
"""
71+
6472
def apply_text_edits(doc, text_edits):
6573
text = doc.source
6674
sorted_edits = merge_sort_text_edits(list(map(get_well_formatted_edit, text_edits)))
@@ -69,7 +77,7 @@ def apply_text_edits(doc, text_edits):
6977
for e in sorted_edits:
7078
start_offset = doc.offset_at_position(e['range']['start'])
7179
if start_offset < last_modified_offset:
72-
raise Exception('overlapping edit')
80+
raise OverLappingTextEditException('overlapping edit')
7381

7482
if start_offset > last_modified_offset:
7583
spans.append(text[last_modified_offset:start_offset])

Diff for: test/test_text_edit.py

+53-56
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pylsp.text_edit import apply_text_edits
1+
from pylsp.text_edit import OverLappingTextEditException, apply_text_edits
22
from pylsp import uris
33

44
DOC_URI = uris.from_fs_path(__file__)
@@ -245,70 +245,67 @@ def test_apply_text_edits_overlap(pylsp):
245245
pylsp.workspace.put_document(DOC_URI, '012345678901234567890123456789')
246246
test_doc = pylsp.workspace.get_document(DOC_URI)
247247

248-
over_lapping_edits1 = [{
249-
"range": {
250-
"start": {
251-
"line": 0,
252-
"character": 3
253-
},
254-
"end": {
255-
"line": 0,
256-
"character": 6
257-
}
258-
},
259-
"newText": "Hello"
260-
}, {
261-
"range": {
262-
"start": {
263-
"line": 0,
264-
"character": 3
265-
},
266-
"end": {
267-
"line": 0,
268-
"character": 3
269-
}
270-
},
271-
"newText": "World"
272-
}]
273-
274248
did_throw = False
275249
try:
276-
apply_text_edits(test_doc, over_lapping_edits1)
277-
except Exception:
250+
apply_text_edits(test_doc, [{
251+
"range": {
252+
"start": {
253+
"line": 0,
254+
"character": 3
255+
},
256+
"end": {
257+
"line": 0,
258+
"character": 6
259+
}
260+
},
261+
"newText": "Hello"
262+
}, {
263+
"range": {
264+
"start": {
265+
"line": 0,
266+
"character": 3
267+
},
268+
"end": {
269+
"line": 0,
270+
"character": 3
271+
}
272+
},
273+
"newText": "World"
274+
}])
275+
except OverLappingTextEditException:
278276
did_throw = True
279277

280278
assert did_throw
281279

282-
over_lapping_edits2 = [{
283-
"range": {
284-
"start": {
285-
"line": 0,
286-
"character": 3
287-
},
288-
"end": {
289-
"line": 0,
290-
"character": 6
291-
}
292-
},
293-
"newText": "Hello"
294-
}, {
295-
"range": {
296-
"start": {
297-
"line": 0,
298-
"character": 4
299-
},
300-
"end": {
301-
"line": 0,
302-
"character": 4
303-
}
304-
},
305-
"newText": "World"
306-
}]
307280
did_throw = False
308281

309282
try:
310-
apply_text_edits(test_doc, over_lapping_edits2)
311-
except Exception:
283+
apply_text_edits(test_doc, [{
284+
"range": {
285+
"start": {
286+
"line": 0,
287+
"character": 3
288+
},
289+
"end": {
290+
"line": 0,
291+
"character": 6
292+
}
293+
},
294+
"newText": "Hello"
295+
}, {
296+
"range": {
297+
"start": {
298+
"line": 0,
299+
"character": 4
300+
},
301+
"end": {
302+
"line": 0,
303+
"character": 4
304+
}
305+
},
306+
"newText": "World"
307+
}])
308+
except OverLappingTextEditException:
312309
did_throw = True
313310

314311
assert did_throw

0 commit comments

Comments
 (0)