8000 yapf_format: fix config lookup (#473) · lcheylus/python-lsp-server@db16c23 · GitHub
[go: up one dir, main page]

Skip to content

Commit db16c23

Browse files
perrinjeromegatesn
authored andcommitted
yapf_format: fix config lookup (python-lsp#473)
1 parent 98977b6 commit db16c23

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pyls/plugins/yapf_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _format(document, lines=None):
3737
lines=lines,
3838
filename=document.filename,
3939
style_config=file_resources.GetDefaultStyleForDir(
40-
os.path.dirname(document.filename)
40+
os.path.dirname(document.path)
4141
)
4242
)
4343

test/plugins/test_yapf_format.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ def test_range_format():
4545
def test_no_change():
4646
doc = Document(DOC_URI, GOOD_DOC)
4747
assert not pyls_format_document(doc)
48+
49+
50+
def test_config_file(tmpdir):
51+
# a config file in the same directory as the source file will be used
52+
conf = tmpdir.join('.style.yapf')
53+
conf.write('[style]\ncolumn_limit = 14')
54+
src = tmpdir.join('test.py')
55+
doc = Document(uris.from_fs_path(src.strpath), DOC)
56+
57+
# A was split on multiple lines because of column_limit from config file
58+
assert pyls_format_document(doc)[0]['newText'] == "A = [\n 'h', 'w',\n 'a'\n]\n\nB = ['h', 'w']\n"

0 commit comments

Comments
 (0)
0