Skip to content

Commit e79bbb2

Browse files
committed
feat: close cell if deleted
1 parent 4f140da commit e79bbb2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pylsp/python_lsp.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def _lint_text_document(self, doc_uri, workspace, is_saved):
394394
flatten(self._hook('pylsp_lint', doc_uri, is_saved=is_saved))
395395
)
396396

397-
def _lint_notebook_document(self, notebook_document, workspace):
397+
def _lint_notebook_document(self, notebook_document, workspace): # pylint: disable=too-many-locals
398398
"""
399399
Lint a notebook document.
400400
@@ -443,11 +443,13 @@ def _lint_notebook_document(self, notebook_document, workspace):
443443
for cell in cell_list:
444444
cell_diagnostics = []
445445
for diagnostic in document_diagnostics:
446-
if diagnostic['range']['start']['line'] > cell['line_end'] \
447-
or diagnostic['range']['end']['line'] < cell['line_start']:
446+
start_line = diagnostic['range']['start']['line']
447+
end_line = diagnostic['range']['end']['line']
448+
449+
if start_line > cell['line_end'] or end_line < cell['line_start']:
448450
continue
449-
diagnostic['range']['start']['line'] = diagnostic['range']['start']['line'] - cell['line_start']
450-
diagnostic['range']['end']['line'] = diagnostic['range']['end']['line'] - cell['line_start']
451+
diagnostic['range']['start']['line'] = start_line - cell['line_start']
452+
diagnostic['range']['end']['line'] = end_line - cell['line_start']
451453
cell_diagnostics.append(diagnostic)
452454

453455
workspace.publish_diagnostics(cell['uri'], cell_diagnostics)
@@ -528,6 +530,7 @@ def m_notebook_document__did_change(self, notebookDocument=None, change=None, **
528530
# Cell documents
529531
for cell_document in structure['didClose']:
530532
workspace.rm_document(cell_document['uri'])
533+
workspace.publish_diagnostics(cell_document['uri'], [])
531534
# Cell metadata which is removed from Notebook
532535
workspace.remove_notebook_cells(notebookDocument['uri'], start, cell_delete_count)
533536

0 commit comments

Comments
 (0)