Skip to content

Commit 321d204

Browse files
Harry-Hopkinsonpull[bot]
authored andcommitted
Fixed namespace and type errors, changed null to undefined where applicable (#18345)
* Fixed namespace and type errors * Fetch Jupyter Notebook Interpreters if there are multiple available and fetches the path of the interpreter. * Complying types to reduce errors * Ran prettier * News * Used prettier on service.ts
1 parent 1f48065 commit 321d204

File tree

7 files changed

+47
-24
lines changed

7 files changed

+47
-24
lines changed

news/3 Code Health/18345.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed typescript and namespace errors. (Thanks [Harry-Hopkinson](https://github.com/Harry-Hopkinson))

src/client/browser/extension.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function runPylance(
8383

8484
const languageClient = new LanguageClient('python', 'Python Language Server', clientOptions, worker);
8585

86-
languageClient.onDidChangeState((e) => {
86+
languageClient.onDidChangeState((e): void => {
8787
// The client's on* methods must be called after the client has started, but if called too
8888
// late the server may have already sent a message (which leads to failures). Register
8989
// these on the state change to running to ensure they are ready soon enough.
@@ -97,20 +97,27 @@ async function runPylance(
9797
),
9898
);
9999

100-
languageClient.onTelemetry((telemetryEvent) => {
101-
const eventName = telemetryEvent.EventName || EventName.LANGUAGE_SERVER_TELEMETRY;
102-
const formattedProperties = {
103-
...telemetryEvent.Properties,
104-
// Replace all slashes in the method name so it doesn't get scrubbed by vscode-extension-telemetry.
105-
method: telemetryEvent.Properties.method?.replace(/\//g, '.'),
106-
};
107-
sendTelemetryEventBrowser(
108-
eventName,
109-
telemetryEvent.Measurements,
110-
formattedProperties,
111-
telemetryEvent.Exception,
112-
);
113-
});
100+
languageClient.onTelemetry(
101+
(telemetryEvent: {
102+
EventName: EventName;
103+
Properties: { method: string };
104+
Measurements: number | Record<string, number> | undefined;
105+
Exception: Error | undefined;
106+
}) => {
107+
const eventName = telemetryEvent.EventName || EventName.LANGUAGE_SERVER_TELEMETRY;
108+
const formattedProperties = {
109+
...telemetryEvent.Properties,
110+
// Replace all slashes in the method name so it doesn't get scrubbed by vscode-extension-telemetry.
111+
method: telemetryEvent.Properties.method?.replace(/\//g, '.'),
112+
};
113+
sendTelemetryEventBrowser(
114+
eventName,
115+
telemetryEvent.Measurements,
116+
formattedProperties,
117+
telemetryEvent.Exception,
118+
);
119+
},
120+
);
114121
});
115122

116123
const disposable = languageClient.start();

src/client/browser/intellisenseStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export function createStatusItem(): vscode.Disposable {
2222
return statusItem;
2323
}
2424
// eslint-disable-next-line @typescript-eslint/no-empty-function
25-
return { dispose: () => {} };
25+
return { dispose: () => undefined };
2626
}

src/client/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ initializeFileLogging(logDispose);
2929
// loading starts here
3030

3131
import { ProgressLocation, ProgressOptions, window } from 'vscode';
32-
3332
import { buildApi } from './api';
3433
import { IApplicationShell, IWorkspaceService } from './common/application/types';
3534
import { IAsyncDisposableRegistry, IDisposableRegistry, IExperimentService, IExtensionContext } from './common/types';
@@ -193,6 +192,6 @@ function notifyUser(msg: string) {
193192
}
194193
appShell.showErrorMessage(msg).ignoreErrors();
195194
} catch (ex) {
196-
traceError('failed to notify user', ex);
195+
traceError('Failed to Notify User', ex);
197196
}
198197
}

src/client/interpreter/helpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IDocumentManager, IWorkspaceService } from '../common/application/types
44
import { FileSystemPaths } from '../common/platform/fs-paths';
55
import { Resource } from '../common/types';
66
import { IServiceContainer } from '../ioc/types';
7+
import { PythonEnvSource } from '../pythonEnvironments/base/info';
78
import { compareSemVerLikeVersions } from '../pythonEnvironments/base/info/pythonVersion';
89
import { EnvironmentType, getEnvironmentTypeName, PythonEnvironment } from '../pythonEnvironments/info';
910
import { IComponentAdapter, IInterpreterHelper, WorkspacePythonPath } from './contracts';
@@ -66,6 +67,22 @@ export class InterpreterHelper implements IInterpreterHelper {
6667
return this.pyenvs.getInterpreterInformation(pythonPath);
6768
}
6869

70+
public async getInterpreters({ resource, source }: { resource?: Uri; source?: PythonEnvSource[] } = {}): Promise<
71+
PythonEnvironment[]
72+
> {
73+
const interpreters = await this.pyenvs.getInterpreters(resource, source);
74+
return sortInterpreters(interpreters);
75+
}
76+
77+
public async getInterpreterPath(pythonPath: string): Promise<string> {
78+
const interpreterInfo: any = await this.getInterpreterInformation(pythonPath);
79+
if (interpreterInfo) {
80+
return interpreterInfo.path;
81+
} else {
82+
return pythonPath;
83+
}
84+
}
85+
6986
public async isMacDefaultPythonPath(pythonPath: string): Promise<boolean> {
7087
return this.pyenvs.isMacDefaultPythonPath(pythonPath);
7188
}

src/client/interpreter/interpreterService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class InterpreterService implements Disposable, IInterpreterService {
107107
interpreterDisplay.registerVisibilityFilter(filter);
108108
}
109109
disposables.push(
110-
this.onDidChangeInterpreters((e) => {
110+
this.onDidChangeInterpreters((e): void => {
111111
const interpreter = e.old ?? e.new;
112112
if (interpreter) {
113113
this.didChangeInterpreterInformation.fire(interpreter);
@@ -119,7 +119,7 @@ export class InterpreterService implements Disposable, IInterpreterService {
119119
// To handle scenario when language mode is set to "python"
120120
filter.interpreterVisibilityEmitter.fire();
121121
}),
122-
documentManager.onDidChangeActiveTextEditor((e) => {
122+
documentManager.onDidChangeActiveTextEditor((e): void => {
123123
filter.interpreterVisibilityEmitter.fire();
124124
if (e && e.document) {
125125
this.refresh(e.document.uri);
@@ -129,7 +129,7 @@ export class InterpreterService implements Disposable, IInterpreterService {
129129
const pySettings = this.configService.getSettings();
130130
this._pythonPathSetting = pySettings.pythonPath;
131131
disposables.push(
132-
this.interpreterPathService.onDidChange((i) => {
132+
this.interpreterPathService.onDidChange((i): void => {
133133
this._onConfigChanged(i.uri);
134134
}),
135135
);

typings/index.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
54
// Added to allow compilation of backbone types pulled in from ipywidgets (@jupyterlab/widgets).
6-
declare module JQuery {
7-
type TriggeredEvent = any;
5+
declare namespace JQuery {
6+
type TriggeredEvent = unknown;
87
}

0 commit comments

Comments
 (0)