Skip to content

Commit

Permalink
jupyter-lsp#299: stop using throw
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Jul 27, 2020
1 parent 419ec72 commit 09d52e2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
11 changes: 7 additions & 4 deletions docs/Installation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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, \"..\")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class Hover extends CodeMirrorLSPFeature {
e.message === "Cannot read property 'string' of undefined"
)
) {
throw e;
console.warn(e);
}
}
};
Expand Down
9 changes: 7 additions & 2 deletions packages/jupyterlab-lsp/src/command_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/jupyterlab-lsp/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions packages/jupyterlab-lsp/src/virtual/editors/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions packages/lsp-ws-connection/src/ws-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
);

Expand Down

0 comments on commit 09d52e2

Please sign in to comment.