@@ -345,7 +345,7 @@ class NBIInlineCompletionProvider
345345 get schema ( ) : ISettingRegistry . IProperty {
346346 return {
347347 default : {
348- debouncerDelay : 200 ,
348+ debouncerDelay : 100 ,
349349 timeout : 15000
350350 }
351351 } ;
@@ -438,7 +438,6 @@ class NBIInlineCompletionProvider
438438 editorType
439439 }
440440 } ) ;
441-
442441 return new Promise ( ( resolve , reject ) => {
443442 const items : IInlineCompletionItem [ ] = [ ] ;
444443
@@ -453,11 +452,35 @@ class NBIInlineCompletionProvider
453452 RequestDataType . CancelInlineCompletionRequest ,
454453 { chatId : this . _lastRequestInfo . chatId }
455454 ) ;
455+
456+ if (
457+ this . _lastRequestInfo . completion &&
458+ preCursor . length > 0 &&
459+ preCursor [ preCursor . length - 1 ] ===
460+ this . _lastRequestInfo . completion [ 0 ]
461+ ) {
462+ // if the last element of the preCursor is the first element of the completion
463+ // we do not need to make a completion request on the assumption that the
464+ // user is about to type the rest of the completion
465+ resolve ( {
466+ items : [
467+ { insertText : this . _lastRequestInfo . completion . substring ( 1 ) }
468+ ]
469+ } ) ;
470+ this . _lastRequestInfo . completion =
471+ this . _lastRequestInfo . completion . substring ( 1 ) ;
472+ return ;
473+ }
456474 }
457475
458476 const messageId = UUID . uuid4 ( ) ;
459477 const chatId = UUID . uuid4 ( ) ;
460- this . _lastRequestInfo = { chatId, messageId, requestTime : new Date ( ) } ;
478+ this . _lastRequestInfo = {
479+ chatId,
480+ messageId,
481+ completion : '' ,
482+ requestTime : new Date ( )
483+ } ;
461484
462485 NBIAPI . inlineCompletionsRequest (
463486 chatId ,
@@ -475,6 +498,7 @@ class NBIInlineCompletionProvider
475498 items . push ( {
476499 insertText : response . data . completions
477500 } ) ;
501+ this . _lastRequestInfo . completion = response . data . completions ;
478502
479503 const timeElapsed =
480504 ( new Date ( ) . getTime ( ) -
@@ -518,6 +542,7 @@ class NBIInlineCompletionProvider
518542 private _lastRequestInfo : {
519543 chatId : string ;
520544 messageId : string ;
545+ completion : string ;
521546 requestTime : Date ;
522547 } = null ;
523548 private _telemetryEmitter : TelemetryEmitter ;
@@ -721,7 +746,7 @@ const plugin: JupyterFrontEndPlugin<INotebookIntelligence> = {
721746 } )
722747 . catch ( reason => {
723748 console . error (
724- 'Failed to load settings for @notebook-intelligence/lab-notebook-intelligence.' ,
749+ 'Failed to load settings for @lab- notebook-intelligence/lab-notebook-intelligence.' ,
725750 reason
726751 ) ;
727752 } ) ;
0 commit comments