Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Search for a matching path.
const model = find(models, m => m.path === widget.context.path);
if (model) {
// If there is a matching path, but it is the same
// session as we previously had, do nothing.
if (oldSession && oldSession.id === model.id) {
return;
}
// Otherwise, dispose of the old session and reset to
// a new CompletionConnector.
if (oldSession) {
delete activeSessions[widget.id];
oldSession.dispose();
}
const session = sessions.connectTo(model);
handler.connector = new CompletionConnector({ session, editor });
activeSessions[widget.id] = session;
} else {
// If we didn't find a match, make sure
// the connector is the contextConnector and
// dispose of any previous connection.
handler.connector = contextConnector;
if (oldSession) {
delete activeSessions[widget.id];
oldSession.dispose();
}
}
};
void Session.listRunning().then(models => {
consoles.widgetAdded.connect((sender, panel) => {
const anchor = panel.console;
const cell = anchor.promptCell;
const editor = cell && cell.editor;
const session = anchor.session;
const parent = panel;
const connector = new CompletionConnector({ session, editor });
const handler = manager.register({ connector, editor, parent });
// Listen for prompt creation.
anchor.promptCellCreated.connect((sender, cell) => {
const editor = cell && cell.editor;
handler.editor = editor;
handler.connector = new CompletionConnector({ session, editor });
});
});
// Search for a matching path.
const model = find(models, m => m.path === widget.context.path);
if (model) {
// If there is a matching path, but it is the same
// session as we previously had, do nothing.
if (oldSession && oldSession.id === model.id) {
return;
}
// Otherwise, dispose of the old session and reset to
// a new CompletionConnector.
if (oldSession) {
delete activeSessions[widget.id];
oldSession.dispose();
}
const session = sessions.connectTo(model);
handler.connector = new CompletionConnector({ session, editor });
activeSessions[widget.id] = session;
} else {
// If we didn't find a match, make sure
// the connector is the contextConnector and
// dispose of any previous connection.
handler.connector = contextConnector;
if (oldSession) {
delete activeSessions[widget.id];
oldSession.dispose();
}
}
};
void Session.listRunning().then(models => {
notebooks.widgetAdded.connect((sender, panel) => {
const cell = panel.content.activeCell;
const editor = cell && cell.editor;
const session = panel.session;
const parent = panel;
const connector = new CompletionConnector({ session, editor });
const handler = manager.register({ connector, editor, parent });
// Listen for active cell changes.
panel.content.activeCellChanged.connect((sender, cell) => {
const editor = cell && cell.editor;
handler.editor = editor;
handler.connector = new CompletionConnector({ session, editor });
});
});
consoles.widgetAdded.connect((sender, panel) => {
const anchor = panel.console;
const cell = anchor.promptCell;
const editor = cell && cell.editor;
const session = anchor.session;
const parent = panel;
const connector = new CompletionConnector({ session, editor });
const handler = manager.register({ connector, editor, parent });
// Listen for prompt creation.
anchor.promptCellCreated.connect((sender, cell) => {
const editor = cell && cell.editor;
handler.editor = editor;
handler.connector = new CompletionConnector({ session, editor });
});
});
constructor(options: LSPConnector.IOptions) {
super();
this._editor = options.editor;
this._connections = options.connections;
this.virtual_editor = options.virtual_editor;
this._context_connector = new ContextConnector({ editor: options.editor });
if (options.session) {
let kernel_options = { editor: options.editor, session: options.session };
this._kernel_connector = new KernelConnector(kernel_options);
this._kernel_and_context_connector = new CompletionConnector(
kernel_options
);
}
this.options = options;
}
panel.content.activeCellChanged.connect((sender, cell) => {
const editor = cell && cell.editor;
handler.editor = editor;
handler.connector = new CompletionConnector({ session, editor });
});
});