diff --git a/docs/Installation.ipynb b/docs/Installation.ipynb index 97c1e0768..ef53063b8 100644 --- a/docs/Installation.ipynb +++ b/docs/Installation.ipynb @@ -8,16 +8,19 @@ }, "outputs": [], "source": [ - "from markdown import markdown\n", "import sys\n", - "sys.path.insert(0, '..')\n", + "\n", + "from markdown import markdown\n", + "\n", "from versions import (\n", " JUPYTER_LSP_VERSION,\n", " JUPYTERLAB_LSP_VERSION,\n", " JUPYTERLAB_NEXT_MAJOR_VERSION,\n", " JUPYTERLAB_VERSION,\n", - " REQUIRED_JUPYTERLAB\n", - ")" + " REQUIRED_JUPYTERLAB,\n", + ")\n", + "\n", + "sys.path.insert(0, \"..\")" ] }, { diff --git a/packages/jupyterlab-lsp/src/adapters/codemirror/features/hover.ts b/packages/jupyterlab-lsp/src/adapters/codemirror/features/hover.ts index 536056797..05e6324fe 100644 --- a/packages/jupyterlab-lsp/src/adapters/codemirror/features/hover.ts +++ b/packages/jupyterlab-lsp/src/adapters/codemirror/features/hover.ts @@ -201,7 +201,7 @@ export class Hover extends CodeMirrorLSPFeature { e.message === "Cannot read property 'string' of undefined" ) ) { - throw e; + console.warn(e); } } }; diff --git a/packages/jupyterlab-lsp/src/command_manager.ts b/packages/jupyterlab-lsp/src/command_manager.ts index 69e7d11e1..07e41ef03 100644 --- a/packages/jupyterlab-lsp/src/command_manager.ts +++ b/packages/jupyterlab-lsp/src/command_manager.ts @@ -201,7 +201,7 @@ export class NotebookCommandManager extends ContextCommandManager { return notebook_adapters.get(notebook.id); } - context_from_active_document(): ICommandContext { + context_from_active_document(): ICommandContext | null { if (!this.is_widget_current) { return null; } @@ -213,7 +213,7 @@ export class NotebookCommandManager extends ContextCommandManager { let virtual_editor = this.current_adapter?.virtual_editor; - if (!virtual_editor) { + if (virtual_editor == null) { return null; } @@ -222,6 +222,11 @@ export class NotebookCommandManager extends ContextCommandManager { cm_cursor ); + if (root_position == null) { + console.warn('Could not retrieve current context', virtual_editor); + return null; + } + return this.current_adapter?.get_context(root_position); } } diff --git a/packages/jupyterlab-lsp/src/manager.ts b/packages/jupyterlab-lsp/src/manager.ts index 68028af48..ade479059 100644 --- a/packages/jupyterlab-lsp/src/manager.ts +++ b/packages/jupyterlab-lsp/src/manager.ts @@ -53,7 +53,8 @@ export class LanguageServerManager implements ILanguageServerManager { ); if (!response.ok) { - throw new Error(response.statusText); + console.error('Could not fetch sessions', response); + return; } let sessions: SCHEMA.Sessions; diff --git a/packages/jupyterlab-lsp/src/virtual/editors/notebook.ts b/packages/jupyterlab-lsp/src/virtual/editors/notebook.ts index 00578410c..fdcb00f83 100644 --- a/packages/jupyterlab-lsp/src/virtual/editors/notebook.ts +++ b/packages/jupyterlab-lsp/src/virtual/editors/notebook.ts @@ -118,11 +118,12 @@ export class VirtualEditorForNotebook extends VirtualEditor { transform_from_notebook_to_root( cell: Cell, position: IEditorPosition - ): IRootPosition { + ): IRootPosition | null { // TODO: if cell is not known, refresh let shift = this.cell_to_corresponding_source_line.get(cell); - if (shift === undefined) { - throw Error('Cell not found in cell_line_map'); + if (shift == null) { + console.warn('Cell not found in cell_line_map'); + return null; } return { ...(position as CodeMirror.Position), diff --git a/packages/lsp-ws-connection/src/server-capability-registration.ts b/packages/lsp-ws-connection/src/server-capability-registration.ts index 12d158634..765612cc3 100644 --- a/packages/lsp-ws-connection/src/server-capability-registration.ts +++ b/packages/lsp-ws-connection/src/server-capability-registration.ts @@ -11,7 +11,7 @@ interface IFlexibleServerCapabilities extends ServerCapabilities { function registerServerCapability( serverCapabilities: ServerCapabilities, registration: Registration -): ServerCapabilities { +): ServerCapabilities | null { const serverCapabilitiesCopy = JSON.parse( JSON.stringify(serverCapabilities) ) as IFlexibleServerCapabilities; @@ -27,7 +27,8 @@ function registerServerCapability( ); } } else { - throw new Error('Could not register server capability.'); + console.warn('Could not register server capability.', registration); + return null; } return serverCapabilitiesCopy; diff --git a/packages/lsp-ws-connection/src/ws-connection.ts b/packages/lsp-ws-connection/src/ws-connection.ts index 24acea4eb..cd3ff9b99 100644 --- a/packages/lsp-ws-connection/src/ws-connection.ts +++ b/packages/lsp-ws-connection/src/ws-connection.ts @@ -79,10 +79,14 @@ export class LspWsConnection extends events.EventEmitter (params: protocol.RegistrationParams) => { params.registrations.forEach( (capabilityRegistration: protocol.Registration) => { - this.serverCapabilities = registerServerCapability( - this.serverCapabilities, - capabilityRegistration - ); + try { + this.serverCapabilities = registerServerCapability( + this.serverCapabilities, + capabilityRegistration + ); + } catch (err) { + console.error(err); + } } );