@@ -6,6 +6,7 @@ import { uploadCode } from "./util"
66import * as statusbar from "./statusbar"
77import * as path from "path"
88import { DlangUIHandler } from "./dlangui"
9+ import { lintDfmt } from "./dfmt-check"
910
1011let diagnosticCollection : vscode . DiagnosticCollection ;
1112
@@ -21,7 +22,7 @@ export function activate(context: vscode.ExtensionContext) {
2122
2223 let workspaced = new WorkspaceD ( vscode . workspace . rootPath ) ;
2324 context . subscriptions . push ( vscode . languages . registerCompletionItemProvider ( DML_MODE , workspaced . getDlangUI ( ) ) ) ;
24-
25+
2526 context . subscriptions . push ( vscode . languages . registerCompletionItemProvider ( D_MODE , workspaced , "." ) ) ;
2627 context . subscriptions . push ( vscode . languages . registerSignatureHelpProvider ( D_MODE , workspaced , "(" , "," ) ) ;
2728 context . subscriptions . push ( vscode . languages . registerDocumentSymbolProvider ( D_MODE , workspaced ) ) ;
@@ -79,7 +80,7 @@ export function activate(context: vscode.ExtensionContext) {
7980 decreaseIndentPattern : / \} / ,
8081 increaseIndentPattern : / \{ /
8182 } ,
82-
83+
8384 wordPattern : / [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ ] * / g,
8485
8586 brackets : [
@@ -95,7 +96,34 @@ export function activate(context: vscode.ExtensionContext) {
9596 context . subscriptions . push ( diagnosticCollection ) ;
9697
9798 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+
99127 context . subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( document => {
100128 if ( document . languageId != "d" )
101129 return ;
@@ -113,6 +141,8 @@ export function activate(context: vscode.ExtensionContext) {
113141 diagnosticCollection . set ( allErrors ) ;
114142 } ;
115143
144+ oldLint [ 2 ] = [ [ document . uri , lintDfmt ( document , document . getText ( ) ) ] ] ;
145+ buildErrors ( ) ;
116146 workspaced . lint ( document ) . then ( ( errors : [ vscode . Uri , vscode . Diagnostic [ ] ] [ ] ) => {
117147 if ( target == version ) {
118148 oldLint [ 0 ] = errors ;
@@ -196,7 +226,7 @@ export function activate(context: vscode.ExtensionContext) {
196226 vscode . window . showErrorMessage ( "Could not update imports. dub might not be initialized yet!" ) ;
197227 } ) ;
198228 } ) ) ;
199-
229+
200230 context . subscriptions . push ( vscode . commands . registerCommand ( "code-d.insertDscanner" , ( ) => {
201231 vscode . window . activeTextEditor . edit ( ( bld ) => {
202232 bld . insert ( vscode . window . activeTextEditor . selection . start , `; Configurue which static analysis checks are enabled
0 commit comments