@@ -15,6 +15,7 @@ import {Status} from './flowStatus'
1515import type { DiagnosticCollection , Disposable } from 'vscode' ;
1616
1717import { flowFindDiagnostics } from './pkg/flow-base/lib/FlowService' ;
18+ import { isRunOnEditEnabled } from './utils/util'
1819
1920let lastDiagnostics : null | DiagnosticCollection = null ;
2021const status = new Status ( )
@@ -37,20 +38,27 @@ export function setupDiagnostics(disposables: Array<Disposable>): void {
3738 updateDiagnostics ( vscode . window . activeTextEditor . document ) ;
3839 }
3940 } ) ) ;
41+
42+ disposables . push ( vscode . workspace . onDidChangeTextDocument ( event => {
43+ const isDocumentActive = vscode . window . activeTextEditor . document === event . document ;
44+ if ( isDocumentActive && isRunOnEditEnabled ( ) ) {
45+ updateDiagnostics ( event . document , event . document . getText ( ) ) ;
46+ }
47+ } ) ) ;
4048}
4149
42- async function updateDiagnostics ( document ) {
50+ async function updateDiagnostics ( document , content :? string ) {
4351 status . busy ( )
4452 try {
45- let diagnostics = await getDiagnostics ( document )
53+ let diagnostics = await getDiagnostics ( document , content )
4654 applyDiagnostics ( diagnostics )
4755 } catch ( error ) {
4856 console . error ( error )
4957 }
5058 status . idle ( )
5159}
5260
53- async function getDiagnostics ( document ) {
61+ async function getDiagnostics ( document , content :? string ) {
5462 let diags = Object . create ( null ) ;
5563
5664 if ( ! document ) {
@@ -65,7 +73,7 @@ async function getDiagnostics(document) {
6573 // flowFindDiagnostics takes the provided filePath and then walks up directories
6674 // until a .flowconfig is found. The diagnostics are then valid for the entire
6775 // flow workspace.
68- let rawDiag = await flowFindDiagnostics ( filePath ) ;
76+ let rawDiag = await flowFindDiagnostics ( filePath , content ) ;
6977 if ( rawDiag && rawDiag . messages ) {
7078 const { flowRoot } = rawDiag ;
7179
0 commit comments