Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/11297.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lazy load types from `jupyterlab/services` and similar `npm modules`.
4 changes: 2 additions & 2 deletions src/client/datascience/baseJupyterSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT License.
'use strict';
import type { Kernel, KernelMessage, Session } from '@jupyterlab/services';
import { JSONObject } from '@phosphor/coreutils';
import { Slot } from '@phosphor/signaling';
import type { JSONObject } from '@phosphor/coreutils';
import type { Slot } from '@phosphor/signaling';
import { Observable } from 'rxjs/Observable';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { Event, EventEmitter } from 'vscode';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/codeCssGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { JSONArray, JSONObject } from '@phosphor/coreutils';
import type { JSONArray, JSONObject } from '@phosphor/coreutils';
import { inject, injectable } from 'inversify';
import { parse } from 'jsonc-parser';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { Memento } from 'vscode';
import { splitMultilineString } from '../../datascience-ui/common';
import { noop } from '../common/utils/misc';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/data-viewing/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { JSONObject } from '@phosphor/coreutils';
import type { JSONObject } from '@phosphor/coreutils';

import { SharedMessages } from '../messages';
import { IJupyterVariable } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/datascience.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { JSONObject } from '@phosphor/coreutils';
import type { JSONObject } from '@phosphor/coreutils';
import { inject, injectable } from 'inversify';
import * as vscode from 'vscode';
import { ICommandManager, IDocumentManager, IWorkspaceService } from '../common/application/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';
import '../../common/extensions';

import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import type { KernelMessage } from '@jupyterlab/services';
import { injectable, unmanaged } from 'inversify';
import * as os from 'os';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/interactive-ipynb/nativeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import {
} from '../types';
import { NativeEditorSynchronizer } from './nativeEditorSynchronizer';

import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
// tslint:disable-next-line: no-require-imports
import cloneDeep = require('lodash/cloneDeep');
import { concatMultilineStringInput } from '../../../datascience-ui/common';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import * as fastDeepEqual from 'fast-deep-equal';
import { inject, injectable, named } from 'inversify';
import * as path from 'path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable, multiInject, named } from 'inversify';
import * as path from 'path';
import { Event, EventEmitter, Memento, Uri, ViewColumn } from 'vscode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
'use strict';

import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { sha256 } from 'hash.js';
import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../../activation/types';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterDebugger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import * as uuid from 'uuid/v4';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterExporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable } from 'inversify';
import * as os from 'os';
import * as path from 'path';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';
import '../../common/extensions';

import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable } from 'inversify';
import * as os from 'os';
import * as path from 'path';
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterNotebook.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import type { Kernel, KernelMessage } from '@jupyterlab/services';
import { JSONObject } from '@phosphor/coreutils';
import type { JSONObject } from '@phosphor/coreutils';
import { Observable } from 'rxjs/Observable';
import { Subscriber } from 'rxjs/Subscriber';
import * as uuid from 'uuid/v4';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import * as uuid from 'uuid/v4';
import { Disposable, Uri } from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/jupyter/jupyterServerWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable, named } from 'inversify';
import * as uuid from 'uuid/v4';
import { Uri } from 'vscode';
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type {
Session,
SessionManager
} from '@jupyterlab/services';
import { JSONObject } from '@phosphor/coreutils';
import { Slot } from '@phosphor/signaling';
import type { JSONObject } from '@phosphor/coreutils';
import type { Slot } from '@phosphor/signaling';
import * as uuid from 'uuid/v4';
import { CancellationToken } from 'vscode-jsonrpc';
import { Cancellation } from '../../common/cancellation';
Expand Down
19 changes: 13 additions & 6 deletions src/client/datascience/jupyter/jupyterSessionManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { ContentsManager, Kernel, ServerConnection, Session, SessionManager } from '@jupyterlab/services';
import type { ContentsManager, ServerConnection, Session, SessionManager } from '@jupyterlab/services';
import { Agent as HttpsAgent } from 'https';
import { CancellationToken } from 'vscode-jsonrpc';

Expand Down Expand Up @@ -29,7 +29,14 @@ export class JupyterSessionManager implements IJupyterSessionManager {
private contentsManager: ContentsManager | undefined;
private connInfo: IJupyterConnection | undefined;
private serverSettings: ServerConnection.ISettings | undefined;

private _jupyterlab?: typeof import('@jupyterlab/services');
private get jupyterlab(): typeof import('@jupyterlab/services') {
if (!this._jupyterlab) {
// tslint:disable-next-line: no-require-imports
this._jupyterlab = require('@jupyterlab/services');
}
return this._jupyterlab!;
}
constructor(
private jupyterPasswordConnect: IJupyterPasswordConnect,
_config: IConfigurationService,
Expand Down Expand Up @@ -78,8 +85,8 @@ export class JupyterSessionManager implements IJupyterSessionManager {
public async initialize(connInfo: IJupyterConnection): Promise<void> {
this.connInfo = connInfo;
this.serverSettings = await this.getServerConnectSettings(connInfo);
this.sessionManager = new SessionManager({ serverSettings: this.serverSettings });
this.contentsManager = new ContentsManager({ serverSettings: this.serverSettings });
this.sessionManager = new this.jupyterlab.SessionManager({ serverSettings: this.serverSettings });
this.contentsManager = new this.jupyterlab.ContentsManager({ serverSettings: this.serverSettings });
}

public async getRunningSessions(): Promise<Session.IModel[]> {
Expand All @@ -102,7 +109,7 @@ export class JupyterSessionManager implements IJupyterSessionManager {
}

public async getRunningKernels(): Promise<IJupyterKernel[]> {
const models = await Kernel.listRunning(this.serverSettings);
const models = await this.jupyterlab.Kernel.listRunning(this.serverSettings);
// Remove duplicates.
const dup = new Set<string>();
return models
Expand Down Expand Up @@ -246,6 +253,6 @@ export class JupyterSessionManager implements IJupyterSessionManager {
) as any
};

return ServerConnection.makeSettings(serverSettings);
return this.jupyterlab.ServerConnection.makeSettings(serverSettings);
}
}
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterVariables.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import { JSONObject } from '@phosphor/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import type { JSONObject } from '@phosphor/coreutils';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import stripAnsi from 'strip-ansi';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Kernel } from '@jupyterlab/services';
import type { Kernel } from '@jupyterlab/services';
import * as path from 'path';
import { CancellationToken } from 'vscode';
import { createPromiseFromCancellation } from '../../../common/cancellation';
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/kernels/kernelSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT License.
import '../../../common/extensions';

import { nbformat } from '@jupyterlab/coreutils';
import { Kernel } from '@jupyterlab/services';
import type { nbformat } from '@jupyterlab/coreutils';
import type { Kernel } from '@jupyterlab/services';
import { inject, injectable } from 'inversify';
import { CancellationToken } from 'vscode-jsonrpc';

Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/kernels/kernelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

'use strict';

import { nbformat } from '@jupyterlab/coreutils';
import { Kernel } from '@jupyterlab/services';
import type { nbformat } from '@jupyterlab/coreutils';
import type { Kernel } from '@jupyterlab/services';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import * as uuid from 'uuid/v4';
Expand Down
10 changes: 5 additions & 5 deletions src/client/datascience/jupyter/liveshare/guestJupyterNotebook.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Kernel, KernelMessage } from '@jupyterlab/services';
import { JSONObject } from '@phosphor/coreutils';
import type { Kernel, KernelMessage } from '@jupyterlab/services';
import type { JSONObject } from '@phosphor/coreutils';
import { Observable } from 'rxjs/Observable';
import { Event, EventEmitter, Uri } from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
Expand Down Expand Up @@ -36,12 +36,12 @@ import { IExecuteObservableResponse, ILiveShareParticipant, IServerResponse } fr
export class GuestJupyterNotebook
extends LiveShareParticipantGuest(LiveShareParticipantDefault, LiveShare.JupyterNotebookSharedService)
implements INotebook, ILiveShareParticipant {
private get jupyterLab(): undefined | typeof import('@jupyterlab/services') {
private get jupyterLab(): typeof import('@jupyterlab/services') {
if (!this._jupyterLab) {
// tslint:disable-next-line:no-require-imports
this._jupyterLab = require('@jupyterlab/services') as typeof import('@jupyterlab/services'); // NOSONAR
}
return this._jupyterLab;
return this._jupyterLab!;
}

public get identity(): Uri {
Expand Down Expand Up @@ -299,7 +299,7 @@ export class GuestJupyterNotebook
public requestCommInfo(
_content: KernelMessage.ICommInfoRequestMsg['content']
): Promise<KernelMessage.ICommInfoReplyMsg> {
const shellMessage = KernelMessage.createMessage<KernelMessage.ICommInfoReplyMsg>({
const shellMessage = this.jupyterLab?.KernelMessage.createMessage<KernelMessage.ICommInfoReplyMsg>({
msgType: 'comm_info_reply',
channel: 'shell',
content: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as vscode from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
import * as vsls from 'vsls/vscode';

import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { IApplicationShell, ILiveShareApi, IWorkspaceService } from '../../../common/application/types';
import { isTestExecution } from '../../../common/constants';
import { traceInfo } from '../../../common/logger';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/liveshare/postOffice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { JSONArray } from '@phosphor/coreutils';
import type { JSONArray } from '@phosphor/coreutils';
import * as vscode from 'vscode';
import * as vsls from 'vsls/vscode';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This code was copied from https://github.com/nteract/enchannel-zmq-backend/blob/master/src/index.ts
// and modified to work with zeromq-beta-6

import { Channels, JupyterMessage } from '@nteract/messaging';
import type { Channels, JupyterMessage } from '@nteract/messaging';
import * as wireProtocol from '@nteract/messaging/lib/wire-protocol';
import * as Events from 'events';
import * as rxjs from 'rxjs';
Expand Down
4 changes: 2 additions & 2 deletions src/client/datascience/raw-kernel/enchannelJMPConnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { KernelMessage } from '@jupyterlab/services';
import { Channels } from '@nteract/messaging';
import type { KernelMessage } from '@jupyterlab/services';
import type { Channels } from '@nteract/messaging';
import { injectable } from 'inversify';
import { IJMPConnection, IJMPConnectionInfo } from '../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { Uri } from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
import * as vsls from 'vsls/vscode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
import * as vsls from 'vsls/vscode';

import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { IApplicationShell, ILiveShareApi, IWorkspaceService } from '../../../common/application/types';
import { traceError, traceInfo } from '../../../common/logger';
import { IFileSystem } from '../../../common/platform/types';
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/raw-kernel/rawFuture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Kernel, KernelMessage } from '@jupyterlab/services';
import type { Kernel, KernelMessage } from '@jupyterlab/services';
import { createDeferred, Deferred } from '../../common/utils/async';
import { noop } from '../../common/utils/misc';

Expand Down
12 changes: 7 additions & 5 deletions src/client/datascience/raw-kernel/rawKernel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Kernel, KernelMessage, ServerConnection } from '@jupyterlab/services';
import { JSONObject } from '@phosphor/coreutils';
import { ISignal, Signal } from '@phosphor/signaling';
import type { Kernel, KernelMessage, ServerConnection } from '@jupyterlab/services';
import type { JSONObject } from '@phosphor/coreutils';
import type { ISignal, Signal } from '@phosphor/signaling';
// tslint:disable-next-line: no-require-imports
import cloneDeep = require('lodash/cloneDeep');
import * as uuid from 'uuid/v4';
Expand Down Expand Up @@ -94,7 +94,9 @@ export class RawKernel implements Kernel.IKernel {
this._clientId = clientId;
this._id = uuid();
this._status = 'unknown';
this._statusChanged = new Signal<this, Kernel.Status>(this);
// tslint:disable-next-line: no-require-imports
const signalling = require('@phosphor/signaling') as typeof import('@phosphor/signaling');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signaling

this._statusChanged = new signalling.Signal<this, Kernel.Status>(this);

// Subscribe to messages coming in from our JMP channel
this.jmpConnection = jmpConnection;
Expand Down Expand Up @@ -438,7 +440,7 @@ export class RawKernel implements Kernel.IKernel {
return false;
}

/*
/*
Messages are handled async so there is a possibility that the kernel might be
disposed or restarted during handling. Throw an error here if our message that
we are handling is no longer valid.
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/raw-kernel/rawNotebookProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import * as uuid from 'uuid/v4';
import { Event, EventEmitter, Uri } from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import type { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { CancellationToken } from 'vscode-jsonrpc';
Expand Down
Loading