@@ -434,23 +434,25 @@ def _lint_notebook_document(self, notebook_document, workspace): # pylint: dis
434
434
offset += num_lines
435
435
436
436
workspace .put_document (random_uri , total_source )
437
- document_diagnostics = flatten (self ._hook ('pylsp_lint' , random_uri , is_saved = True ))
438
-
439
- # Now we need to map the diagnostics back to the correct cell and publish them.
440
- # Note: this is O(n*m) in the number of cells and diagnostics, respectively.
441
- for cell in cell_list :
442
- cell_diagnostics = []
443
- for diagnostic in document_diagnostics :
444
- if diagnostic ['range' ]['start' ]['line' ] > cell ['line_end' ] \
445
- or diagnostic ['range' ]['end' ]['line' ] < cell ['line_start' ]:
446
- continue
447
- diagnostic ['range' ]['start' ]['line' ] = diagnostic ['range' ]['start' ]['line' ] - cell ['line_start' ]
448
- diagnostic ['range' ]['end' ]['line' ] = diagnostic ['range' ]['end' ]['line' ] - cell ['line_start' ]
449
- cell_diagnostics .append (diagnostic )
450
-
451
- workspace .publish_diagnostics (cell ['uri' ], cell_diagnostics )
452
437
453
- workspace .rm_document (random_uri )
438
+ try :
439
+ document_diagnostics = flatten (self ._hook ('pylsp_lint' , random_uri , is_saved = True ))
440
+
441
+ # Now we need to map the diagnostics back to the correct cell and publish them.
442
+ # Note: this is O(n*m) in the number of cells and diagnostics, respectively.
443
+ for cell in cell_list :
444
+ cell_diagnostics = []
445
+ for diagnostic in document_diagnostics :
446
+ if diagnostic ['range' ]['start' ]['line' ] > cell ['line_end' ] \
447
+ or diagnostic ['range' ]['end' ]['line' ] < cell ['line_start' ]:
448
+ 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
+ cell_diagnostics .append (diagnostic )
452
+
453
+ workspace .publish_diagnostics (cell ['uri' ], cell_diagnostics )
454
+ finally :
455
+ workspace .rm_document (random_uri )
454
456
455
457
def references (self , doc_uri , position , exclude_declaration ):
456
458
return flatten (self ._hook (
0 commit comments