@@ -34,13 +34,17 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
3434 private readonly model = this . _register ( new MutableDisposable < ParameterHintsModel > ( ) ) ;
3535 private readonly keyVisible : IContextKey < boolean > ;
3636 private readonly keyMultipleSignatures : IContextKey < boolean > ;
37- private element : HTMLElement ;
38- private signature : HTMLElement ;
39- private docs : HTMLElement ;
40- private overloads : HTMLElement ;
41- private visible : boolean ;
42- private announcedLabel : string | null ;
43- private scrollbar : DomScrollableElement ;
37+
38+ private domNodes ?: {
39+ readonly element : HTMLElement ;
40+ readonly signature : HTMLElement ;
41+ readonly docs : HTMLElement ;
42+ readonly overloads : HTMLElement ;
43+ readonly scrollbar : DomScrollableElement ;
44+ } ;
45+
46+ private visible : boolean = false ;
47+ private announcedLabel : string | null = null ;
4448
4549 // Editor.IContentWidget.allowEditorOverflow
4650 allowEditorOverflow = true ;
@@ -56,7 +60,6 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
5660 this . model . value = new ParameterHintsModel ( editor ) ;
5761 this . keyVisible = Context . Visible . bindTo ( contextKeyService ) ;
5862 this . keyMultipleSignatures = Context . MultipleSignatures . bindTo ( contextKeyService ) ;
59- this . visible = false ;
6063
6164 this . _register ( this . model . value . onChangedHints ( newParameterHints => {
6265 if ( newParameterHints ) {
@@ -69,8 +72,8 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
6972 }
7073
7174 private createParamaterHintDOMNodes ( ) {
72- this . element = $ ( '.editor-widget.parameter-hints-widget' ) ;
73- const wrapper = dom . append ( this . element , $ ( '.wrapper' ) ) ;
75+ const element = $ ( '.editor-widget.parameter-hints-widget' ) ;
76+ const wrapper = dom . append ( element , $ ( '.wrapper' ) ) ;
7477 wrapper . tabIndex = - 1 ;
7578
7679 const buttons = dom . append ( wrapper , $ ( '.buttons' ) ) ;
@@ -83,30 +86,41 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
8386 const onNextClick = stop ( domEvent ( next , 'click' ) ) ;
8487 this . _register ( onNextClick ( this . next , this ) ) ;
8588
86- this . overloads = dom . append ( wrapper , $ ( '.overloads' ) ) ;
89+ const overloads = dom . append ( wrapper , $ ( '.overloads' ) ) ;
8790
8891 const body = $ ( '.body' ) ;
89- this . scrollbar = new DomScrollableElement ( body , { } ) ;
90- this . _register ( this . scrollbar ) ;
91- wrapper . appendChild ( this . scrollbar . getDomNode ( ) ) ;
92+ const scrollbar = new DomScrollableElement ( body , { } ) ;
93+ this . _register ( scrollbar ) ;
94+ wrapper . appendChild ( scrollbar . getDomNode ( ) ) ;
9295
93- this . signature = dom . append ( body , $ ( '.signature' ) ) ;
96+ const signature = dom . append ( body , $ ( '.signature' ) ) ;
97+ const docs = dom . append ( body , $ ( '.docs' ) ) ;
9498
95- this . docs = dom . append ( body , $ ( '.docs' ) ) ;
99+ element . style . userSelect = 'text' ;
100+
101+ this . domNodes = {
102+ element,
103+ signature,
104+ overloads,
105+ docs,
106+ scrollbar,
107+ } ;
96108
97109 this . editor . addContentWidget ( this ) ;
98110 this . hide ( ) ;
99111
100- this . element . style . userSelect = 'text' ;
101112 this . _register ( this . editor . onDidChangeCursorSelection ( e => {
102113 if ( this . visible ) {
103114 this . editor . layoutContentWidget ( this ) ;
104115 }
105116 } ) ) ;
106117
107118 const updateFont = ( ) => {
119+ if ( ! this . domNodes ) {
120+ return ;
121+ }
108122 const fontInfo = this . editor . getOption ( EditorOption . fontInfo ) ;
109- this . element . style . fontSize = `${ fontInfo . fontSize } px` ;
123+ this . domNodes . element . style . fontSize = `${ fontInfo . fontSize } px` ;
110124 } ;
111125
112126 updateFont ( ) ;
@@ -124,13 +138,17 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
124138 return ;
125139 }
126140
127- if ( ! this . element ) {
141+ if ( ! this . domNodes ) {
128142 this . createParamaterHintDOMNodes ( ) ;
129143 }
130144
131145 this . keyVisible . set ( true ) ;
132146 this . visible = true ;
133- setTimeout ( ( ) => dom . addClass ( this . element , 'visible' ) , 100 ) ;
147+ setTimeout ( ( ) => {
148+ if ( this . domNodes ) {
149+ dom . addClass ( this . domNodes . element , 'visible' ) ;
150+ }
151+ } , 100 ) ;
134152 this . editor . layoutContentWidget ( this ) ;
135153 }
136154
@@ -139,14 +157,12 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
139157 return ;
140158 }
141159
142- if ( ! this . element ) {
143- this . createParamaterHintDOMNodes ( ) ;
144- }
145-
146160 this . keyVisible . reset ( ) ;
147161 this . visible = false ;
148162 this . announcedLabel = null ;
149- dom . removeClass ( this . element , 'visible' ) ;
163+ if ( this . domNodes ) {
164+ dom . removeClass ( this . domNodes . element , 'visible' ) ;
165+ }
150166 this . editor . layoutContentWidget ( this ) ;
151167 }
152168
@@ -161,20 +177,24 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
161177 }
162178
163179 private render ( hints : modes . SignatureHelp ) : void {
180+ if ( ! this . domNodes ) {
181+ return ;
182+ }
183+
164184 const multiple = hints . signatures . length > 1 ;
165- dom . toggleClass ( this . element , 'multiple' , multiple ) ;
185+ dom . toggleClass ( this . domNodes . element , 'multiple' , multiple ) ;
166186 this . keyMultipleSignatures . set ( multiple ) ;
167187
168- this . signature . innerHTML = '' ;
169- this . docs . innerHTML = '' ;
188+ this . domNodes . signature . innerHTML = '' ;
189+ this . domNodes . docs . innerHTML = '' ;
170190
171191 const signature = hints . signatures [ hints . activeSignature ] ;
172192
173193 if ( ! signature ) {
174194 return ;
175195 }
176196
177- const code = dom . append ( this . signature , $ ( '.code' ) ) ;
197+ const code = dom . append ( this . domNodes . signature , $ ( '.code' ) ) ;
178198 const hasParameters = signature . parameters . length > 0 ;
179199
180200 const fontInfo = this . editor . getOption ( EditorOption . fontInfo ) ;
@@ -203,17 +223,17 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
203223 this . renderDisposeables . add ( renderedContents ) ;
204224 documentation . appendChild ( renderedContents . element ) ;
205225 }
206- dom . append ( this . docs , $ ( 'p' , { } , documentation ) ) ;
226+ dom . append ( this . domNodes . docs , $ ( 'p' , { } , documentation ) ) ;
207227 }
208228
209229 if ( signature . documentation === undefined ) { /** no op */ }
210230 else if ( typeof signature . documentation === 'string' ) {
211- dom . append ( this . docs , $ ( 'p' , { } , signature . documentation ) ) ;
231+ dom . append ( this . domNodes . docs , $ ( 'p' , { } , signature . documentation ) ) ;
212232 } else {
213233 const renderedContents = this . markdownRenderer . render ( signature . documentation ) ;
214234 dom . addClass ( renderedContents . element , 'markdown-docs' ) ;
215235 this . renderDisposeables . add ( renderedContents ) ;
216- dom . append ( this . docs , renderedContents . element ) ;
236+ dom . append ( this . domNodes . docs , renderedContents . element ) ;
217237 }
218238
219239 let hasDocs = false ;
@@ -230,16 +250,16 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
230250 hasDocs = true ;
231251 }
232252
233- dom . toggleClass ( this . signature , 'has-docs' , hasDocs ) ;
234- dom . toggleClass ( this . docs , 'empty' , ! hasDocs ) ;
253+ dom . toggleClass ( this . domNodes . signature , 'has-docs' , hasDocs ) ;
254+ dom . toggleClass ( this . domNodes . docs , 'empty' , ! hasDocs ) ;
235255
236256 let currentOverload = String ( hints . activeSignature + 1 ) ;
237257
238258 if ( hints . signatures . length < 10 ) {
239259 currentOverload += `/${ hints . signatures . length } ` ;
240260 }
241261
242- this . overloads . textContent = currentOverload ;
262+ this . domNodes . overloads . textContent = currentOverload ;
243263
244264 if ( activeParameter ) {
245265 const labelToAnnounce = this . getParameterLabel ( signature , hints . activeParameter ) ;
@@ -253,7 +273,7 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
253273 }
254274
255275 this . editor . layoutContentWidget ( this ) ;
256- this . scrollbar . scanDomNode ( ) ;
276+ this . domNodes . scrollbar . scanDomNode ( ) ;
257277 }
258278
259279 private renderParameters ( parent : HTMLElement , signature : modes . SignatureInformation , currentParameter : number ) : void {
@@ -317,7 +337,10 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
317337 }
318338
319339 getDomNode ( ) : HTMLElement {
320- return this . element ;
340+ if ( ! this . domNodes ) {
341+ this . createParamaterHintDOMNodes ( ) ;
342+ }
343+ return this . domNodes ! . element ;
321344 }
322345
323346 getId ( ) : string {
@@ -331,10 +354,13 @@ export class ParameterHintsWidget extends Disposable implements IContentWidget,
331354 }
332355
333356 private updateMaxHeight ( ) : void {
357+ if ( ! this . domNodes ) {
358+ return ;
359+ }
334360 const height = Math . max ( this . editor . getLayoutInfo ( ) . height / 4 , 250 ) ;
335361 const maxHeight = `${ height } px` ;
336- this . element . style . maxHeight = maxHeight ;
337- const wrapper = this . element . getElementsByClassName ( 'wrapper' ) as HTMLCollectionOf < HTMLElement > ;
362+ this . domNodes . element . style . maxHeight = maxHeight ;
363+ const wrapper = this . domNodes . element . getElementsByClassName ( 'wrapper' ) as HTMLCollectionOf < HTMLElement > ;
338364 if ( wrapper . length ) {
339365 wrapper [ 0 ] . style . maxHeight = maxHeight ;
340366 }
0 commit comments