Skip to content

Commit

Permalink
fix(lsp): lsp causes error when reconnecting kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
BroKun committed Feb 4, 2024
1 parent 9c11bc7 commit 4db97cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions packages/libro-lsp/src/adapters/notebook-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class NotebookAdapter extends WidgetLSPAdapter<LibroView> {
* @param _session - Session context of changed kernel
* @param change - Changed data
*/
async onKernelChanged(): Promise<void> {
onKernelChanged = async (): Promise<void> => {
try {
// note: we need to wait until ready before updating language info
const oldLanguageInfo = this._languageInfo;
Expand All @@ -212,7 +212,7 @@ export class NotebookAdapter extends WidgetLSPAdapter<LibroView> {
// try to reconnect anyway
this.reloadConnection();
}
}
};

/**
* Dispose the widget.
Expand Down Expand Up @@ -397,9 +397,11 @@ export class NotebookAdapter extends WidgetLSPAdapter<LibroView> {
return;
}

this._activeEditorChanged.fire({
editor: this.getCellEditor(libroModel.active)!,
});
if (libroModel.active) {
this._activeEditorChanged.fire({
editor: this.getCellEditor(libroModel.active)!,
});
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/libro-lsp/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export class DocumentConnectionManager implements ILSPDocumentConnectionManager
* language.
*/
disconnect(languageId: TLanguageServerId): void {
this.disconnect(languageId);
this.disconnectServer(languageId);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/libro-lsp/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ export class LSPConnection extends LspWsConnection implements ILSPConnection {
if (this.isDisposed) {
return;
}
Object.values(this.serverRequests).forEach((request) => request.clearHandler());
if (this.serverRequests) {
Object.values(this.serverRequests).forEach((request) => request.clearHandler());
}
this.close();
super.dispose();
}
Expand Down

0 comments on commit 4db97cb

Please sign in to comment.