Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 63fecec

Browse files
authored
Merge pull request #87 from Gozala/check-on-edit
Check on edit
2 parents 6a0e872 + b524f3f commit 63fecec

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Follow the [instructions](https://code.visualstudio.com/docs/editor/extension-ga
2020
* `flow.enabled` (default: true) you can disable flow for some Project for example
2121
* `flow.useNPMPackagedFlow` (default: false) you can also run Flow by defining it in your `package.json`
2222
* `flow.showStatus` (default: `true`) If `true` will display a spinner in the statusbar while flow is type checking.
23+
* `flow.runOnEdit` (default: `true`) If `true` will run flow on every edit, otherwise will run only when changes are saved.
2324

2425
## Features
2526

lib/flowDiagnostics.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Status} from './flowStatus'
1515
import type {DiagnosticCollection, Disposable} from 'vscode';
1616

1717
import {flowFindDiagnostics} from './pkg/flow-base/lib/FlowService';
18+
import {isRunOnEditEnabled} from './utils/util'
1819

1920
let lastDiagnostics: null | DiagnosticCollection = null;
2021
const 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

lib/utils/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export function isFlowStatusEnabled():boolean {
1818
return workspace.getConfiguration('flow').get('showStatus')
1919
}
2020

21+
export function isRunOnEditEnabled():boolean {
22+
return workspace.getConfiguration('flow').get('runOnEdit')
23+
}
24+
2125
export function checkNode() {
2226
try {
2327
const check = spawn(process.platform === 'win32' ? 'where' : 'which', ['node'])

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"default": true,
3838
"description": "If true will display flow status is the statusbar"
3939
},
40+
"flow.runOnEdit": {
41+
"type": "boolean",
42+
"default": true,
43+
"description": "If true will run flow on every edit, otherwise will run only when changes are saved"
44+
},
4045
"flow.stopFlowOnExit": {
4146
"type": "boolean",
4247
"default": true,

0 commit comments

Comments
 (0)