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
16 changes: 15 additions & 1 deletion src/client/common/application/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { EXTENSION_ROOT_DIR } from '../constants';
*/
@injectable()
export class Extensions implements IExtensions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _cachedExtensions?: readonly Extension<any>[];

constructor(@inject(IFileSystem) private readonly fs: IFileSystem) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -32,6 +35,16 @@ export class Extensions implements IExtensions {
return extensions.getExtension(extensionId);
}

private get cachedExtensions() {
if (!this._cachedExtensions) {
this._cachedExtensions = this._cachedExtensions || extensions.all;
extensions.onDidChange(() => {
this._cachedExtensions = this._cachedExtensions || extensions.all;
});
}
return this._cachedExtensions;
}

/**
* Code borrowed from:
* https://github.com/microsoft/vscode-jupyter/blob/67fe33d072f11d6443cf232a06bed0ac5e24682c/src/platform/common/application/extensions.node.ts
Expand All @@ -51,7 +64,8 @@ export class Extensions implements IExtensions {
})
.filter((item) => item && !item.toLowerCase().startsWith(pythonExtRoot))
.filter((item) =>
this.all.some(
// Use cached list of extensions as we need this to be fast.
this.cachedExtensions.some(
Copy link
Member

Choose a reason for hiding this comment

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

Another possible solution is capture all extension uris at the entrance of determineExtensionFromCallStack, if we don't want to hold all extension info objects in memory for too long.

Copy link
Author

Choose a reason for hiding this comment

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

aah yes, will leave that change for kartik

(ext) => item!.includes(ext.extensionUri.path) || item!.includes(ext.extensionUri.fsPath),
),
) as string[];
Expand Down
24 changes: 14 additions & 10 deletions src/client/proposedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,20 @@ export function buildProposedApi(
const extensions = serviceContainer.get<IExtensions>(IExtensions);
const envVarsProvider = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
function sendApiTelemetry(apiName: string, args?: unknown) {
extensions
.determineExtensionFromCallStack()
.then((info) => {
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
apiName,
extensionId: info.extensionId,
});
traceVerbose(`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`);
})
.ignoreErrors();
setTimeout(() =>
extensions
.determineExtensionFromCallStack()
.then((info) => {
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
apiName,
extensionId: info.extensionId,
});
traceVerbose(
`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`,
);
})
.ignoreErrors(),
);
}
disposables.push(
discoveryApi.onChanged((e) => {
Expand Down
2 changes: 0 additions & 2 deletions src/test/proposedApi.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ suite('Proposed Extension API', () => {
});

teardown(() => {
// Verify each API method sends telemetry regarding who called the API.
extensions.verifyAll();
sinon.restore();
});

Expand Down