@@ -7,13 +7,14 @@ import { inject, injectable } from 'inversify';
77import {
88 CancellationToken , OutputChannel , TextDocument , Uri
99} from 'vscode' ;
10+ import { IWorkspaceService } from '../common/application/types' ;
1011import {
1112 IConfigurationService , ILogger , Product
1213} from '../common/types' ;
1314import { IServiceContainer } from '../ioc/types' ;
1415import { Bandit } from './bandit' ;
1516import { Flake8 } from './flake8' ;
16- import { LinterInfo } from './linterInfo' ;
17+ import { LinterInfo , PylintLinterInfo } from './linterInfo' ;
1718import { MyPy } from './mypy' ;
1819import { Pep8 } from './pep8' ;
1920import { Prospector } from './prospector' ;
@@ -36,17 +37,17 @@ class DisabledLinter implements ILinter {
3637
3738@injectable ( )
3839export class LinterManager implements ILinterManager {
39- private lintingEnabledSettingName = 'enabled' ;
4040 private linters : ILinterInfo [ ] ;
4141 private configService : IConfigurationService ;
42- private checkedForInstalledLinters : boolean = false ;
42+ private checkedForInstalledLinters = new Set < string > ( ) ;
4343
44- constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ) {
44+ constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ,
45+ @inject ( IWorkspaceService ) private readonly workspaceService : IWorkspaceService ) {
4546 this . configService = serviceContainer . get < IConfigurationService > ( IConfigurationService ) ;
4647 this . linters = [
4748 new LinterInfo ( Product . bandit , 'bandit' , this . configService ) ,
4849 new LinterInfo ( Product . flake8 , 'flake8' , this . configService ) ,
49- new LinterInfo ( Product . pylint , 'pylint' , this . configService , [ '.pylintrc' , 'pylintrc' ] ) ,
50+ new PylintLinterInfo ( this . configService , this . workspaceService , [ '.pylintrc' , 'pylintrc' ] ) ,
5051 new LinterInfo ( Product . mypy , 'mypy' , this . configService ) ,
5152 new LinterInfo ( Product . pep8 , 'pep8' , this . configService ) ,
5253 new LinterInfo ( Product . prospector , 'prospector' , this . configService ) ,
@@ -70,11 +71,11 @@ export class LinterManager implements ILinterManager {
7071 public async isLintingEnabled ( silent : boolean , resource ?: Uri ) : Promise < boolean > {
7172 const settings = this . configService . getSettings ( resource ) ;
7273 const activeLintersPresent = await this . getActiveLinters ( silent , resource ) ;
73- return ( settings . linting [ this . lintingEnabledSettingName ] as boolean ) && activeLintersPresent . length > 0 ;
74+ return settings . linting . enabled && activeLintersPresent . length > 0 ;
7475 }
7576
7677 public async enableLintingAsync ( enable : boolean , resource ?: Uri ) : Promise < void > {
77- await this . configService . updateSetting ( ` linting.${ this . lintingEnabledSettingName } ` , enable , resource ) ;
78+ await this . configService . updateSetting ( ' linting.enabled' , enable , resource ) ;
7879 }
7980
8081 public async getActiveLinters ( silent : boolean , resource ?: Uri ) : Promise < ILinterInfo [ ] > {
@@ -137,23 +138,21 @@ export class LinterManager implements ILinterManager {
137138 throw new Error ( error ) ;
138139 }
139140
140- protected async enableUnconfiguredLinters ( resource ?: Uri ) : Promise < boolean > {
141- // if we've already checked during this session, don't bother again
142- if ( this . checkedForInstalledLinters ) {
143- return false ;
141+ protected async enableUnconfiguredLinters ( resource ?: Uri ) : Promise < void > {
142+ const settings = this . configService . getSettings ( resource ) ;
143+ if ( ! settings . linting . pylintEnabled || ! settings . linting . enabled ) {
144+ return ;
145+ }
146+ // If we've already checked during this session for the same workspace and Python path, then don't bother again.
147+ const workspaceKey = `${ this . workspaceService . getWorkspaceFolderIdentifier ( resource ) } ${ settings . pythonPath } ` ;
148+ if ( this . checkedForInstalledLinters . has ( workspaceKey ) ) {
149+ return ;
144150 }
145- this . checkedForInstalledLinters = true ;
151+ this . checkedForInstalledLinters . add ( workspaceKey ) ;
146152
147153 // only check & ask the user if they'd like to enable pylint
148- const pylintInfo = this . linters . find (
149- ( linter : ILinterInfo ) => linter . id === 'pylint'
150- ) ;
151-
152- // If linting is disabled, don't bother checking further.
153- if ( pylintInfo && await this . isLintingEnabled ( true , resource ) ) {
154- const activator = this . serviceContainer . get < IAvailableLinterActivator > ( IAvailableLinterActivator ) ;
155- return activator . promptIfLinterAvailable ( pylintInfo , resource ) ;
156- }
157- return false ;
154+ const pylintInfo = this . linters . find ( linter => linter . id === 'pylint' ) ;
155+ const activator = this . serviceContainer . get < IAvailableLinterActivator > ( IAvailableLinterActivator ) ;
156+ await activator . promptIfLinterAvailable ( pylintInfo ! , resource ) ;
158157 }
159158}
0 commit comments