@@ -14,17 +14,16 @@ import * as settings from '../common/configSettings';
1414import * as telemetryHelper from '../common/telemetry' ;
1515import * as telemetryContracts from '../common/telemetryContracts' ;
1616import * as fs from 'fs' ;
17+ import { LinterErrors } from '../common/constants' ;
18+ const Minimatch = require ( "minimatch" ) . Minimatch ;
1719
18- import { LinterErrors } from '../common/constants'
1920const lintSeverityToVSSeverity = new Map < linter . LintMessageSeverity , vscode . DiagnosticSeverity > ( ) ;
20- lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Error , vscode . DiagnosticSeverity . Error )
21- lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Hint , vscode . DiagnosticSeverity . Hint )
22- lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Information , vscode . DiagnosticSeverity . Information )
23- lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Warning , vscode . DiagnosticSeverity . Warning )
21+ lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Error , vscode . DiagnosticSeverity . Error ) ;
22+ lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Hint , vscode . DiagnosticSeverity . Hint ) ;
23+ lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Information , vscode . DiagnosticSeverity . Information ) ;
24+ lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Warning , vscode . DiagnosticSeverity . Warning ) ;
2425
2526function createDiagnostics ( message : linter . ILintMessage , txtDocumentLines : string [ ] ) : vscode . Diagnostic {
26- let sourceLine = txtDocumentLines [ message . line - 1 ] ;
27- let sourceStart = sourceLine . substring ( message . column - 1 ) ;
2827 let endCol = txtDocumentLines [ message . line - 1 ] . length ;
2928
3029 // try to get the first word from the startig position
@@ -51,17 +50,31 @@ export class LintProvider extends vscode.Disposable {
5150 private pendingLintings = new Map < string , vscode . CancellationTokenSource > ( ) ;
5251 private outputChannel : vscode . OutputChannel ;
5352 private context : vscode . ExtensionContext ;
54-
53+ private disposables : vscode . Disposable [ ] ;
54+ private ignoreMinmatches : { match : ( fname : string ) => boolean } [ ] ;
5555 public constructor ( context : vscode . ExtensionContext , outputChannel : vscode . OutputChannel ,
5656 private workspaceRootPath : string , private documentHasJupyterCodeCells : DocumentHasJupyterCodeCells ) {
5757 super ( ( ) => { } ) ;
5858 this . outputChannel = outputChannel ;
5959 this . context = context ;
6060 this . settings = settings . PythonSettings . getInstance ( ) ;
61-
61+ this . disposables = [ ] ;
62+ this . ignoreMinmatches = [ ] ;
6263 this . initialize ( ) ;
63- }
6464
65+ this . disposables . push ( vscode . workspace . onDidChangeConfiguration ( this . onConfigChanged . bind ( this ) ) ) ;
66+ }
67+ dispose ( ) {
68+ this . disposables . forEach ( d => d . dispose ( ) ) ;
69+ }
70+ private onConfigChanged ( ) {
71+ this . initializeGlobs ( ) ;
72+ }
73+ private initializeGlobs ( ) {
74+ this . ignoreMinmatches = settings . PythonSettings . getInstance ( ) . linting . ignorePatterns . map ( pattern => {
75+ return new Minimatch ( pattern ) ;
76+ } ) ;
77+ }
6578 private isDocumentOpen ( uri : vscode . Uri ) : boolean {
6679 return vscode . window . visibleTextEditors . some ( editor => editor . document && editor . document . uri . fsPath === uri . fsPath ) ;
6780 }
@@ -89,7 +102,7 @@ export class LintProvider extends vscode.Disposable {
89102 if ( e . languageId !== 'python' || ! this . settings . linting . enabled ) {
90103 return ;
91104 }
92- if ( ! e . uri . path || ( path . basename ( e . uri . path ) === e . uri . path && ! fs . existsSync ( e . uri . path ) ) ) {
105+ if ( ! e . uri . path || ( path . basename ( e . uri . path ) === e . uri . path && ! fs . existsSync ( e . uri . path ) ) ) {
93106 return ;
94107 }
95108 this . lintDocument ( e , e . uri , e . getText ( ) . split ( / \r ? \n / g) , 100 ) ;
@@ -106,6 +119,7 @@ export class LintProvider extends vscode.Disposable {
106119 }
107120 } ) ;
108121 this . context . subscriptions . push ( disposable ) ;
122+ this . initializeGlobs ( ) ;
109123 }
110124
111125 private lastTimeout : number ;
@@ -123,6 +137,11 @@ export class LintProvider extends vscode.Disposable {
123137 }
124138
125139 private onLintDocument ( document : vscode . TextDocument , documentUri : vscode . Uri , documentLines : string [ ] ) : void {
140+ // Check if we need to lint this document
141+ const relativeFileName = path . relative ( vscode . workspace . rootPath , document . fileName ) ;
142+ if ( this . ignoreMinmatches . some ( matcher => matcher . match ( document . fileName ) || matcher . match ( relativeFileName ) ) ) {
143+ return ;
144+ }
126145 if ( this . pendingLintings . has ( documentUri . fsPath ) ) {
127146 this . pendingLintings . get ( documentUri . fsPath ) . cancel ( ) ;
128147 this . pendingLintings . delete ( documentUri . fsPath ) ;
0 commit comments