Skip to content

Commit 0e70e72

Browse files
committed
Update hookspec
1 parent 581da5d commit 0e70e72

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

pylsp/hookspecs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ def pylsp_folding_range(config, workspace, document):
8080

8181

8282
@hookspec(firstresult=True)
83-
def pylsp_format_document(config, workspace, document):
83+
def pylsp_format_document(config, workspace, document, options):
8484
pass
8585

8686

8787
@hookspec(firstresult=True)
88-
def pylsp_format_range(config, workspace, document, range):
88+
def pylsp_format_range(config, workspace, document, range, options):
8989
pass
9090

9191

pylsp/plugins/autopep8_format.py

Lines changed: 2 additions & 2 deletions
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):
16+
def pylsp_format_document(config, document, _options=None):
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): # pylint: disable=redefined-builtin
22+
def pylsp_format_range(config, document, range, _options=None): # pylint: disable=redefined-builtin
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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515

1616
@hookimpl
17-
def pylsp_format_document(document):
18-
return _format(document)
17+
def pylsp_format_document(document, options=None):
18+
return _format(document, options=options)
1919

2020

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

3434
# Add 1 for 1-indexing vs LSP's 0-indexing
3535
lines = [(range['start']['line'] + 1, range['end']['line'] + 1)]
36-
return _format(document, lines=lines)
36+
return _format(document, lines=lines, options=None)
3737

3838

39-
def _format(document, lines=None):
39+
def _format(document, lines=None, options=None):
4040
# Yapf doesn't work with CR line endings, so we replace them by '\n'
4141
# and restore them below.
4242
replace_cr = False

pylsp/python_lsp.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ def document_symbols(self, doc_uri):
277277
def execute_command(self, command, arguments):
278278
return self._hook('pylsp_execute_command', command=command, arguments=arguments)
279279

280-
def format_document(self, doc_uri):
281-
return self._hook('pylsp_format_document', doc_uri)
280+
def format_document(self, doc_uri, options):
281+
return self._hook('pylsp_format_document', doc_uri, options)
282282

283-
def format_range(self, doc_uri, range):
284-
return self._hook('pylsp_format_range', doc_uri, range=range)
283+
def format_range(self, doc_uri, range, options):
284+
return self._hook('pylsp_format_range', doc_uri, range=range, options=options)
285285

286286
def highlight(self, doc_uri, position):
287287
return flatten(self._hook('pylsp_document_highlight', doc_uri, position=position)) or None
@@ -362,19 +362,17 @@ def m_text_document__hover(self, textDocument=None, position=None, **_kwargs):
362362
def m_text_document__document_symbol(self, textDocument=None, **_kwargs):
363363
return self.document_symbols(textDocument['uri'])
364364

365-
def m_text_document__formatting(self, textDocument=None, _options=None, **_kwargs):
366-
# For now we're ignoring formatting options.
367-
return self.format_document(textDocument['uri'])
365+
def m_text_document__formatting(self, textDocument=None, options=None, **_kwargs):
366+
return self.format_document(textDocument['uri'], options)
368367

369368
def m_text_document__rename(self, textDocument=None, position=None, newName=None, **_kwargs):
370369
return self.rename(textDocument['uri'], position, newName)
371370

372371
def m_text_document__folding_range(self, textDocument=None, **_kwargs):
373372
return self.folding(textDocument['uri'])
374373

375-
def m_text_document__range_formatting(self, textDocument=None, range=None, _options=None, **_kwargs):
376-
# Again, we'll ignore formatting options for now.
377-
return self.format_range(textDocument['uri'], range)
374+
def m_text_document__range_formatting(self, textDocument=None, range=None, options=None, **_kwargs):
375+
return self.format_range(textDocument['uri'], range, options)
378376

379377
def m_text_document__references(self, textDocument=None, position=None, context=None, **_kwargs):
380378
exclude_declaration = not context['includeDeclaration']

0 commit comments

Comments
 (0)