1
- ' use strict' ;
2
-
3
- import * as vscode from ' vscode' ;
4
- import * as path from ' path' ;
5
- import * as linter from ' ../linters/baseLinter' ;
6
- import * as prospector from ' ./../linters/prospector' ;
7
- import * as pylint from ' ./../linters/pylint' ;
8
- import * as pep8 from ' ./../linters/pep8Linter' ;
9
- import * as flake8 from ' ./../linters/flake8' ;
10
- import * as pydocstyle from ' ./../linters/pydocstyle' ;
11
- import * as settings from ' ../common/configSettings' ;
1
+ " use strict" ;
2
+
3
+ import * as vscode from " vscode" ;
4
+ import * as path from " path" ;
5
+ import * as linter from " ../linters/baseLinter" ;
6
+ import * as prospector from " ./../linters/prospector" ;
7
+ import * as pylint from " ./../linters/pylint" ;
8
+ import * as pep8 from " ./../linters/pep8Linter" ;
9
+ import * as flake8 from " ./../linters/flake8" ;
10
+ import * as pydocstyle from " ./../linters/pydocstyle" ;
11
+ import * as settings from " ../common/configSettings" ;
12
12
import * as telemetryHelper from "../common/telemetry" ;
13
13
import * as telemetryContracts from "../common/telemetryContracts" ;
14
14
15
- const FILE_PROTOCOL = "file:///"
16
-
17
- function uriToPath ( pathValue : string ) : string {
18
- if ( pathValue . startsWith ( FILE_PROTOCOL ) ) {
19
- pathValue = pathValue . substring ( FILE_PROTOCOL . length ) ;
20
- }
21
-
22
- return path . normalize ( decodeURIComponent ( pathValue ) ) ;
23
- }
24
-
25
15
const lintSeverityToVSSeverity = new Map < linter . LintMessageSeverity , vscode . DiagnosticSeverity > ( ) ;
26
16
lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Error , vscode . DiagnosticSeverity . Error )
27
17
lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Hint , vscode . DiagnosticSeverity . Hint )
28
18
lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Information , vscode . DiagnosticSeverity . Information )
29
19
lintSeverityToVSSeverity . set ( linter . LintMessageSeverity . Warning , vscode . DiagnosticSeverity . Warning )
30
20
31
21
function createDiagnostics ( message : linter . ILintMessage , txtDocumentLines : string [ ] ) : vscode . Diagnostic {
32
- var sourceLine = txtDocumentLines [ message . line - 1 ] ;
33
- var sourceStart = sourceLine . substring ( message . column - 1 ) ;
34
- var endCol = txtDocumentLines [ message . line - 1 ] . length ;
22
+ let sourceLine = txtDocumentLines [ message . line - 1 ] ;
23
+ let sourceStart = sourceLine . substring ( message . column - 1 ) ;
24
+ let endCol = txtDocumentLines [ message . line - 1 ] . length ;
35
25
36
- //try to get the first word from the startig position
26
+ // try to get the first word from the startig position
37
27
if ( message . possibleWord === "string" && message . possibleWord . length > 0 ) {
38
28
endCol = message . column + message . possibleWord . length ;
39
29
}
40
30
41
- var range = new vscode . Range ( new vscode . Position ( message . line - 1 , message . column ) , new vscode . Position ( message . line - 1 , endCol ) ) ;
31
+ let range = new vscode . Range ( new vscode . Position ( message . line - 1 , message . column ) , new vscode . Position ( message . line - 1 , endCol ) ) ;
42
32
43
- var severity = lintSeverityToVSSeverity . get ( message . severity ) ;
33
+ let severity = lintSeverityToVSSeverity . get ( message . severity ) ;
44
34
return new vscode . Diagnostic ( range , message . code + ":" + message . message , severity ) ;
45
35
}
46
36
@@ -63,23 +53,15 @@ export class LintProvider extends vscode.Disposable {
63
53
64
54
private initialize ( ) {
65
55
this . diagnosticCollection = vscode . languages . createDiagnosticCollection ( "python" ) ;
66
- var disposables = [ ] ;
56
+ let disposables = [ ] ;
67
57
68
58
this . linters . push ( new prospector . Linter ( this . outputChannel ) ) ;
69
59
this . linters . push ( new pylint . Linter ( this . outputChannel ) ) ;
70
60
this . linters . push ( new pep8 . Linter ( this . outputChannel ) ) ;
71
61
this . linters . push ( new flake8 . Linter ( this . outputChannel ) ) ;
72
62
this . linters . push ( new pydocstyle . Linter ( this . outputChannel ) ) ;
73
63
74
- var disposable = vscode . workspace . onDidChangeTextDocument ( ( e ) => {
75
- if ( e . document . languageId !== "python" || ! this . settings . linting . enabled || ! this . settings . linting . lintOnTextChange ) {
76
- return ;
77
- }
78
- this . lintDocument ( e . document . uri , e . document . getText ( ) . split ( / \r ? \n / g) , 1000 ) ;
79
- } ) ;
80
- this . context . subscriptions . push ( disposable ) ;
81
-
82
- disposable = vscode . workspace . onDidSaveTextDocument ( ( e ) => {
64
+ let disposable = vscode . workspace . onDidSaveTextDocument ( ( e ) => {
83
65
if ( e . languageId !== "python" || ! this . settings . linting . enabled || ! this . settings . linting . lintOnSave ) {
84
66
return ;
85
67
}
@@ -90,8 +72,8 @@ export class LintProvider extends vscode.Disposable {
90
72
91
73
private lastTimeout : number ;
92
74
private lintDocument ( documentUri : vscode . Uri , documentLines : string [ ] , delay : number ) : void {
93
- //Since this is a hack, lets wait for 2 seconds before linting
94
- //Give user to continue typing before we waste CPU time
75
+ // Since this is a hack, lets wait for 2 seconds before linting
76
+ // Give user to continue typing before we waste CPU time
95
77
if ( this . lastTimeout ) {
96
78
clearTimeout ( this . lastTimeout ) ;
97
79
this . lastTimeout = 0 ;
@@ -108,15 +90,15 @@ export class LintProvider extends vscode.Disposable {
108
90
this . pendingLintings . delete ( documentUri . fsPath ) ;
109
91
}
110
92
111
- var cancelToken = new vscode . CancellationTokenSource ( ) ;
93
+ let cancelToken = new vscode . CancellationTokenSource ( ) ;
112
94
cancelToken . token . onCancellationRequested ( ( ) => {
113
95
if ( this . pendingLintings . has ( documentUri . fsPath ) ) {
114
96
this . pendingLintings . delete ( documentUri . fsPath ) ;
115
97
}
116
98
} ) ;
117
99
118
100
this . pendingLintings . set ( documentUri . fsPath , cancelToken ) ;
119
- var promises = this . linters . map ( linter => {
101
+ let promises = this . linters . map ( linter => {
120
102
if ( ! linter . isEnabled ( ) ) {
121
103
return Promise . resolve ( [ ] ) ;
122
104
}
@@ -133,15 +115,15 @@ export class LintProvider extends vscode.Disposable {
133
115
return ;
134
116
}
135
117
136
- //Flatten the array
137
- var consolidatedMessages : linter . ILintMessage [ ] = [ ] ;
118
+ // Flatten the array
119
+ let consolidatedMessages : linter . ILintMessage [ ] = [ ] ;
138
120
msgs . forEach ( lintMessages => consolidatedMessages = consolidatedMessages . concat ( lintMessages ) ) ;
139
121
140
- //Limit the number of messages to the max value
122
+ // Limit the number of messages to the max value
141
123
consolidatedMessages = consolidatedMessages . filter ( ( value , index ) => index <= this . settings . linting . maxNumberOfProblems ) ;
142
124
143
- //Build the message and suffix the message with the name of the linter used
144
- var messages = [ ] ;
125
+ // Build the message and suffix the message with the name of the linter used
126
+ let messages = [ ] ;
145
127
consolidatedMessages . forEach ( d => {
146
128
d . message = `${ d . message } (${ d . provider } )` ;
147
129
messages . push ( createDiagnostics ( d , documentLines ) ) ;
0 commit comments