Skip to content

Commit

Permalink
Separate python/intepreter api and extension api (#10494)
Browse files Browse the repository at this point in the history
* Separate python/intepreter api and extension api

* Move kernel connection wrapper into api

* Update telemetry

* telemetry
  • Loading branch information
rebornix authored Jun 18, 2022
1 parent c925935 commit b821681
Show file tree
Hide file tree
Showing 22 changed files with 2,311 additions and 2,300 deletions.
4,458 changes: 2,229 additions & 2,229 deletions TELEMETRY.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/extension.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
} from 'vscode';
import * as fsExtra from 'fs-extra';
import * as path from './platform/vscode-path/path';
import { buildApi, IExtensionApi } from './platform/api';
import { buildApi, IExtensionApi } from './webviews/extension-side/api/api';
import { IApplicationEnvironment, ICommandManager } from './platform/common/application/types';
import { setHomeDirectory, traceError } from './platform/logging';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/extension.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
window,
workspace
} from 'vscode';
import { buildApi, IExtensionApi } from './platform/api';
import { buildApi, IExtensionApi } from './webviews/extension-side/api/api';
import { IApplicationEnvironment, ICommandManager } from './platform/common/application/types';
import { traceError } from './platform/logging';
import {
Expand Down
3 changes: 2 additions & 1 deletion src/kernels/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import type {
import type * as nbformat from '@jupyterlab/nbformat';
import { PythonEnvironment } from '../platform/pythonEnvironments/info';
import { IAsyncDisposable, IDisplayOptions, Resource } from '../platform/common/types';
import { WebSocketData } from '../platform/api/extension';
import { IBackupFile, IJupyterKernel } from './jupyter/types';
import { PythonEnvironment_PythonApi } from '../platform/api/types';

export type WebSocketData = string | Buffer | ArrayBuffer | Buffer[];

export type LiveKernelModel = IJupyterKernel &
Partial<IJupyterKernelSpec> & { model: Session.IModel | undefined; notebook?: { path?: string } };

Expand Down
3 changes: 1 addition & 2 deletions src/notebooks/languages/cellLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type * as nbformat from '@jupyterlab/nbformat';
import { inject, injectable, named } from 'inversify';
import { Memento, NotebookCellKind, NotebookDocument } from 'vscode';
import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { IJupyterKernelSpec } from '../../platform/api/extension';
import { IPythonExtensionChecker } from '../../platform/api/types';
import { IVSCodeNotebook } from '../../platform/common/application/types';
import {
Expand All @@ -24,7 +23,7 @@ import {
isPythonKernelConnection
} from '../../kernels/helpers';
import { getNotebookMetadata, isJupyterNotebook, translateKernelLanguageToMonaco } from '../../platform/common/utils';
import { KernelConnectionMetadata } from '../../kernels/types';
import { IJupyterKernelSpec, KernelConnectionMetadata } from '../../kernels/types';

export const LastSavedNotebookCellLanguage = 'DATASCIENCE.LAST_SAVED_CELL_LANGUAGE';
/**
Expand Down
2 changes: 1 addition & 1 deletion src/platform/api/pythonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { Disposable, EventEmitter, Event, Uri, workspace, ExtensionMode } from 'vscode';
import { fsPathToUri } from '../vscode-path/utils';
import { PythonEnvironment } from './extension';
import {
IPythonApiProvider,
IPythonExtensionChecker,
Expand All @@ -28,6 +27,7 @@ import { getDisplayPath, getFilePath } from '../common/platform/fs-paths';
import { IInterpreterSelector, IInterpreterQuickPickItem } from '../interpreter/configuration/types';
import { IInterpreterService } from '../interpreter/contracts';
import { areInterpreterPathsSame } from '../pythonEnvironments/info/interpreter';
import { PythonEnvironment } from '../pythonEnvironments/info';
import { TraceOptions } from '../logging/types';
import { noop } from '../common/utils/misc';

Expand Down
8 changes: 0 additions & 8 deletions src/platform/api/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import { IInterpreterSelector } from '../interpreter/configuration/types';
import { IInterpreterService } from '../interpreter/contracts';
import { InterpreterStatusBarVisibility } from '../interpreter/display/visibilityFilter.node';
import { IServiceManager } from '../ioc/types';
import { ApiAccessService } from './apiAccessService';
import { JupyterKernelServiceFactory } from './kernelApi';
import { InterpreterSelector, InterpreterService, PythonApiProvider, PythonExtensionChecker } from './pythonApi';
import { LanguageServerProvider, PythonDebuggerPathProvider } from './pythonApi.node';
import {
IExportedKernelServiceFactory,
ILanguageServerProvider,
IPythonApiProvider,
IPythonDebuggerPathProvider,
Expand All @@ -37,9 +34,4 @@ export function registerTypes(serviceManager: IServiceManager): void {
IEnvironmentActivationService,
EnvironmentActivationService
);
serviceManager.addSingleton<IExportedKernelServiceFactory>(
IExportedKernelServiceFactory,
JupyterKernelServiceFactory
);
serviceManager.addSingleton<ApiAccessService>(ApiAccessService, ApiAccessService);
}
9 changes: 1 addition & 8 deletions src/platform/api/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@
import { IInterpreterSelector } from '../interpreter/configuration/types';
import { IInterpreterService } from '../interpreter/contracts';
import { IServiceManager } from '../ioc/types';
import { ApiAccessService } from './apiAccessService';
import { JupyterKernelServiceFactory } from './kernelApi';
import { InterpreterSelector, InterpreterService, PythonApiProvider, PythonExtensionChecker } from './pythonApi';
import { IExportedKernelServiceFactory, IPythonApiProvider, IPythonExtensionChecker } from './types';
import { IPythonApiProvider, IPythonExtensionChecker } from './types';

export function registerTypes(serviceManager: IServiceManager): void {
serviceManager.addSingleton<IPythonApiProvider>(IPythonApiProvider, PythonApiProvider);
serviceManager.addSingleton<IPythonExtensionChecker>(IPythonExtensionChecker, PythonExtensionChecker);
serviceManager.addSingleton<IInterpreterService>(IInterpreterService, InterpreterService);
serviceManager.addSingleton<IInterpreterSelector>(IInterpreterSelector, InterpreterSelector);
serviceManager.addSingleton<ApiAccessService>(ApiAccessService, ApiAccessService);
serviceManager.addSingleton<IExportedKernelServiceFactory>(
IExportedKernelServiceFactory,
JupyterKernelServiceFactory
);
}
9 changes: 3 additions & 6 deletions src/platform/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { Disposable, Event, QuickPickItem, Uri } from 'vscode';
import * as lsp from 'vscode-languageserver-protocol';
import { InterpreterUri, Resource } from '../common/types';
import type { SemVer } from 'semver';
import { EnvironmentType, IExportedKernelService, PythonVersion } from './extension';
import { PythonVersion } from '../pythonEnvironments/info/pythonVersion';
import { EnvironmentType } from '../pythonEnvironments/info';

export type ILanguageServerConnection = Pick<
lsp.ProtocolConnection,
'sendRequest' | 'sendNotification' | 'onProgress' | 'sendProgress' | 'onNotification' | 'onRequest'
Expand Down Expand Up @@ -180,8 +182,3 @@ export const ILanguageServerProvider = Symbol('ILanguageServerProvider');
export interface ILanguageServerProvider {
getLanguageServer(resource?: InterpreterUri): Promise<ILanguageServer | undefined>;
}

export const IExportedKernelServiceFactory = Symbol('IExportedKernelServiceFactory');
export interface IExportedKernelServiceFactory {
getService(): Promise<IExportedKernelService | undefined>;
}
2 changes: 1 addition & 1 deletion src/platform/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { traceError, traceInfo } from '../logging';

import { ICell } from './types';
import { DataScience } from './utils/localize';
import { IJupyterKernelSpec } from '../api/extension';
import { IJupyterKernelSpec } from '../../webviews/extension-side/api/extension';

// Can't figure out a better way to do this. Enumerate
// the allowed keys of different output formats.
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { EnvironmentType, PythonEnvironment } from '../platform/pythonEnvironmen
import { TelemetryErrorProperties, ErrorCategory } from '../platform/errors/types';
import { ExportFormat } from '../notebooks/export/types';
import { InterruptResult, KernelConnectionMetadata, KernelInterpreterDependencyResponse } from '../kernels/types';
import { IExportedKernelService } from '../platform/api/extension';
import { IExportedKernelService } from '../webviews/extension-side/api/extension';
import { PreferredKernelExactMatchReason } from '../notebooks/controllers/notebookControllerManager';
import { SelectJupyterUriCommandSource } from '../kernels/jupyter/serverSelector';
import { TerminalShellType } from '../platform/terminals/types';
Expand Down
2 changes: 1 addition & 1 deletion src/test/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { NotebookDocument, Uri, Event } from 'vscode';
import { IExtensionApi } from '../platform/api';
import { IExtensionApi } from '../webviews/extension-side/api/api';
import { IDisposable } from '../platform/common/types';
import { IServiceContainer, IServiceManager } from '../platform/ioc/types';

Expand Down
2 changes: 1 addition & 1 deletion src/test/datascience/notebook/exportFull.vscode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import { BufferDecoder } from '../../../platform/common/process/decoder.node';
import { INbConvertInterpreterDependencyChecker, INotebookImporter } from '../../../kernels/jupyter/types';
import { JupyterImporter } from '../../../webviews/extension-side/import-export/jupyterImporter.node';
import { IInterpreterService } from '../../../platform/interpreter/contracts';
import { PythonEnvironment } from '../../../platform/api/extension';
import { CodeSnippets, Identifiers } from '../../../platform/common/constants';
import { noop } from '../../../platform/common/utils/misc';
import { PythonEnvironment } from '../../../platform/pythonEnvironments/info';

// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const expectedPromptMessageSuffix = `requires ${ProductNames.get(Product.ipykernel)!} to be installed.`;
Expand Down
2 changes: 1 addition & 1 deletion src/test/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { clearPendingChainedUpdatesForTests } from '../kernels/execution/notebookUpdater';
import { IExtensionApi } from '../platform/api';
import { IExtensionApi } from '../webviews/extension-side/api/api';
import { disposeAllDisposables } from '../platform/common/helpers';
import { IDisposable } from '../platform/common/types';
import { sleep } from '../platform/common/utils/async';
Expand Down
2 changes: 1 addition & 1 deletion src/test/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// The same objects/types will be used as the module is only ever loaded once by nodejs.
import * as extension from '../../extension.web';
import * as vscode from 'vscode';
import type { IExtensionApi } from '../../platform/api';
import type { IExtensionApi } from '../../webviews/extension-side/api/api';
import type { IExtensionContext } from '../../platform/common/types';
import { IExtensionTestApi } from '../common';
import { JVSC_EXTENSION_ID, setCI, setTestExecution } from '../../platform/common/constants';
Expand Down
33 changes: 21 additions & 12 deletions src/platform/api.ts → src/webviews/extension-side/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
'use strict';

import { ExtensionMode, NotebookController, NotebookDocument } from 'vscode';
import { JupyterConnection } from '../kernels/jupyter/jupyterConnection';
import { computeServerId, generateUriFromRemoteProvider } from '../kernels/jupyter/jupyterUtils';
import { JupyterServerSelector } from '../kernels/jupyter/serverSelector';
import { IJupyterUriProvider, IJupyterUriProviderRegistration, JupyterServerUriHandle } from '../kernels/jupyter/types';
import { INotebookControllerManager, INotebookEditorProvider } from '../notebooks/types';
import { IDataViewerDataProvider, IDataViewerFactory } from '../webviews/extension-side/dataviewer/types';
import { IExportedKernelService } from './api/extension';
import { IExportedKernelServiceFactory, IPythonApiProvider, PythonApi } from './api/types';
import { isTestExecution } from './common/constants';
import { IExtensionContext } from './common/types';
import { IServiceContainer, IServiceManager } from './ioc/types';
import { traceError } from './logging';
import { JupyterConnection } from '../../../kernels/jupyter/jupyterConnection';
import { computeServerId, generateUriFromRemoteProvider } from '../../../kernels/jupyter/jupyterUtils';
import { JupyterServerSelector } from '../../../kernels/jupyter/serverSelector';
import {
IJupyterUriProvider,
IJupyterUriProviderRegistration,
JupyterServerUriHandle
} from '../../../kernels/jupyter/types';
import { INotebookControllerManager, INotebookEditorProvider } from '../../../notebooks/types';
import { IDataViewerDataProvider, IDataViewerFactory } from '../dataviewer/types';
import { IExportedKernelService } from './extension';
import { IPythonApiProvider, PythonApi } from '../../../platform/api/types';
import { isTestExecution } from '../../../platform/common/constants';
import { IExtensionContext } from '../../../platform/common/types';
import { IServiceContainer, IServiceManager } from '../../../platform/ioc/types';
import { traceError } from '../../../platform/logging';

export const IExportedKernelServiceFactory = Symbol('IExportedKernelServiceFactory');
export interface IExportedKernelServiceFactory {
getService(): Promise<IExportedKernelService | undefined>;
}

/*
* Do not introduce any breaking changes to this API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import { injectable, inject, named } from 'inversify';
import { ExtensionMode, Memento } from 'vscode';
import { IApplicationShell } from '../common/application/types';
import { JVSC_EXTENSION_ID, Telemetry } from '../common/constants';
import { GLOBAL_MEMENTO, IExtensionContext, IMemento } from '../common/types';
import { PromiseChain } from '../common/utils/async';
import { Common, DataScience } from '../common/utils/localize';
import { sendTelemetryEvent } from '../../telemetry';
import { traceError } from '../logging';
import { noop } from '../common/utils/misc';
import { IApplicationShell } from '../../../platform/common/application/types';
import { JVSC_EXTENSION_ID, Telemetry } from '../../../platform/common/constants';
import { GLOBAL_MEMENTO, IExtensionContext, IMemento } from '../../../platform/common/types';
import { PromiseChain } from '../../../platform/common/utils/async';
import { Common, DataScience } from '../../../platform/common/utils/localize';
import { sendTelemetryEvent } from '../../../telemetry';
import { traceError } from '../../../platform/logging';
import { noop } from '../../../platform/common/utils/misc';

type ApiExtensionInfo = {
extensionId: string;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
IKernelProvider,
IKernel,
KernelConnectionMetadata as IKernelKernelConnectionMetadata
} from '../../kernels/types';
import { INotebookControllerManager } from '../../notebooks/types';
import { disposeAllDisposables } from '../common/helpers';
import { traceInfo } from '../logging';
import { IDisposable, IDisposableRegistry, IExtensions } from '../common/types';
import { PromiseChain } from '../common/utils/async';
import { IKernelSocket as ExtensionKernelSocket } from '../../kernels/types';
import { sendTelemetryEvent } from '../../telemetry';
} from '../../../kernels/types';
import { INotebookControllerManager } from '../../../notebooks/types';
import { disposeAllDisposables } from '../../../platform/common/helpers';
import { traceInfo } from '../../../platform/logging';
import { IDisposable, IDisposableRegistry, IExtensions } from '../../../platform/common/types';
import { PromiseChain } from '../../../platform/common/utils/async';
import { IKernelSocket as ExtensionKernelSocket } from '../../../kernels/types';
import { sendTelemetryEvent } from '../../../telemetry';
import { ApiAccessService } from './apiAccessService';
import {
ActiveKernel,
Expand All @@ -25,11 +25,11 @@ import {
KernelConnectionMetadata,
WebSocketData
} from './extension';
import { JupyterNotebookView, Telemetry } from '../common/constants';
import { KernelConnector } from '../../notebooks/controllers/kernelConnector';
import { DisplayOptions } from '../../kernels/displayOptions';
import { IServiceContainer } from '../ioc/types';
import { IExportedKernelServiceFactory } from './types';
import { JupyterNotebookView, Telemetry } from '../../../platform/common/constants';
import { KernelConnector } from '../../../notebooks/controllers/kernelConnector';
import { DisplayOptions } from '../../../kernels/displayOptions';
import { IServiceContainer } from '../../../platform/ioc/types';
import { IExportedKernelServiceFactory } from './api';

@injectable()
export class JupyterKernelServiceFactory implements IExportedKernelServiceFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT License.

import type { Kernel } from '@jupyterlab/services';
import { IDisposable } from '../common/types';
import { noop } from '../common/utils/misc';
import { BaseKernelConnectionWrapper } from '../../kernels/jupyter/baseKernelConnectionWrapper';
import { IKernel } from '../../kernels/types';
import { IDisposable } from '../../../platform/common/types';
import { noop } from '../../../platform/common/utils/misc';
import { BaseKernelConnectionWrapper } from '../../../kernels/jupyter/baseKernelConnectionWrapper';
import { IKernel } from '../../../kernels/types';

export class KernelConnectionWrapper extends BaseKernelConnectionWrapper {
/**
Expand Down
10 changes: 10 additions & 0 deletions src/webviews/extension-side/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import { ActiveEditorContextService } from './activeEditorContext';
import { AmlComputeContext } from './amlContext.node';
import { IImportTracker, ImportTracker } from './importTracker.node';
import { GlobalActivation } from './globalActivation';
import { JupyterKernelServiceFactory } from './api/kernelApi';
import { IExportedKernelServiceFactory } from './api/api';
import { ApiAccessService } from './api/apiAccessService';

export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) {
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, GlobalActivation);
Expand Down Expand Up @@ -105,4 +108,11 @@ export function registerTypes(serviceManager: IServiceManager, _isDevMode: boole
);

serviceManager.addSingletonInstance<IExtensionSideRenderer>(IExtensionSideRenderer, new ExtensionSideRenderer());

// API
serviceManager.addSingleton<IExportedKernelServiceFactory>(
IExportedKernelServiceFactory,
JupyterKernelServiceFactory
);
serviceManager.addSingleton<ApiAccessService>(ApiAccessService, ApiAccessService);
}
10 changes: 10 additions & 0 deletions src/webviews/extension-side/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { GlobalActivation } from './globalActivation';
import { DataViewer } from './dataviewer/dataViewer';
import { INotebookExporter } from '../../kernels/jupyter/types';
import { JupyterExporter } from './import-export/jupyterExporter';
import { JupyterKernelServiceFactory } from './api/kernelApi';
import { IExportedKernelServiceFactory } from './api/api';
import { ApiAccessService } from './api/apiAccessService';

export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) {
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, GlobalActivation);
Expand Down Expand Up @@ -67,4 +70,11 @@ export function registerTypes(serviceManager: IServiceManager, _isDevMode: boole

serviceManager.addSingletonInstance<IExtensionSideRenderer>(IExtensionSideRenderer, new ExtensionSideRenderer());
serviceManager.add<INotebookExporter>(INotebookExporter, JupyterExporter);

// API
serviceManager.addSingleton<IExportedKernelServiceFactory>(
IExportedKernelServiceFactory,
JupyterKernelServiceFactory
);
serviceManager.addSingleton<ApiAccessService>(ApiAccessService, ApiAccessService);
}

0 comments on commit b821681

Please sign in to comment.