Skip to content

Commit 9e9661b

Browse files
committed
Port diagnostics, hover, jump, signature to extensionFactory,
reduce verbosity of less important logs which give false positives.
1 parent a4e820b commit 9e9661b

File tree

5 files changed

+31
-92
lines changed

5 files changed

+31
-92
lines changed

packages/jupyterlab-lsp/src/features/diagnostics/feature.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,12 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
150150
});
151151
}
152152

153-
options.editorExtensionRegistry.addExtension({
153+
this.extensionFactory = {
154154
name: 'lsp:diagnostics',
155-
factory: options => {
155+
factory: factoryOptions => {
156+
const { widgetAdapter: adapter } = factoryOptions;
156157
const source = async (view: EditorView) => {
157158
let diagnostics: Diagnostic[] = [];
158-
159-
const adapter = [...connectionManager.adapters.values()].find(
160-
adapter => adapter.widget.node.contains(view.contentDOM) // this is going to be problematic with the windowed notebook. Another solution is needed.
161-
);
162-
163-
if (!adapter) {
164-
this.console.debug(
165-
'No adapter found for editor by model. Maybe not registered yet?'
166-
);
167-
return [];
168-
}
169159
// NHT: `response.version` could be checked against document versions
170160
// and if non matches we could yield (raise an error or hang for a
171161
// few seconds to trigger timeout). Because `response.version` is
@@ -262,7 +252,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
262252

263253
return EditorExtensionRegistry.createImmutableExtension(extensions);
264254
}
265-
});
255+
};
266256
}
267257

268258
private _reconfigureTheme() {
@@ -482,7 +472,7 @@ export class DiagnosticsFeature extends Feature implements IDiagnosticsFeature {
482472
.get(start.line)!
483473
.skipInspect.includes(document.idPath)
484474
) {
485-
this.console.log(
475+
this.console.debug(
486476
'Ignoring inspections silenced for this document:',
487477
diagnostics,
488478
document.idPath,

packages/jupyterlab-lsp/src/features/hover.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
import { CodeEditor } from '@jupyterlab/codeeditor';
77
import {
88
CodeMirrorEditor,
9-
IEditorExtensionRegistry,
109
EditorExtensionRegistry
1110
} from '@jupyterlab/codemirror';
1211
import {
@@ -178,32 +177,23 @@ export class HoverFeature extends Feature {
178177
this.contextAssembler = options.contextAssembler;
179178

180179
this.cache = new ResponseCache(10);
181-
const connectionManager = options.connectionManager;
182180

183181
this.markManager = createMarkManager({
184182
hover: { class: 'cm-lsp-hover-available' }
185183
});
186184

187-
options.editorExtensionRegistry.addExtension({
185+
this.extensionFactory = {
188186
name: 'lsp:hover',
189-
factory: options => {
187+
factory: factoryOptions => {
188+
const { widgetAdapter: adapter } = factoryOptions;
189+
190190
const updateListener = EditorView.updateListener.of(viewUpdate => {
191191
if (viewUpdate.docChanged) {
192192
this.afterChange();
193193
}
194194
});
195195
const eventListeners = EditorView.domEventHandlers({
196196
mousemove: event => {
197-
const adapter = [...connectionManager.adapters.values()].find(
198-
adapter =>
199-
adapter.widget.node.contains(event.target as HTMLElement)
200-
);
201-
202-
if (!adapter) {
203-
this.console.warn('Adapter not found');
204-
return;
205-
}
206-
207197
// this is used to hide the tooltip on leaving cells in notebook
208198
this.updateUnderlineAndTooltip(event, adapter)
209199
?.then(keepTooltip => {
@@ -218,16 +208,6 @@ export class HoverFeature extends Feature {
218208
},
219209
// show hover after pressing the modifier key
220210
keydown: event => {
221-
const adapter = [...connectionManager.adapters.values()].find(
222-
adapter =>
223-
adapter.widget.node.contains(
224-
event.currentTarget! as HTMLElement
225-
)
226-
);
227-
if (!adapter) {
228-
this.console.warn('Adapter not found');
229-
return;
230-
}
231211
this.onKeyDown(event, adapter);
232212
}
233213
});
@@ -236,7 +216,7 @@ export class HoverFeature extends Feature {
236216
updateListener
237217
]);
238218
}
239-
});
219+
};
240220

241221
this.debouncedGetHover = this.createThrottler();
242222

@@ -752,7 +732,6 @@ export namespace HoverFeature {
752732
export interface IOptions extends Feature.IOptions {
753733
settings: FeatureSettings<LSPHoverSettings>;
754734
renderMimeRegistry: IRenderMimeRegistry;
755-
editorExtensionRegistry: IEditorExtensionRegistry;
756735
contextAssembler: ContextAssembler;
757736
}
758737
export const id = PLUGIN_ID + ':hover';
@@ -764,7 +743,6 @@ export const HOVER_PLUGIN: JupyterFrontEndPlugin<void> = {
764743
ILSPFeatureManager,
765744
ISettingRegistry,
766745
IRenderMimeRegistry,
767-
IEditorExtensionRegistry,
768746
ILSPDocumentConnectionManager
769747
],
770748
autoStart: true,
@@ -773,7 +751,6 @@ export const HOVER_PLUGIN: JupyterFrontEndPlugin<void> = {
773751
featureManager: ILSPFeatureManager,
774752
settingRegistry: ISettingRegistry,
775753
renderMimeRegistry: IRenderMimeRegistry,
776-
editorExtensionRegistry: IEditorExtensionRegistry,
777754
connectionManager: ILSPDocumentConnectionManager
778755
) => {
779756
const contextAssembler = new ContextAssembler({ app, connectionManager });
@@ -788,7 +765,6 @@ export const HOVER_PLUGIN: JupyterFrontEndPlugin<void> = {
788765
const feature = new HoverFeature({
789766
settings,
790767
renderMimeRegistry,
791-
editorExtensionRegistry,
792768
connectionManager,
793769
contextAssembler
794770
});

packages/jupyterlab-lsp/src/features/jump_to.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '@jupyterlab/apputils';
1616
import {
1717
CodeMirrorEditor,
18-
IEditorExtensionRegistry,
1918
EditorExtensionRegistry
2019
} from '@jupyterlab/codemirror';
2120
import { URLExt } from '@jupyterlab/coreutils';
@@ -106,22 +105,13 @@ export class NavigationFeature extends Feature {
106105
this.settings = options.settings;
107106
this._trans = options.trans;
108107
this.contextAssembler = options.contextAssembler;
109-
const connectionManager = options.connectionManager;
110108

111-
options.editorExtensionRegistry.addExtension({
109+
this.extensionFactory = {
112110
name: 'lsp:jump',
113-
factory: options => {
111+
factory: factoryOptions => {
112+
const { widgetAdapter: adapter } = factoryOptions;
114113
const clickListener = EditorView.domEventHandlers({
115114
mouseup: event => {
116-
const adapter = [...connectionManager.adapters.values()].find(
117-
adapter =>
118-
adapter.widget.node.contains(event.target as HTMLElement)
119-
);
120-
121-
if (!adapter) {
122-
this.console.warn('Adapter not found');
123-
return;
124-
}
125115
this._jumpOnMouseUp(event, adapter);
126116
}
127117
});
@@ -130,7 +120,7 @@ export class NavigationFeature extends Feature {
130120
clickListener
131121
]);
132122
}
133-
});
123+
};
134124

135125
this._jumpers = new Map();
136126
const { fileEditorTracker, notebookTracker, documentManager } = options;
@@ -500,7 +490,6 @@ export namespace NavigationFeature {
500490
notebookTracker: INotebookTracker;
501491
documentManager: IDocumentManager;
502492
contextAssembler: ContextAssembler;
503-
editorExtensionRegistry: IEditorExtensionRegistry;
504493
fileEditorTracker: IEditorTracker | null;
505494
}
506495
export const id = PLUGIN_ID + ':jump_to';
@@ -519,8 +508,7 @@ export const JUMP_PLUGIN: JupyterFrontEndPlugin<void> = {
519508
ISettingRegistry,
520509
ILSPDocumentConnectionManager,
521510
INotebookTracker,
522-
IDocumentManager,
523-
IEditorExtensionRegistry
511+
IDocumentManager
524512
],
525513
optional: [IEditorTracker, ICommandPalette, ITranslator],
526514
autoStart: true,
@@ -531,7 +519,6 @@ export const JUMP_PLUGIN: JupyterFrontEndPlugin<void> = {
531519
connectionManager: ILSPDocumentConnectionManager,
532520
notebookTracker: INotebookTracker,
533521
documentManager: IDocumentManager,
534-
editorExtensionRegistry: IEditorExtensionRegistry,
535522
fileEditorTracker: IEditorTracker | null,
536523
palette: ICommandPalette | null,
537524
translator: ITranslator | null
@@ -555,7 +542,6 @@ export const JUMP_PLUGIN: JupyterFrontEndPlugin<void> = {
555542
documentManager,
556543
fileEditorTracker,
557544
contextAssembler,
558-
editorExtensionRegistry,
559545
trans
560546
});
561547
featureManager.register(feature);
@@ -595,7 +581,7 @@ export const JUMP_PLUGIN: JupyterFrontEndPlugin<void> = {
595581
isEnabled: () => {
596582
const context = contextAssembler.getContext();
597583
if (!context) {
598-
console.warn('Could not get context');
584+
console.debug('Could not get context');
599585
return false;
600586
}
601587
const { connection } = context;
@@ -641,7 +627,7 @@ export const JUMP_PLUGIN: JupyterFrontEndPlugin<void> = {
641627
isEnabled: () => {
642628
const context = contextAssembler.getContext();
643629
if (!context) {
644-
console.warn('Could not get context');
630+
console.debug('Could not get context');
645631
return false;
646632
}
647633
const { connection } = context;
@@ -663,7 +649,7 @@ export const JUMP_PLUGIN: JupyterFrontEndPlugin<void> = {
663649
isEnabled: () => {
664650
const context = contextAssembler.getContext();
665651
if (!context) {
666-
console.warn('Could not get context');
652+
console.debug('Could not get context');
667653
return false;
668654
}
669655
const { connection } = context;

packages/jupyterlab-lsp/src/features/signature.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
JupyterFrontEndPlugin
77
} from '@jupyterlab/application';
88
import {
9-
IEditorExtensionRegistry,
109
EditorExtensionRegistry,
1110
IEditorLanguageRegistry,
1211
jupyterHighlightStyle
@@ -297,22 +296,13 @@ export class SignatureFeature extends Feature {
297296
this.settings = options.settings;
298297
this.tooltip = new EditorTooltipManager(options.renderMimeRegistry);
299298
this.languageRegistry = options.languageRegistry;
300-
const connectionManager = options.connectionManager;
301-
options.editorExtensionRegistry.addExtension({
299+
this.extensionFactory = {
302300
name: 'lsp:codeSignature',
303-
factory: options => {
304-
const updateListener = EditorView.updateListener.of(viewUpdate => {
305-
const adapter = [...connectionManager.adapters.values()].find(
306-
adapter => adapter.widget.node.contains(viewUpdate.view.contentDOM)
307-
);
308-
309-
if (!adapter) {
310-
this.console.log('No adapter, will not show signature');
311-
return;
312-
}
301+
factory: factoryOptions => {
302+
const { editor: editorAccessor, widgetAdapter: adapter } =
303+
factoryOptions;
313304

314-
// 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.
315-
const editorAccessor = adapter.activeEditor;
305+
const updateListener = EditorView.updateListener.of(viewUpdate => {
316306
const editor = editorAccessor!.getEditor();
317307

318308
if (!editor) {
@@ -364,7 +354,7 @@ export class SignatureFeature extends Feature {
364354
focusListener
365355
]);
366356
}
367-
});
357+
};
368358
}
369359

370360
get _closeCharacters(): string[] {
@@ -712,7 +702,6 @@ export namespace SignatureFeature {
712702
export interface IOptions extends Feature.IOptions {
713703
settings: FeatureSettings<LSPSignatureSettings>;
714704
renderMimeRegistry: IRenderMimeRegistry;
715-
editorExtensionRegistry: IEditorExtensionRegistry;
716705
languageRegistry: IEditorLanguageRegistry;
717706
}
718707
export const id = PLUGIN_ID + ':signature';
@@ -724,7 +713,6 @@ export const SIGNATURE_PLUGIN: JupyterFrontEndPlugin<void> = {
724713
ILSPFeatureManager,
725714
ISettingRegistry,
726715
IRenderMimeRegistry,
727-
IEditorExtensionRegistry,
728716
ILSPDocumentConnectionManager,
729717
IEditorLanguageRegistry
730718
],
@@ -734,7 +722,6 @@ export const SIGNATURE_PLUGIN: JupyterFrontEndPlugin<void> = {
734722
featureManager: ILSPFeatureManager,
735723
settingRegistry: ISettingRegistry,
736724
renderMimeRegistry: IRenderMimeRegistry,
737-
editorExtensionRegistry: IEditorExtensionRegistry,
738725
connectionManager: ILSPDocumentConnectionManager,
739726
languageRegistry: IEditorLanguageRegistry
740727
) => {
@@ -750,7 +737,6 @@ export const SIGNATURE_PLUGIN: JupyterFrontEndPlugin<void> = {
750737
settings,
751738
connectionManager,
752739
renderMimeRegistry,
753-
editorExtensionRegistry,
754740
languageRegistry
755741
});
756742
featureManager.register(feature);

packages/jupyterlab-lsp/src/features/syntax_highlighting.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,17 @@ export class SyntaxHighlightingFeature extends Feature {
4646
factory: factoryOptions => {
4747
const { editor: editorAccessor, widgetAdapter: adapter } =
4848
factoryOptions;
49+
const allReady = Promise.all([editorAccessor.ready, adapter.ready]);
4950

5051
const updateHandler = async (awaitUpdate = true) => {
51-
await adapter.ready;
52-
52+
await allReady;
5353
await this.updateMode(adapter, editorAccessor, awaitUpdate);
5454
};
5555

5656
const updateListener = EditorView.updateListener.of(async () => {
5757
await updateHandler();
5858
});
59-
Promise.all([editorAccessor.ready, adapter.ready])
60-
.then(() => updateHandler(false))
61-
.catch(console.warn);
59+
allReady.then(() => updateHandler(false)).catch(console.warn);
6260

6361
// update the mode at first update even if no changes to ensure the
6462
// correct mode gets applied on load.
@@ -110,7 +108,10 @@ export class SyntaxHighlightingFeature extends Feature {
110108
await topDocument.updateManager.updateDone;
111109
}
112110

113-
const editor = editorAccessor.getEditor()! as CodeMirrorEditor;
111+
const editor = editorAccessor.getEditor() as CodeMirrorEditor | null;
112+
if (!editor) {
113+
return;
114+
}
114115
const totalArea = editor.state.doc.length;
115116

116117
const overrides = new Map();

0 commit comments

Comments
 (0)