@@ -32,15 +32,15 @@ import { getPathFromPythonCommand } from './common/utils';
3232import { JupyterProvider } from './jupyter/provider' ;
3333import { activateGoToObjectDefinitionProvider } from './providers/objectDefinitionProvider' ;
3434
35- const PYTHON : vscode . DocumentFilter = { language : 'python' , scheme : 'file' } ;
35+ const PYTHON : vscode . DocumentFilter = { language : 'python' } ;
3636let unitTestOutChannel : vscode . OutputChannel ;
3737let formatOutChannel : vscode . OutputChannel ;
3838let lintingOutChannel : vscode . OutputChannel ;
3939let jupMain : jup . Jupyter ;
4040export function activate ( context : vscode . ExtensionContext ) {
41- let pythonSettings = settings . PythonSettings . getInstance ( ) ;
42- let pythonExt = new PythonExt ( ) ;
43- const hasPySparkInCompletionPath = pythonSettings . autoComplete . extraPaths . some ( p => p . toLowerCase ( ) . indexOf ( 'spark' ) >= 0 ) ;
41+ const pythonSettings = settings . PythonSettings . getInstance ( ) ;
42+ const pythonExt = new PythonExt ( ) ;
43+ context . subscriptions . push ( pythonExt ) ;
4444 // telemetryHelper.sendTelemetryEvent(telemetryContracts.EVENT_LOAD, {
4545 // CodeComplete_Has_ExtraPaths: pythonSettings.autoComplete.extraPaths.length > 0 ? 'true' : 'false',
4646 // Format_Has_Custom_Python_Path: pythonSettings.pythonPath.length !== 'python'.length ? 'true' : 'false',
@@ -149,42 +149,39 @@ export function activate(context: vscode.ExtensionContext) {
149149 context . subscriptions . push ( activateSingleFileDebug ( ) ) ;
150150}
151151
152- // this method is called when your extension is deactivated
153- export function deactivate ( ) {
154- }
155- class PythonExt {
152+ class PythonExt implements vscode . Disposable {
156153
157- private _isDjangoProject : ContextKey ;
154+ private isDjangoProject : ContextKey ;
158155
159156 constructor ( ) {
160- this . _isDjangoProject = new ContextKey ( 'python.isDjangoProject' ) ;
161- this . _ensureState ( ) ;
157+ this . isDjangoProject = new ContextKey ( 'python.isDjangoProject' ) ;
158+ this . ensureState ( ) ;
162159 }
163-
164- private _ensureState ( ) : void {
160+ public dispose ( ) {
161+ this . isDjangoProject = null ;
162+ }
163+ private ensureState ( ) : void {
165164 // context: python.isDjangoProject
166165 if ( typeof vscode . workspace . rootPath === 'string' ) {
167- this . _isDjangoProject . set ( fs . existsSync ( vscode . workspace . rootPath . concat ( "/manage.py" ) ) ) ;
166+ this . isDjangoProject . set ( fs . existsSync ( vscode . workspace . rootPath . concat ( "/manage.py" ) ) ) ;
168167 }
169168 else {
170- this . _isDjangoProject . set ( false ) ;
169+ this . isDjangoProject . set ( false ) ;
171170 }
172171 }
173172}
174173
175174class ContextKey {
176- private _name : string ;
177- private _lastValue : boolean ;
175+ private lastValue : boolean ;
178176
179- constructor ( name : string ) {
180- this . _name = name ;
177+ constructor ( private name : string ) {
181178 }
182179
183180 public set ( value : boolean ) : void {
184- if ( this . _lastValue === value ) {
181+ if ( this . lastValue === value ) {
185182 return ;
186183 }
187- this . _lastValue = value ;
188- vscode . commands . executeCommand ( 'setContext' , this . _name , this . _lastValue ) ;
184+ this . lastValue = value ;
185+ vscode . commands . executeCommand ( 'setContext' , this . name , this . lastValue ) ;
189186 }
190187}
0 commit comments