File tree Expand file tree Collapse file tree 3 files changed +29
-13
lines changed Expand file tree Collapse file tree 3 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ import { EXTENSION_ROOT_DIR } from '../constants';
17
17
*/
18
18
@injectable ( )
19
19
export class Extensions implements IExtensions {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ private _cachedExtensions ?: readonly Extension < any > [ ] ;
22
+
20
23
constructor ( @inject ( IFileSystem ) private readonly fs : IFileSystem ) { }
21
24
22
25
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -32,6 +35,16 @@ export class Extensions implements IExtensions {
32
35
return extensions . getExtension ( extensionId ) ;
33
36
}
34
37
38
+ private get cachedExtensions ( ) {
39
+ if ( ! this . _cachedExtensions ) {
40
+ this . _cachedExtensions = this . _cachedExtensions || extensions . all ;
41
+ extensions . onDidChange ( ( ) => {
42
+ this . _cachedExtensions = this . _cachedExtensions || extensions . all ;
43
+ } ) ;
44
+ }
45
+ return this . _cachedExtensions ;
46
+ }
47
+
35
48
/**
36
49
* Code borrowed from:
37
50
* https://github.com/microsoft/vscode-jupyter/blob/67fe33d072f11d6443cf232a06bed0ac5e24682c/src/platform/common/application/extensions.node.ts
@@ -51,7 +64,8 @@ export class Extensions implements IExtensions {
51
64
} )
52
65
. filter ( ( item ) => item && ! item . toLowerCase ( ) . startsWith ( pythonExtRoot ) )
53
66
. filter ( ( item ) =>
54
- this . all . some (
67
+ // Use cached list of extensions as we need this to be fast.
68
+ this . cachedExtensions . some (
55
69
( ext ) => item ! . includes ( ext . extensionUri . path ) || item ! . includes ( ext . extensionUri . fsPath ) ,
56
70
) ,
57
71
) as string [ ] ;
Original file line number Diff line number Diff line change @@ -125,16 +125,20 @@ export function buildProposedApi(
125
125
const extensions = serviceContainer . get < IExtensions > ( IExtensions ) ;
126
126
const envVarsProvider = serviceContainer . get < IEnvironmentVariablesProvider > ( IEnvironmentVariablesProvider ) ;
127
127
function sendApiTelemetry ( apiName : string , args ?: unknown ) {
128
- extensions
129
- . determineExtensionFromCallStack ( )
130
- . then ( ( info ) => {
131
- sendTelemetryEvent ( EventName . PYTHON_ENVIRONMENTS_API , undefined , {
132
- apiName,
133
- extensionId : info . extensionId ,
134
- } ) ;
135
- traceVerbose ( `Extension ${ info . extensionId } accessed ${ apiName } with args: ${ JSON . stringify ( args ) } ` ) ;
136
- } )
137
- . ignoreErrors ( ) ;
128
+ setTimeout ( ( ) =>
129
+ extensions
130
+ . determineExtensionFromCallStack ( )
131
+ . then ( ( info ) => {
132
+ sendTelemetryEvent ( EventName . PYTHON_ENVIRONMENTS_API , undefined , {
133
+ apiName,
134
+ extensionId : info . extensionId ,
135
+ } ) ;
136
+ traceVerbose (
137
+ `Extension ${ info . extensionId } accessed ${ apiName } with args: ${ JSON . stringify ( args ) } ` ,
138
+ ) ;
139
+ } )
140
+ . ignoreErrors ( ) ,
141
+ ) ;
138
142
}
139
143
disposables . push (
140
144
discoveryApi . onChanged ( ( e ) => {
Original file line number Diff line number Diff line change @@ -99,8 +99,6 @@ suite('Proposed Extension API', () => {
99
99
} ) ;
100
100
101
101
teardown ( ( ) => {
102
- // Verify each API method sends telemetry regarding who called the API.
103
- extensions . verifyAll ( ) ;
104
102
sinon . restore ( ) ;
105
103
} ) ;
106
104
You can’t perform that action at this time.
0 commit comments