1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
import { inject , injectable } from 'inversify' ;
4
- import * as semver from 'semver' ;
5
4
import { Disposable , extensions } from 'vscode' ;
6
5
import { IConfigurationService , IDisposableRegistry } from '../../common/types' ;
7
6
import { sendTelemetryEvent } from '../../telemetry' ;
@@ -10,7 +9,6 @@ import { JUPYTER_EXTENSION_ID, PYLANCE_EXTENSION_ID } from '../../common/constan
10
9
import { IExtensionSingleActivationService , LanguageServerType } from '../types' ;
11
10
import { traceLog , traceVerbose } from '../../logging' ;
12
11
import { IJupyterExtensionDependencyManager } from '../../common/application/types' ;
13
- import { ILanguageServerWatcher } from '../../languageServer/types' ;
14
12
import { IServiceContainer } from '../../ioc/types' ;
15
13
import { sleep } from '../../common/utils/async' ;
16
14
import { JupyterExtensionIntegration } from '../../jupyter/jupyterIntegration' ;
@@ -23,9 +21,7 @@ export class LspNotebooksExperiment implements IExtensionSingleActivationService
23
21
24
22
private isJupyterInstalled = false ;
25
23
26
- private isInExperiment : boolean | undefined ;
27
-
28
- private supportsInteractiveWindow : boolean | undefined ;
24
+ private isUsingPylance : boolean | undefined ;
29
25
30
26
constructor (
31
27
@inject ( IServiceContainer ) private readonly serviceContainer : IServiceContainer ,
@@ -50,101 +46,33 @@ export class LspNotebooksExperiment implements IExtensionSingleActivationService
50
46
return ;
51
47
}
52
48
53
- if ( LspNotebooksExperiment . jupyterSupportsNotebooksExperiment ( ) ) {
54
- await this . waitForJupyterToRegisterPythonPathFunction ( ) ;
55
- this . updateExperimentSupport ( ) ;
56
- }
49
+ await this . waitForJupyterToRegisterPythonPathFunction ( ) ;
50
+ this . updateExperimentSupport ( ) ;
57
51
58
52
this . isJupyterInstalled = true ;
59
53
}
60
54
61
- public isInNotebooksExperiment ( ) : boolean {
62
- return this . isInExperiment ?? false ;
63
- }
64
-
65
- public isInNotebooksExperimentWithInteractiveWindowSupport ( ) : boolean {
66
- return this . supportsInteractiveWindow ?? false ;
67
- }
68
-
69
55
private updateExperimentSupport ( ) : void {
70
- const wasInExperiment = this . isInExperiment ;
71
- const isInTreatmentGroup = true ;
72
56
const languageServerType = this . configurationService . getSettings ( ) . languageServer ;
73
57
74
- this . isInExperiment = false ;
58
+ this . isUsingPylance = false ;
75
59
if ( languageServerType !== LanguageServerType . Node ) {
76
- traceLog ( `LSP Notebooks experiment is disabled -- not using Pylance` ) ;
60
+ traceLog ( `LSP Notebooks is disabled -- not using Pylance` ) ;
77
61
} else if ( ! LspNotebooksExperiment . isJupyterInstalled ( ) ) {
78
- traceLog ( `LSP Notebooks experiment is disabled -- Jupyter disabled or not installed` ) ;
79
- } else if ( ! LspNotebooksExperiment . jupyterSupportsNotebooksExperiment ( ) ) {
80
- traceLog ( `LSP Notebooks experiment is disabled -- Jupyter does not support experiment` ) ;
62
+ traceLog ( `LSP Notebooks is disabled -- Jupyter disabled or not installed` ) ;
81
63
} else if ( ! LspNotebooksExperiment . isPylanceInstalled ( ) ) {
82
- traceLog ( `LSP Notebooks experiment is disabled -- Pylance disabled or not installed` ) ;
83
- } else if ( ! LspNotebooksExperiment . pylanceSupportsNotebooksExperiment ( ) ) {
84
- traceLog ( `LSP Notebooks experiment is disabled -- Pylance does not support experiment` ) ;
85
- } else if ( ! isInTreatmentGroup ) {
86
- traceLog ( `LSP Notebooks experiment is disabled -- not in treatment group` ) ;
87
- // to avoid scorecard SRMs, we're also triggering the telemetry for users who meet
88
- // the criteria to experience LSP notebooks, but may be in the control group.
89
- sendTelemetryEvent ( EventName . PYTHON_EXPERIMENTS_LSP_NOTEBOOKS ) ;
64
+ traceLog ( `LSP Notebooks is disabled -- Pylance disabled or not installed` ) ;
90
65
} else {
91
- this . isInExperiment = true ;
92
- traceLog ( `LSP Notebooks experiment is enabled` ) ;
66
+ this . isUsingPylance = true ;
67
+ traceLog ( `LSP Notebooks is enabled` ) ;
93
68
sendTelemetryEvent ( EventName . PYTHON_EXPERIMENTS_LSP_NOTEBOOKS ) ;
94
69
}
95
70
96
- this . supportsInteractiveWindow = false ;
97
- if ( ! this . isInExperiment ) {
98
- traceLog ( `LSP Notebooks interactive window support is disabled -- not in LSP Notebooks experiment` ) ;
99
- } else if ( ! LspNotebooksExperiment . jupyterSupportsLspInteractiveWindow ( ) ) {
100
- traceLog ( `LSP Notebooks interactive window support is disabled -- Jupyter is not new enough` ) ;
101
- } else if ( ! LspNotebooksExperiment . pylanceSupportsLspInteractiveWindow ( ) ) {
102
- traceLog ( `LSP Notebooks interactive window support is disabled -- Pylance is not new enough` ) ;
71
+ if ( ! this . isUsingPylance ) {
72
+ traceLog ( `LSP Notebooks interactive window support is disabled -- not using Pylance` ) ;
103
73
} else {
104
- this . supportsInteractiveWindow = true ;
105
74
traceLog ( `LSP Notebooks interactive window support is enabled` ) ;
106
75
}
107
-
108
- // Our "in experiment" status can only change from false to true. That's possible if Pylance
109
- // or Jupyter is installed after Python is activated. A true to false transition would require
110
- // either Pylance or Jupyter to be uninstalled or downgraded after Python activated, and that
111
- // would require VS Code to be reloaded before the new extension version could be used.
112
- if ( wasInExperiment === false && this . isInExperiment === true ) {
113
- const watcher = this . serviceContainer . get < ILanguageServerWatcher > ( ILanguageServerWatcher ) ;
114
- if ( watcher ) {
115
- watcher . restartLanguageServers ( ) ;
116
- }
117
- }
118
- }
119
-
120
- private static jupyterSupportsNotebooksExperiment ( ) : boolean {
121
- const jupyterVersion = extensions . getExtension ( JUPYTER_EXTENSION_ID ) ?. packageJSON . version ;
122
- return (
123
- jupyterVersion && ( semver . gt ( jupyterVersion , '2022.5.1001411044' ) || semver . patch ( jupyterVersion ) === 100 )
124
- ) ;
125
- }
126
-
127
- private static pylanceSupportsNotebooksExperiment ( ) : boolean {
128
- const pylanceVersion = extensions . getExtension ( PYLANCE_EXTENSION_ID ) ?. packageJSON . version ;
129
- return (
130
- pylanceVersion &&
131
- ( semver . gte ( pylanceVersion , '2022.5.3-pre.1' ) || semver . prerelease ( pylanceVersion ) ?. includes ( 'dev' ) )
132
- ) ;
133
- }
134
-
135
- private static jupyterSupportsLspInteractiveWindow ( ) : boolean {
136
- const jupyterVersion = extensions . getExtension ( JUPYTER_EXTENSION_ID ) ?. packageJSON . version ;
137
- return (
138
- jupyterVersion && ( semver . gt ( jupyterVersion , '2022.7.1002041057' ) || semver . patch ( jupyterVersion ) === 100 )
139
- ) ;
140
- }
141
-
142
- private static pylanceSupportsLspInteractiveWindow ( ) : boolean {
143
- const pylanceVersion = extensions . getExtension ( PYLANCE_EXTENSION_ID ) ?. packageJSON . version ;
144
- return (
145
- pylanceVersion &&
146
- ( semver . gte ( pylanceVersion , '2022.7.51' ) || semver . prerelease ( pylanceVersion ) ?. includes ( 'dev' ) )
147
- ) ;
148
76
}
149
77
150
78
private async waitForJupyterToRegisterPythonPathFunction ( ) : Promise < void > {
0 commit comments