From cc70487f66883295f5498fe2d4c3d59d5291d83c Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Wed, 1 Feb 2023 17:35:35 -0500 Subject: [PATCH 1/3] fix api.ts file eslint errors --- .eslintignore | 1 - src/client/api.ts | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.eslintignore b/.eslintignore index 083b9d650d0c..20ecc74387d9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -149,7 +149,6 @@ src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts src/client/interpreter/activation/service.ts src/client/interpreter/display/index.ts -src/client/api.ts src/client/extension.ts src/client/sourceMapSupport.ts src/client/startupTelemetry.ts diff --git a/src/client/api.ts b/src/client/api.ts index 78663feab712..37f40dadec76 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. @@ -13,10 +14,11 @@ import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/extens import { IInterpreterService } from './interpreter/contracts'; import { IServiceContainer, IServiceManager } from './ioc/types'; import { JupyterExtensionIntegration } from './jupyter/jupyterIntegration'; +import { IDataViewerDataProvider, IJupyterUriProvider } from './jupyter/types'; import { traceError } from './logging'; export function buildApi( - ready: Promise, + ready: Promise, serviceManager: IServiceManager, serviceContainer: IServiceContainer, ): IExtensionApi { @@ -47,7 +49,7 @@ export function buildApi( async getRemoteLauncherCommand( host: string, port: number, - waitUntilDebuggerAttaches: boolean = true, + waitUntilDebuggerAttaches = true, ): Promise { return getDebugpyLauncherArgs({ host, @@ -62,20 +64,23 @@ export function buildApi( settings: { onDidChangeExecutionDetails: interpreterService.onDidChangeInterpreterConfiguration, getExecutionDetails(resource?: Resource) { - const pythonPath = configurationService.getSettings(resource).pythonPath; + const {pythonPath} = configurationService.getSettings(resource); // If pythonPath equals an empty string, no interpreter is set. return { execCommand: pythonPath === '' ? undefined : [pythonPath] }; }, + getEnvFile(workspaceFolder?: Uri) : string { + return configurationService.getSettings(workspaceFolder).envFile + } }, // These are for backwards compatibility. Other extensions are using these APIs and we don't want // to force them to move to the jupyter extension ... yet. datascience: { registerRemoteServerProvider: jupyterIntegration ? jupyterIntegration.registerRemoteServerProvider.bind(jupyterIntegration) - : (noop as any), + : (noop as unknown as (serverProvider: IJupyterUriProvider) => void), showDataViewer: jupyterIntegration ? jupyterIntegration.showDataViewer.bind(jupyterIntegration) - : (noop as any), + : (noop as unknown as (dataProvider: IDataViewerDataProvider, title: string) => Promise), }, pylance: { getPythonPathVar: async (resource?: Uri) => { From 346659dd7c438c0d76bcf01375584ed07e1a1351 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Wed, 1 Feb 2023 17:35:54 -0500 Subject: [PATCH 2/3] add getEnvFile Function to api --- src/client/apiTypes.ts | 1 + src/test/api.functional.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/client/apiTypes.ts b/src/client/apiTypes.ts index a10fd2dccb96..e414fd886720 100644 --- a/src/client/apiTypes.ts +++ b/src/client/apiTypes.ts @@ -70,6 +70,7 @@ export interface IExtensionApi { */ execCommand: string[] | undefined; }; + getEnvFile(workspaceFolder?:Uri) : string; }; datascience: { diff --git a/src/test/api.functional.test.ts b/src/test/api.functional.test.ts index 490b5d86b8b3..c9b4403e59dc 100644 --- a/src/test/api.functional.test.ts +++ b/src/test/api.functional.test.ts @@ -72,6 +72,19 @@ suite('Extension API', () => { assert.deepEqual(execDetails, { execCommand: undefined }); }); + test('getEnvFile API returns expected object if interpreter is set', async () => { + const resource = Uri.parse('a'); + when(configurationService.getSettings(resource)).thenReturn({ envFile: 'envFile' } as any); + + const envFile = buildApi( + Promise.resolve(), + instance(serviceManager), + instance(serviceContainer), + ).settings.getEnvFile(resource); + + assert.equal(envFile, 'envFile'); + }); + test('Provide a callback which is called when interpreter setting changes', async () => { const expectedEvent = Typemoq.Mock.ofType>().object; when(interpreterService.onDidChangeInterpreterConfiguration).thenReturn(expectedEvent); From 6e2ffb8f97a752e550e5975dc1ff906ee9664962 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Wed, 1 Feb 2023 17:59:39 -0500 Subject: [PATCH 3/3] Update api file --- src/client/api.ts | 9 +++------ src/client/apiTypes.ts | 1 - src/test/api.functional.test.ts | 13 ------------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/client/api.ts b/src/client/api.ts index 37f40dadec76..787b4d8ba32c 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -64,23 +64,20 @@ export function buildApi( settings: { onDidChangeExecutionDetails: interpreterService.onDidChangeInterpreterConfiguration, getExecutionDetails(resource?: Resource) { - const {pythonPath} = configurationService.getSettings(resource); + const { pythonPath } = configurationService.getSettings(resource); // If pythonPath equals an empty string, no interpreter is set. return { execCommand: pythonPath === '' ? undefined : [pythonPath] }; }, - getEnvFile(workspaceFolder?: Uri) : string { - return configurationService.getSettings(workspaceFolder).envFile - } }, // These are for backwards compatibility. Other extensions are using these APIs and we don't want // to force them to move to the jupyter extension ... yet. datascience: { registerRemoteServerProvider: jupyterIntegration ? jupyterIntegration.registerRemoteServerProvider.bind(jupyterIntegration) - : (noop as unknown as (serverProvider: IJupyterUriProvider) => void), + : ((noop as unknown) as (serverProvider: IJupyterUriProvider) => void), showDataViewer: jupyterIntegration ? jupyterIntegration.showDataViewer.bind(jupyterIntegration) - : (noop as unknown as (dataProvider: IDataViewerDataProvider, title: string) => Promise), + : ((noop as unknown) as (dataProvider: IDataViewerDataProvider, title: string) => Promise), }, pylance: { getPythonPathVar: async (resource?: Uri) => { diff --git a/src/client/apiTypes.ts b/src/client/apiTypes.ts index e414fd886720..a10fd2dccb96 100644 --- a/src/client/apiTypes.ts +++ b/src/client/apiTypes.ts @@ -70,7 +70,6 @@ export interface IExtensionApi { */ execCommand: string[] | undefined; }; - getEnvFile(workspaceFolder?:Uri) : string; }; datascience: { diff --git a/src/test/api.functional.test.ts b/src/test/api.functional.test.ts index c9b4403e59dc..490b5d86b8b3 100644 --- a/src/test/api.functional.test.ts +++ b/src/test/api.functional.test.ts @@ -72,19 +72,6 @@ suite('Extension API', () => { assert.deepEqual(execDetails, { execCommand: undefined }); }); - test('getEnvFile API returns expected object if interpreter is set', async () => { - const resource = Uri.parse('a'); - when(configurationService.getSettings(resource)).thenReturn({ envFile: 'envFile' } as any); - - const envFile = buildApi( - Promise.resolve(), - instance(serviceManager), - instance(serviceContainer), - ).settings.getEnvFile(resource); - - assert.equal(envFile, 'envFile'); - }); - test('Provide a callback which is called when interpreter setting changes', async () => { const expectedEvent = Typemoq.Mock.ofType>().object; when(interpreterService.onDidChangeInterpreterConfiguration).thenReturn(expectedEvent);