Skip to content

Commit 7cad321

Browse files
authored
Fix options not being passed to yapf format (python-lsp#262)
1 parent b218215 commit 7cad321

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pylsp/plugins/autopep8_format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414

1515
@hookimpl(tryfirst=True) # Prefer autopep8 over YAPF
16-
def pylsp_format_document(config, document, options=None): # pylint: disable=unused-argument
16+
def pylsp_format_document(config, document, options): # pylint: disable=unused-argument
1717
log.info("Formatting document %s with autopep8", document)
1818
return _format(config, document)
1919

2020

2121
@hookimpl(tryfirst=True) # Prefer autopep8 over YAPF
22-
def pylsp_format_range(config, document, range, options=None): # pylint: disable=redefined-builtin,unused-argument
22+
def pylsp_format_range(config, document, range, options): # pylint: disable=redefined-builtin,unused-argument
2323
log.info("Formatting document %s in range %s with autopep8", document, range)
2424

2525
# First we 'round' the range up/down to full lines only

pylsp/plugins/yapf_format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717

1818
@hookimpl
19-
def pylsp_format_document(document, options=None):
19+
def pylsp_format_document(document, options):
2020
return _format(document, options=options)
2121

2222

2323
@hookimpl
24-
def pylsp_format_range(document, range, options=None): # pylint: disable=redefined-builtin
24+
def pylsp_format_range(document, range, options): # pylint: disable=redefined-builtin
2525
# First we 'round' the range up/down to full lines only
2626
range['start']['character'] = 0
2727
range['end']['line'] += 1

test/plugins/test_autopep8_format.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def func():
4141

4242
def test_format(config, workspace):
4343
doc = Document(DOC_URI, workspace, DOC)
44-
res = pylsp_format_document(config, doc)
44+
res = pylsp_format_document(config, doc, options=None)
4545

4646
assert len(res) == 1
4747
assert res[0]['newText'] == "a = 123\n\n\ndef func():\n pass\n"
@@ -54,7 +54,7 @@ def test_range_format(config, workspace):
5454
'start': {'line': 0, 'character': 0},
5555
'end': {'line': 2, 'character': 0}
5656
}
57-
res = pylsp_format_range(config, doc, def_range)
57+
res = pylsp_format_range(config, doc, def_range, options=None)
5858

5959
assert len(res) == 1
6060

@@ -64,12 +64,12 @@ def test_range_format(config, workspace):
6464

6565
def test_no_change(config, workspace):
6666
doc = Document(DOC_URI, workspace, GOOD_DOC)
67-
assert not pylsp_format_document(config, doc)
67+
assert not pylsp_format_document(config, doc, options=None)
6868

6969

7070
def test_hanging_indentation(config, workspace):
7171
doc = Document(DOC_URI, workspace, INDENTED_DOC)
72-
res = pylsp_format_document(config, doc)
72+
res = pylsp_format_document(config, doc, options=None)
7373

7474
assert len(res) == 1
7575
assert res[0]['newText'] == CORRECT_INDENTED_DOC
@@ -78,6 +78,6 @@ def test_hanging_indentation(config, workspace):
7878
@pytest.mark.parametrize('newline', ['\r\n', '\r'])
7979
def test_line_endings(config, workspace, newline):
8080
doc = Document(DOC_URI, workspace, f'import os;import sys{2 * newline}dict(a=1)')
81-
res = pylsp_format_document(config, doc)
81+
res = pylsp_format_document(config, doc, options=None)
8282

8383
assert res[0]['newText'] == f'import os{newline}import sys{2 * newline}dict(a=1){newline}'

test/plugins/test_yapf_format.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
def test_format(workspace):
3131
doc = Document(DOC_URI, workspace, DOC)
32-
res = pylsp_format_document(doc)
32+
res = pylsp_format_document(doc, None)
3333

3434
assert apply_text_edits(doc, res) == "A = ['h', 'w', 'a']\n\nB = ['h', 'w']\n"
3535

@@ -41,15 +41,15 @@ def test_range_format(workspace):
4141
'start': {'line': 0, 'character': 0},
4242
'end': {'line': 4, 'character': 10}
4343
}
44-
res = pylsp_format_range(doc, def_range)
44+
res = pylsp_format_range(doc, def_range, None)
4545

4646
# Make sure B is still badly formatted
4747
assert apply_text_edits(doc, res) == "A = ['h', 'w', 'a']\n\nB = ['h',\n\n\n'w']\n"
4848

4949

5050
def test_no_change(workspace):
5151
doc = Document(DOC_URI, workspace, GOOD_DOC)
52-
assert not pylsp_format_document(doc)
52+
assert not pylsp_format_document(doc, options=None)
5353

5454

5555
def test_config_file(tmpdir, workspace):
@@ -59,7 +59,7 @@ def test_config_file(tmpdir, workspace):
5959
src = tmpdir.join('test.py')
6060
doc = Document(uris.from_fs_path(src.strpath), workspace, DOC)
6161

62-
res = pylsp_format_document(doc)
62+
res = pylsp_format_document(doc, options=None)
6363

6464
# A was split on multiple lines because of column_limit from config file
6565
assert apply_text_edits(doc, res) == "A = [\n 'h', 'w',\n 'a'\n]\n\nB = ['h', 'w']\n"
@@ -68,7 +68,7 @@ def test_config_file(tmpdir, workspace):
6868
@pytest.mark.parametrize('newline', ['\r\n'])
6969
def test_line_endings(workspace, newline):
7070
doc = Document(DOC_URI, workspace, f'import os;import sys{2 * newline}dict(a=1)')
71-
res = pylsp_format_document(doc)
71+
res = pylsp_format_document(doc, options=None)
7272

7373
assert apply_text_edits(doc, res) == f'import os{newline}import sys{2 * newline}dict(a=1){newline}'
7474

@@ -99,7 +99,7 @@ def test_format_returns_text_edit_per_line(workspace):
9999
log("x")
100100
log("hi")"""
101101
doc = Document(DOC_URI, workspace, single_space_indent)
102-
res = pylsp_format_document(doc)
102+
res = pylsp_format_document(doc, options=None)
103103

104104
# two removes and two adds
105105
assert len(res) == 4

0 commit comments

Comments
 (0)