11'use strict' ;
22
3+ // eslint-disable-next-line camelcase
34import * as child_process from 'child_process' ;
45import * as path from 'path' ;
56import {
@@ -13,7 +14,7 @@ import {
1314 WorkspaceConfiguration ,
1415} from 'vscode' ;
1516import { LanguageServerType } from '../activation/types' ;
16- import '../common /extensions' ;
17+ import './extensions' ;
1718import { IInterpreterAutoSeletionProxyService , IInterpreterSecurityService } from '../interpreter/autoSelection/types' ;
1819import { LogLevel } from '../logging/levels' ;
1920import { sendTelemetryEvent } from '../telemetry' ;
@@ -56,6 +57,7 @@ export class PythonSettings implements IPythonSettings {
5657 public get pythonPath ( ) : string {
5758 return this . _pythonPath ;
5859 }
60+
5961 public set pythonPath ( value : string ) {
6062 if ( this . _pythonPath === value ) {
6163 return ;
@@ -72,6 +74,7 @@ export class PythonSettings implements IPythonSettings {
7274 public get defaultInterpreterPath ( ) : string {
7375 return this . _defaultInterpreterPath ;
7476 }
77+
7578 public set defaultInterpreterPath ( value : string ) {
7679 if ( this . _defaultInterpreterPath === value ) {
7780 return ;
@@ -84,41 +87,73 @@ export class PythonSettings implements IPythonSettings {
8487 this . _defaultInterpreterPath = value ;
8588 }
8689 }
90+
8791 private static pythonSettings : Map < string , PythonSettings > = new Map < string , PythonSettings > ( ) ;
92+
8893 public showStartPage = true ;
94+
8995 public downloadLanguageServer = true ;
96+
9097 public jediPath = '' ;
98+
9199 public jediMemoryLimit = 1024 ;
100+
92101 public envFile = '' ;
102+
93103 public venvPath = '' ;
104+
94105 public venvFolders : string [ ] = [ ] ;
106+
95107 public condaPath = '' ;
108+
96109 public pipenvPath = '' ;
110+
97111 public poetryPath = '' ;
112+
98113 public devOptions : string [ ] = [ ] ;
114+
99115 public linting ! : ILintingSettings ;
116+
100117 public formatting ! : IFormattingSettings ;
118+
101119 public autoComplete ! : IAutoCompleteSettings ;
120+
102121 public testing ! : ITestingSettings ;
122+
103123 public terminal ! : ITerminalSettings ;
124+
104125 public sortImports ! : ISortImportSettings ;
126+
105127 public workspaceSymbols ! : IWorkspaceSymbolSettings ;
128+
106129 public disableInstallationChecks = false ;
130+
107131 public globalModuleInstallation = false ;
132+
108133 public analysis ! : IAnalysisSettings ;
109- public autoUpdateLanguageServer : boolean = true ;
134+
135+ public autoUpdateLanguageServer = true ;
136+
110137 public insidersChannel ! : ExtensionChannels ;
138+
111139 public experiments ! : IExperiments ;
140+
112141 public languageServer : LanguageServerType = LanguageServerType . Microsoft ;
142+
113143 public logging : ILoggingSettings = { level : LogLevel . Error } ;
114- public useIsolation : boolean = true ;
144+
145+ public useIsolation = true ;
115146
116147 protected readonly changed = new EventEmitter < void > ( ) ;
148+
117149 private workspaceRoot : Resource ;
150+
118151 private disposables : Disposable [ ] = [ ] ;
119152
120153 private _pythonPath = '' ;
154+
121155 private _defaultInterpreterPath = '' ;
156+
122157 private readonly workspace : IWorkspaceService ;
123158
124159 constructor (
@@ -158,7 +193,8 @@ export class PythonSettings implements IPythonSettings {
158193 PythonSettings . pythonSettings . set ( workspaceFolderKey , settings ) ;
159194 // Pass null to avoid VSC from complaining about not passing in a value.
160195
161- const config = workspace . getConfiguration ( 'editor' , resource ? resource : ( null as any ) ) ;
196+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
197+ const config = workspace . getConfiguration ( 'editor' , resource || ( null as any ) ) ;
162198 const formatOnType = config ? config . get ( 'formatOnType' , false ) : false ;
163199 sendTelemetryEvent ( EventName . COMPLETION_ADD_BRACKETS , undefined , {
164200 enabled : settings . autoComplete ? settings . autoComplete . addBrackets : false ,
@@ -185,7 +221,7 @@ export class PythonSettings implements IPythonSettings {
185221 return { uri : workspaceFolderUri , target } ;
186222 }
187223
188- public static dispose ( ) {
224+ public static dispose ( ) : void {
189225 if ( ! isTestExecution ( ) ) {
190226 throw new Error ( 'Dispose can only be called from unit tests' ) ;
191227 }
@@ -195,6 +231,7 @@ export class PythonSettings implements IPythonSettings {
195231 }
196232
197233 public static toSerializable ( settings : IPythonSettings ) : IPythonSettings {
234+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
198235 const clone : any = { } ;
199236 const keys = Object . entries ( settings ) ;
200237 keys . forEach ( ( e ) => {
@@ -207,19 +244,19 @@ export class PythonSettings implements IPythonSettings {
207244 return clone as IPythonSettings ;
208245 }
209246
210- public dispose ( ) {
247+ public dispose ( ) : void {
211248 this . disposables . forEach ( ( disposable ) => disposable && disposable . dispose ( ) ) ;
212249 this . disposables = [ ] ;
213250 }
214251
215- protected update ( pythonSettings : WorkspaceConfiguration ) {
252+ protected update ( pythonSettings : WorkspaceConfiguration ) : void {
216253 const workspaceRoot = this . workspaceRoot ?. fsPath ;
217254 const systemVariables : SystemVariables = new SystemVariables ( undefined , workspaceRoot , this . workspace ) ;
218255
219256 this . pythonPath = this . getPythonPath ( pythonSettings , systemVariables , workspaceRoot ) ;
220257
221258 const defaultInterpreterPath = systemVariables . resolveAny ( pythonSettings . get < string > ( 'defaultInterpreterPath' ) ) ;
222- this . defaultInterpreterPath = defaultInterpreterPath ? defaultInterpreterPath : DEFAULT_INTERPRETER_SETTING ;
259+ this . defaultInterpreterPath = defaultInterpreterPath || DEFAULT_INTERPRETER_SETTING ;
223260 this . defaultInterpreterPath = getAbsolutePath ( this . defaultInterpreterPath , workspaceRoot ) ;
224261
225262 this . venvPath = systemVariables . resolveAny ( pythonSettings . get < string > ( 'venvPath' ) ) ! ;
@@ -259,9 +296,11 @@ export class PythonSettings implements IPythonSettings {
259296 this . envFile = systemVariables . resolveAny ( envFileSetting ) ! ;
260297 sendSettingTelemetry ( this . workspace , envFileSetting ) ;
261298
299+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
262300 this . devOptions = systemVariables . resolveAny ( pythonSettings . get < any [ ] > ( 'devOptions' ) ) ! ;
263301 this . devOptions = Array . isArray ( this . devOptions ) ? this . devOptions : [ ] ;
264302
303+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
265304 const loggingSettings = systemVariables . resolveAny ( pythonSettings . get < any > ( 'logging' ) ) ! ;
266305 loggingSettings . level = convertSettingTypeToLogLevel ( loggingSettings . level ) ;
267306 if ( this . logging ) {
@@ -520,6 +559,8 @@ export class PythonSettings implements IPythonSettings {
520559 } else {
521560 this . experiments = experiments ;
522561 }
562+ // Note we directly access experiment settings using workspace service in ExperimentService class.
563+ // Any changes here specific to these settings should propogate their as well.
523564 this . experiments = this . experiments
524565 ? this . experiments
525566 : {
@@ -536,11 +577,13 @@ export class PythonSettings implements IPythonSettings {
536577 this . insidersChannel = pythonSettings . get < ExtensionChannels > ( 'insidersChannel' ) ! ;
537578 }
538579
539- protected getPythonExecutable ( pythonPath : string ) {
580+ // eslint-disable-next-line class-methods-use-this
581+ protected getPythonExecutable ( pythonPath : string ) : string {
540582 return getPythonExecutable ( pythonPath ) ;
541583 }
542- protected onWorkspaceFoldersChanged ( ) {
543- //If an activated workspace folder was removed, delete its key
584+
585+ protected onWorkspaceFoldersChanged ( ) : void {
586+ // If an activated workspace folder was removed, delete its key
544587 const workspaceKeys = this . workspace . workspaceFolders ! . map ( ( workspaceFolder ) => workspaceFolder . uri . fsPath ) ;
545588 const activatedWkspcKeys = Array . from ( PythonSettings . pythonSettings . keys ( ) ) ;
546589 const activatedWkspcFoldersRemoved = activatedWkspcKeys . filter ( ( item ) => workspaceKeys . indexOf ( item ) < 0 ) ;
@@ -550,6 +593,7 @@ export class PythonSettings implements IPythonSettings {
550593 }
551594 }
552595 }
596+
553597 protected initialize ( ) : void {
554598 const onDidChange = ( ) => {
555599 const currentConfig = this . workspace . getConfiguration ( 'python' , this . workspaceRoot ) ;
@@ -582,8 +626,9 @@ export class PythonSettings implements IPythonSettings {
582626 this . update ( initialConfig ) ;
583627 }
584628 }
629+
585630 @debounceSync ( 1 )
586- protected debounceChangeNotification ( ) {
631+ protected debounceChangeNotification ( ) : void {
587632 this . changed . fire ( ) ;
588633 }
589634
@@ -625,13 +670,11 @@ export class PythonSettings implements IPythonSettings {
625670 . setWorkspaceInterpreter ( this . workspaceRoot , autoSelectedPythonInterpreter )
626671 . ignoreErrors ( ) ;
627672 }
628- } else {
629- if ( autoSelectedPythonInterpreter && this . workspaceRoot ) {
630- this . pythonPath = autoSelectedPythonInterpreter . path ;
631- this . interpreterAutoSelectionService
632- . setWorkspaceInterpreter ( this . workspaceRoot , autoSelectedPythonInterpreter )
633- . ignoreErrors ( ) ;
634- }
673+ } else if ( autoSelectedPythonInterpreter && this . workspaceRoot ) {
674+ this . pythonPath = autoSelectedPythonInterpreter . path ;
675+ this . interpreterAutoSelectionService
676+ . setWorkspaceInterpreter ( this . workspaceRoot , autoSelectedPythonInterpreter )
677+ . ignoreErrors ( ) ;
635678 }
636679 }
637680 if ( inExperiment && this . pythonPath === DEFAULT_INTERPRETER_SETTING ) {
0 commit comments