@@ -434,21 +434,16 @@ export class Ddc {
434434 return true ;
435435 }
436436
437- const [ ui , uiOptions , uiParams ] = await this . #getUi(
438- denops ,
439- context ,
440- options ,
441- ) ;
442- if ( ! ui ) {
443- return true ;
437+ if ( ! this . currentUi ) {
438+ return false ;
444439 }
445440
446- return await ui . skipCompletion ( {
441+ return await this . currentUi . skipCompletion ( {
447442 denops,
448443 context,
449444 options,
450- uiOptions,
451- uiParams,
445+ uiOptions : this . currentUiOptions ,
446+ uiParams : this . currentUiParams ,
452447 } ) ;
453448 }
454449
@@ -499,6 +494,29 @@ export class Ddc {
499494 options . ui = dynamicUi ;
500495 }
501496
497+ const [ ui , uiOptions , uiParams ] = await getUi (
498+ denops ,
499+ this . #loader,
500+ options ,
501+ ) ;
502+
503+ if ( ui !== this . currentUi ) {
504+ // UI is changed
505+ if ( this . currentUi ) {
506+ await this . currentUi . hide ( {
507+ denops,
508+ context,
509+ options,
510+ uiOptions : this . currentUiOptions ,
511+ uiParams : this . currentUiParams ,
512+ } ) ;
513+ }
514+
515+ this . currentUi = ui ;
516+ this . currentUiOptions = uiOptions ;
517+ this . currentUiParams = uiParams ;
518+ }
519+
502520 await ( async function write ( ddc : Ddc ) {
503521 await batch ( denops , async ( denops : Denops ) => {
504522 await vars . g . set ( denops , "ddc#_changedtick" , context . changedTick ) ;
@@ -535,23 +553,18 @@ export class Ddc {
535553 completePos : number ,
536554 items : DdcItem [ ] ,
537555 ) {
538- const [ ui , uiOptions , uiParams ] = await this . #getUi(
539- denops ,
540- context ,
541- options ,
542- ) ;
543- if ( ! ui ) {
556+ if ( ! this . currentUi ) {
544557 return ;
545558 }
546559
547- await ui . show ( {
560+ await this . currentUi . show ( {
548561 denops,
549562 context,
550563 options,
551564 completePos,
552565 items,
553- uiOptions,
554- uiParams,
566+ uiOptions : this . currentUiOptions ,
567+ uiParams : this . currentUiParams ,
555568 } ) ;
556569
557570 this . #prevUi = options . ui ;
@@ -564,22 +577,18 @@ export class Ddc {
564577 context : Context ,
565578 options : DdcOptions ,
566579 ) {
567- const [ ui , uiOptions , uiParams ] = await this . #getUi(
568- denops ,
569- context ,
570- options ,
571- ) ;
572- if ( ! ui ) {
580+ if ( ! this . currentUi ) {
573581 return ;
574582 }
575583
576- await ui . hide ( {
584+ await this . currentUi . hide ( {
577585 denops,
578586 context,
579587 options,
580- uiOptions,
581- uiParams,
588+ uiOptions : this . currentUiOptions ,
589+ uiParams : this . currentUiParams ,
582590 } ) ;
591+
583592 this . visibleUi = false ;
584593 this . #prevEvent = "" ;
585594 }
@@ -593,56 +602,22 @@ export class Ddc {
593602 return true ;
594603 }
595604
596- const [ ui , uiOptions , uiParams ] = await this . #getUi(
597- denops ,
598- context ,
599- options ,
600- ) ;
601- if ( ! ui ) {
605+ if ( ! this . currentUi ) {
602606 return false ;
603607 }
604608
605609 // Check UI is visible
606610 // NOTE: UI may be closed by users
607- return ui . visible
608- ? ui . visible ( {
611+ return this . currentUi . visible
612+ ? await this . currentUi . visible ( {
609613 denops,
610614 context,
611615 options,
612- uiOptions,
613- uiParams,
616+ uiOptions : this . currentUiOptions ,
617+ uiParams : this . currentUiParams ,
614618 } )
615619 : true ;
616620 }
617-
618- async #getUi(
619- denops : Denops ,
620- context : Context ,
621- options : DdcOptions ,
622- ) : Promise < [ BaseUi < BaseParams > | undefined , UiOptions , BaseParams ] > {
623- const [ ui , uiOptions , uiParams ] = await getUi (
624- denops ,
625- this . #loader,
626- options ,
627- ) ;
628- if ( ui !== this . currentUi ) {
629- // UI is changed
630- if ( this . currentUi ) {
631- await this . currentUi . hide ( {
632- denops,
633- context,
634- options,
635- uiOptions : this . currentUiOptions ,
636- uiParams : this . currentUiParams ,
637- } ) ;
638- }
639-
640- this . currentUi = ui ;
641- this . currentUiOptions = uiOptions ;
642- this . currentUiParams = uiParams ;
643- }
644- return [ ui , uiOptions , uiParams ] ;
645- }
646621}
647622
648623function formatAbbr ( word : string , abbr : string | undefined ) : string {
0 commit comments