@@ -6,15 +6,15 @@ import {
6
6
import { CodeEditor } from '@jupyterlab/codeeditor' ;
7
7
import {
8
8
CodeMirrorEditor ,
9
- IEditorExtensionRegistry ,
10
9
EditorExtensionRegistry
11
10
} from '@jupyterlab/codemirror' ;
12
11
import {
13
12
IVirtualPosition ,
14
13
ILSPFeatureManager ,
15
14
IEditorPosition ,
16
15
ILSPDocumentConnectionManager ,
17
- WidgetLSPAdapter
16
+ WidgetLSPAdapter ,
17
+ Document
18
18
} from '@jupyterlab/lsp' ;
19
19
import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
20
20
import { LabIcon } from '@jupyterlab/ui-components' ;
@@ -23,7 +23,6 @@ import type * as lsProtocol from 'vscode-languageserver-protocol';
23
23
24
24
import highlightSvg from '../../style/icons/highlight.svg' ;
25
25
import { CodeHighlights as LSPHighlightsSettings } from '../_highlights' ;
26
- import { ContextAssembler } from '../context' ;
27
26
import {
28
27
PositionConverter ,
29
28
rootPositionToVirtualPosition ,
@@ -78,7 +77,6 @@ export class HighlightsFeature extends Feature {
78
77
constructor ( options : HighlightsFeature . IOptions ) {
79
78
super ( options ) ;
80
79
this . settings = options . settings ;
81
- const connectionManager = options . connectionManager ;
82
80
this . markManager = createMarkManager ( {
83
81
[ DocumentHighlightKind . Text ] : { class : 'cm-lsp-highlight-Text' } ,
84
82
[ DocumentHighlightKind . Read ] : { class : 'cm-lsp-highlight-Read' } ,
@@ -91,63 +89,43 @@ export class HighlightsFeature extends Feature {
91
89
this . _debouncedGetHighlight = this . createDebouncer ( ) ;
92
90
} ) ;
93
91
94
- options . editorExtensionRegistry . addExtension ( {
92
+ this . extensionFactory = {
95
93
name : 'lsp:highlights' ,
96
- factory : options => {
94
+ factory : factoryOptions => {
95
+ const { editor : editorAccessor , widgetAdapter : adapter } =
96
+ factoryOptions ;
97
97
const updateListener = EditorView . updateListener . of ( viewUpdate => {
98
98
if (
99
99
viewUpdate . docChanged ||
100
100
viewUpdate . selectionSet ||
101
101
viewUpdate . focusChanged
102
102
) {
103
- // TODO a better way to get the adapter here?
104
- const adapter = [ ...connectionManager . adapters . values ( ) ] . find (
105
- adapter => adapter . widget . node . contains ( viewUpdate . view . dom )
103
+ this . onCursorActivity ( editorAccessor , adapter ) . catch (
104
+ this . console . warn
106
105
) ;
107
- if ( ! adapter ) {
108
- this . console . warn ( 'Adapter not found' ) ;
109
- return ;
110
- }
111
- this . onCursorActivity ( adapter ) . catch ( this . console . warn ) ;
112
106
}
113
107
} ) ;
114
108
const eventListeners = EditorView . domEventHandlers ( {
115
- blur : ( e , view ) => {
109
+ blur : ( _ , view ) => {
116
110
this . onBlur ( view ) ;
117
111
} ,
118
- focus : event => {
119
- const adapter = [ ...connectionManager . adapters . values ( ) ] . find (
120
- adapter =>
121
- adapter . widget . node . contains (
122
- event . currentTarget ! as HTMLElement
123
- )
112
+ focus : ( ) => {
113
+ this . onCursorActivity ( editorAccessor , adapter ) . catch (
114
+ this . console . warn
124
115
) ;
125
- if ( ! adapter ) {
126
- this . console . warn ( 'Adapter not found' ) ;
127
- return ;
128
- }
129
- this . onCursorActivity ( adapter ) . catch ( this . console . warn ) ;
130
116
} ,
131
- keydown : event => {
132
- const adapter = [ ...connectionManager . adapters . values ( ) ] . find (
133
- adapter =>
134
- adapter . widget . node . contains (
135
- event . currentTarget ! as HTMLElement
136
- )
117
+ keydown : ( ) => {
118
+ this . onCursorActivity ( editorAccessor , adapter ) . catch (
119
+ this . console . warn
137
120
) ;
138
- if ( ! adapter ) {
139
- this . console . warn ( 'Adapter not found' ) ;
140
- return ;
141
- }
142
- this . onCursorActivity ( adapter ) . catch ( this . console . warn ) ;
143
121
}
144
122
} ) ;
145
123
return EditorExtensionRegistry . createImmutableExtension ( [
146
124
updateListener ,
147
125
eventListeners
148
126
] ) ;
149
127
}
150
- } ) ;
128
+ } ;
151
129
}
152
130
153
131
protected onBlur ( view : EditorView ) {
@@ -260,17 +238,21 @@ export class HighlightsFeature extends Feature {
260
238
} ) ;
261
239
} ;
262
240
263
- protected async onCursorActivity ( adapter : WidgetLSPAdapter < any > ) {
241
+ protected async onCursorActivity (
242
+ editorAccessor : Document . IEditor ,
243
+ adapter : WidgetLSPAdapter < any >
244
+ ) {
264
245
if ( ! adapter . virtualDocument ) {
265
246
this . console . log ( 'virtualDocument not ready on adapter' ) ;
266
247
return ;
267
248
}
268
249
await adapter . virtualDocument ! . updateManager . updateDone ;
269
250
270
- // TODO: this is the same problem as in signature
271
- // TODO: the assumption that updated editor = active editor will fail on RTC. How to get `CodeEditor.IEditor` and `Document.IEditor` from `EditorView`? we got `CodeEditor.IModel` from `options.model` but may need more context here.
272
- const editorAccessor = adapter . activeEditor ;
273
- const editor = editorAccessor ! . getEditor ( ) ! ;
251
+ const editor = editorAccessor . getEditor ( ) ;
252
+ if ( ! editor ) {
253
+ this . console . log ( 'editor not found ready' ) ;
254
+ return ;
255
+ }
274
256
const position = editor . getCursorPosition ( ) ;
275
257
const editorPosition = PositionConverter . ce_to_cm (
276
258
position
@@ -370,8 +352,6 @@ export class HighlightsFeature extends Feature {
370
352
export namespace HighlightsFeature {
371
353
export interface IOptions extends Feature . IOptions {
372
354
settings : FeatureSettings < LSPHighlightsSettings > ;
373
- editorExtensionRegistry : IEditorExtensionRegistry ;
374
- contextAssembler : ContextAssembler ;
375
355
}
376
356
export const id = PLUGIN_ID + ':highlights' ;
377
357
}
@@ -381,18 +361,15 @@ export const HIGHLIGHTS_PLUGIN: JupyterFrontEndPlugin<void> = {
381
361
requires : [
382
362
ILSPFeatureManager ,
383
363
ISettingRegistry ,
384
- IEditorExtensionRegistry ,
385
364
ILSPDocumentConnectionManager
386
365
] ,
387
366
autoStart : true ,
388
367
activate : async (
389
368
app : JupyterFrontEnd ,
390
369
featureManager : ILSPFeatureManager ,
391
370
settingRegistry : ISettingRegistry ,
392
- editorExtensionRegistry : IEditorExtensionRegistry ,
393
371
connectionManager : ILSPDocumentConnectionManager
394
372
) => {
395
- const contextAssembler = new ContextAssembler ( { app, connectionManager } ) ;
396
373
const settings = new FeatureSettings < LSPHighlightsSettings > (
397
374
settingRegistry ,
398
375
HighlightsFeature . id
@@ -403,9 +380,7 @@ export const HIGHLIGHTS_PLUGIN: JupyterFrontEndPlugin<void> = {
403
380
}
404
381
const feature = new HighlightsFeature ( {
405
382
settings,
406
- editorExtensionRegistry,
407
- connectionManager,
408
- contextAssembler
383
+ connectionManager
409
384
} ) ;
410
385
featureManager . register ( feature ) ;
411
386
}
0 commit comments