Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private connect_socket(options: ISocketConnectionOptions): LSPConnection {
let { virtual_document, language } = options;
const wsBase = PageConfig.getBaseUrl().replace(/^http/, 'ws');
const rootUri = PageConfig.getOption('rootUri');
const documentUri = URLExt.join(rootUri, virtual_document.uri);
const serverUri = URLExt.join('ws://jupyter-lsp', language);
let socket = new WebSocket(URLExt.join(wsBase, 'lsp', language));
let connection = new LSPConnection({
languageId: language,
serverUri,
rootUri,
documentUri,
documentText: () => {
// NOTE: Update is async now and this is not really used, as an alternative method
// which is compatible with async is used.
// This should be only used in the initialization step.
// if (main_connection.isConnected) {
// console.warn('documentText is deprecated for use in JupyterLab LSP');
// }
return virtual_document.value;
}
}).connect(socket);
getDownloadUrl(localPath: string): Promise {
let baseUrl = this.serverSettings.baseUrl;
let url = URLExt.join(baseUrl, FILES_URL, URLExt.encodeParts(localPath));
const xsrfTokenMatch = document.cookie.match('\\b_xsrf=([^;]*)\\b');
if (xsrfTokenMatch) {
const fullurl = new URL(url);
fullurl.searchParams.append('_xsrf', xsrfTokenMatch[1]);
url = fullurl.toString();
}
return Promise.resolve(url);
}
export function getServiceUrl(baseUrl: string): string {
return URLExt.join(baseUrl, TERMINAL_SERVICE_URL);
}
private _updateUrl(): void {
if (!this.item || !this.dashboardUrl) {
this.content.url = '';
return;
}
this.content.url = URLExt.join(this.dashboardUrl, this.item!.route);
}
export async function getKernelModel(
id: string,
settings?: ServerConnection.ISettings
): Promise {
settings = settings || ServerConnection.makeSettings();
let url = URLExt.join(
settings.baseUrl,
KERNEL_SERVICE_URL,
encodeURIComponent(id)
);
let response = await ServerConnection.makeRequest(url, {}, settings);
if (response.status !== 200) {
throw new ServerConnection.ResponseError(response);
}
let data = await response.json();
validate.validateModel(data);
return data;
}
export async function startSession(
options: Session.ISessionOptions,
settings: ServerConnection.ISettings = ServerConnection.makeSettings()
): Promise {
let url = URLExt.join(settings.baseUrl, SESSION_SERVICE_URL);
let init = {
method: 'POST',
body: JSON.stringify(options)
};
let response = await ServerConnection.makeRequest(url, init, settings);
if (response.status !== 201) {
throw new ServerConnection.ResponseError(response);
}
let data = await response.json();
updateLegacySessionModel(data);
validateModel(data);
return data;
}
execute: args => {
const current = getCurrent(args);
if (!current) {
return;
}
const notebookPath = URLExt.encodeParts(current.context.path);
const url =
URLExt.join(
services.serverSettings.baseUrl,
'nbconvert',
args['format'] as string,
notebookPath
) + '?download=true';
const child = window.open('', '_blank');
const { context } = current;
child.opener = null;
if (context.model.dirty && !context.model.readOnly) {
return context.save().then(() => {
child.location.assign(url);
});
}
return new Promise(resolve => {
execute: args => {
const current = getCurrent(args);
if (!current) {
return;
}
const notebookPath = URLExt.encodeParts(current.context.path);
const url = URLExt.join(
services.serverSettings.baseUrl,
'nbconvert',
'html_hidecode',
notebookPath
) + '?download=true';
const child = window.open('', '_blank');
const { context } = current;
if (context.model.dirty && !context.model.readOnly) {
return context.save().then(() => { child.location.assign(url); });
}
return new Promise((resolve) => {
child.location.assign(url);
resolve(undefined);
});
map(data, item => {
return URLExt.join(url, item.name);
})
);
export function getSessionUrl(baseUrl: string, id: string): string {
return URLExt.join(baseUrl, SESSION_SERVICE_URL, id);
}