@@ -20,7 +20,7 @@ import { ILSPAdapterManager, ILSPLogConsole } from '../../tokens';
20
20
import { NotebookAdapter } from '../../adapters/notebook/notebook' ;
21
21
import { ILSPCompletionThemeManager } from '@krassowski/completion-theme/lib/types' ;
22
22
import { LSPCompletionRenderer } from './renderer' ;
23
- import { IRenderMime , IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
23
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime' ;
24
24
25
25
export class CompletionCM extends CodeMirrorIntegration {
26
26
private _completionCharacters : string [ ] ;
@@ -80,7 +80,6 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
80
80
protected current_completion_handler : CompletionHandler ;
81
81
protected current_adapter : WidgetAdapter < IDocumentWidget > = null ;
82
82
protected renderer : LSPCompletionRenderer ;
83
- private markdown_renderer : IRenderMime . IRenderer ;
84
83
85
84
constructor (
86
85
private app : JupyterFrontEnd ,
@@ -91,7 +90,14 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
91
90
private console : ILSPLogConsole ,
92
91
private renderMimeRegistry : IRenderMimeRegistry
93
92
) {
94
- this . renderer = new LSPCompletionRenderer ( { integrator : this } ) ;
93
+ const markdown_renderer = this . renderMimeRegistry . createRenderer (
94
+ 'text/markdown'
95
+ ) ;
96
+ this . renderer = new LSPCompletionRenderer ( {
97
+ integrator : this ,
98
+ markdownRenderer : markdown_renderer ,
99
+ console : console . scope ( 'renderer' )
100
+ } ) ;
95
101
this . renderer . activeChanged . connect ( this . active_completion_changed , this ) ;
96
102
adapterManager . adapterChanged . connect ( this . swap_adapter , this ) ;
97
103
settings . changed . connect ( ( ) => {
@@ -100,10 +106,6 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
100
106
this . settings . composite . typesMap
101
107
) ;
102
108
} ) ;
103
-
104
- this . markdown_renderer = this . renderMimeRegistry . createRenderer (
105
- 'text/markdown'
106
- ) ;
107
109
}
108
110
109
111
active_completion_changed (
@@ -190,6 +192,7 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
190
192
}
191
193
this . set_completion_connector ( adapter , editor_changed . editor ) ;
192
194
this . current_completion_handler . editor = editor_changed . editor ;
195
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
193
196
// @ts -ignore
194
197
this . current_completion_handler . connector = this . current_completion_connector ;
195
198
}
@@ -202,7 +205,8 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
202
205
// (note: not trivial as _markup() does filtering too)
203
206
const items = completer . model . completionItems ( ) ;
204
207
205
- // TODO upstream: Completer will have getActiveItem()
208
+ // TODO upstream: add getActiveItem() to Completer
209
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
206
210
// @ts -ignore
207
211
const index = completer . _activeIndex ;
208
212
const active : CompletionHandler . ICompletionItem = items [ index ] ;
@@ -214,25 +218,14 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
214
218
if ( item . documentation ) {
215
219
let docPanel = completer . node . querySelector ( '.jp-Completer-docpanel' ) ;
216
220
221
+ // remove all children
222
+ docPanel . textContent = '' ;
217
223
// TODO upstream: renderer should take care of the documentation rendering
218
224
// sent PR: https://github.com/jupyterlab/jupyterlab/pull/9663
219
- if ( item . isDocumentationMarkdown ) {
220
- this . markdown_renderer
221
- . renderModel ( {
222
- data : {
223
- 'text/markdown' : item . documentation
224
- } ,
225
- trusted : false ,
226
- metadata : { } ,
227
- setData ( options : IRenderMime . IMimeModel . ISetDataOptions ) { }
228
- } )
229
- . catch ( this . console . warn ) ;
230
- // remove all children
231
- docPanel . textContent = '' ;
232
- docPanel . appendChild ( this . markdown_renderer . node ) ;
233
- } else {
234
- docPanel . textContent = item . documentation ;
235
- }
225
+
226
+ const node = this . renderer . createDocumentationNode ( item ) ;
227
+ docPanel . appendChild ( node ) ;
228
+
236
229
docPanel . setAttribute ( 'style' , '' ) ;
237
230
}
238
231
}
0 commit comments