@@ -57,6 +57,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
5757 protected settings : IFeatureSettings < LSPDiagnosticsSettings > ;
5858 protected console = new BrowserConsole ( ) . scope ( 'Diagnostics' ) ;
5959 private _responseReceived : PromiseDelegate < void > = new PromiseDelegate ( ) ;
60+ private _firstResponseReceived : PromiseDelegate < void > = new PromiseDelegate ( ) ;
6061 private _diagnosticsDatabases = new WeakMap <
6162 WidgetLSPAdapter < any > ,
6263 DiagnosticsDatabase
@@ -96,6 +97,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
9697 return value ;
9798 }
9899 } ) ;
100+
99101 const connectionManager = options . connectionManager ;
100102 // https://github.com/jupyterlab/jupyterlab/issues/14783
101103 options . shell . currentChanged . connect ( shell => {
@@ -143,14 +145,30 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
143145 // few seconds to trigger timeout). Because `response.version` is
144146 // optional it would require further testing.
145147
146- await adapter . updateFinished ;
147- await this . _responseReceived . promise ;
148+ if ( view . state . field ( this . _invalidationCounter ) == 0 ) {
149+ // If we are displaying the editor for the first time,
150+ // e.g. after scrolling down in windowed notebook,
151+ // do not wait for next update, show what we already know.
152+
153+ // TODO: this still fails when scrolling down fast and then
154+ // scrolling up to the skipped cells because the state invlidation
155+ // counter kicks in but diagnostics does not get rendered yet before
156+ // we leave..
157+ await this . _firstResponseReceived . promise ;
158+ } else {
159+ await adapter . updateFinished ;
160+ await this . _responseReceived . promise ;
161+ }
148162
149163 const database = this . getDiagnosticsDB ( adapter ) ;
150164
151165 for ( const editorDiagnostics of database . values ( ) ) {
152166 for ( const editorDiagnostic of editorDiagnostics ) {
153- if ( editorDiagnostic . editor . editor !== view ) {
167+ const editor = editorDiagnostic . editorAccessor . getEditor ( ) as
168+ | CodeMirrorEditor
169+ | undefined ;
170+
171+ if ( editor ?. editor !== view ) {
154172 continue ;
155173 }
156174 const diagnostic = editorDiagnostic . diagnostic ;
@@ -165,7 +183,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
165183 editorDiagnostic . range . end
166184 ) ;
167185
168- const from = editorDiagnostic . editor . getOffsetAt (
186+ const from = editor . getOffsetAt (
169187 start . line >= lines
170188 ? {
171189 line : Math . min ( start . line , lines ) ,
@@ -174,7 +192,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
174192 : start
175193 ) ;
176194 // TODO: this is wrong; there is however an issue if this is not applied
177- const to = editorDiagnostic . editor . getOffsetAt (
195+ const to = editor . getOffsetAt (
178196 end . line >= lines
179197 ? {
180198 line : Math . min ( end . line , lines ) ,
@@ -451,7 +469,6 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
451469 }
452470
453471 const editorAccessor = document . getEditorAtVirtualLine ( start ) ;
454- const editor = editorAccessor . getEditor ( ) ! ;
455472
456473 const startInEditor = document . transformVirtualToEditor ( start ) ;
457474 let endInEditor : IEditorPosition | null ;
@@ -483,7 +500,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
483500 for ( let diagnostic of diagnostics ) {
484501 diagnosticsList . push ( {
485502 diagnostic,
486- editor : editor as CodeMirrorEditor ,
503+ editorAccessor : editorAccessor ,
487504 range : {
488505 start : startInEditor ,
489506 end : endInEditor
@@ -497,10 +514,12 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
497514
498515 const previousList = diagnosticsDB . get ( document ) ;
499516 const editorsWhichHadDiagnostics = new Set (
500- previousList ?. map ( d => d . editor )
517+ previousList ?. map ( d => d . editorAccessor . getEditor ( ) )
501518 ) ;
502519
503- const editorsWithDiagnostics = new Set ( diagnosticsList ?. map ( d => d . editor ) ) ;
520+ const editorsWithDiagnostics = new Set (
521+ diagnosticsList ?. map ( d => d . editorAccessor . getEditor ( ) )
522+ ) ;
504523 diagnosticsDB . set ( document , diagnosticsList ) ;
505524
506525 // Refresh editors with diagnostics; this is needed because linter's
@@ -548,6 +567,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
548567 this . setDiagnostics ( response , document , adapter ) ;
549568 const done = new Promise < void > ( resolve => {
550569 setTimeout ( ( ) => {
570+ this . _firstResponseReceived . resolve ( ) ;
551571 this . _responseReceived . resolve ( ) ;
552572 this . _responseReceived = new PromiseDelegate ( ) ;
553573 resolve ( ) ;
0 commit comments