@@ -6,6 +6,7 @@ import { uploadCode } from "./util"
6
6
import * as statusbar from "./statusbar"
7
7
import * as path from "path"
8
8
import { DlangUIHandler } from "./dlangui"
9
+ import { lintDfmt } from "./dfmt-check"
9
10
10
11
let diagnosticCollection : vscode . DiagnosticCollection ;
11
12
@@ -21,7 +22,7 @@ export function activate(context: vscode.ExtensionContext) {
21
22
22
23
let workspaced = new WorkspaceD ( vscode . workspace . rootPath ) ;
23
24
context . subscriptions . push ( vscode . languages . registerCompletionItemProvider ( DML_MODE , workspaced . getDlangUI ( ) ) ) ;
24
-
25
+
25
26
context . subscriptions . push ( vscode . languages . registerCompletionItemProvider ( D_MODE , workspaced , "." ) ) ;
26
27
context . subscriptions . push ( vscode . languages . registerSignatureHelpProvider ( D_MODE , workspaced , "(" , "," ) ) ;
27
28
context . subscriptions . push ( vscode . languages . registerDocumentSymbolProvider ( D_MODE , workspaced ) ) ;
@@ -79,7 +80,7 @@ export function activate(context: vscode.ExtensionContext) {
79
80
decreaseIndentPattern : / \} / ,
80
81
increaseIndentPattern : / \{ /
81
82
} ,
82
-
83
+
83
84
wordPattern : / [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ ] * / g,
84
85
85
86
brackets : [
@@ -95,7 +96,34 @@ export function activate(context: vscode.ExtensionContext) {
95
96
context . subscriptions . push ( diagnosticCollection ) ;
96
97
97
98
let version ;
98
- let oldLint = [ [ ] , [ ] ] ;
99
+ let writeTimeout ;
100
+ let oldLint : [ vscode . Uri , vscode . Diagnostic [ ] ] [ ] [ ] = [ [ ] , [ ] , [ ] ] ;
101
+ context . subscriptions . push ( vscode . workspace . onDidChangeTextDocument ( event => {
102
+ clearTimeout ( writeTimeout ) ;
103
+ writeTimeout = setTimeout ( function ( ) {
104
+ let document = event . document ;
105
+ if ( document . languageId != "d" )
106
+ return ;
107
+ version = document . version ;
108
+ let target = version ;
109
+ if ( config ( ) . get ( "enableLinting" , true ) ) {
110
+ let allErrors : [ vscode . Uri , vscode . Diagnostic [ ] ] [ ] = [ ] ;
111
+
112
+ let fresh = true ;
113
+ let buildErrors = ( ) => {
114
+ allErrors = [ ] ;
115
+ oldLint . forEach ( errors => {
116
+ allErrors . push . apply ( allErrors , errors ) ;
117
+ } ) ;
118
+ diagnosticCollection . set ( allErrors ) ;
119
+ } ;
120
+
121
+ oldLint [ 2 ] = [ [ document . uri , lintDfmt ( document , document . getText ( ) ) ] ] ;
122
+ buildErrors ( ) ;
123
+ }
124
+ } , 500 ) ;
125
+ } ) ) ;
126
+
99
127
context . subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( document => {
100
128
if ( document . languageId != "d" )
101
129
return ;
@@ -113,6 +141,8 @@ export function activate(context: vscode.ExtensionContext) {
113
141
diagnosticCollection . set ( allErrors ) ;
114
142
} ;
115
143
144
+ oldLint [ 2 ] = [ [ document . uri , lintDfmt ( document , document . getText ( ) ) ] ] ;
145
+ buildErrors ( ) ;
116
146
workspaced . lint ( document ) . then ( ( errors : [ vscode . Uri , vscode . Diagnostic [ ] ] [ ] ) => {
117
147
if ( target == version ) {
118
148
oldLint [ 0 ] = errors ;
@@ -196,7 +226,7 @@ export function activate(context: vscode.ExtensionContext) {
196
226
vscode . window . showErrorMessage ( "Could not update imports. dub might not be initialized yet!" ) ;
197
227
} ) ;
198
228
} ) ) ;
199
-
229
+
200
230
context . subscriptions . push ( vscode . commands . registerCommand ( "code-d.insertDscanner" , ( ) => {
201
231
vscode . window . activeTextEditor . edit ( ( bld ) => {
202
232
bld . insert ( vscode . window . activeTextEditor . selection . start , `; Configurue which static analysis checks are enabled
0 commit comments