Skip to content

Commit 1d27f14

Browse files
gabeleviGabe Levi
authored andcommitted
Lazy_mode_utils.focus_and_check failed to process updates
Summary: `Rechecker.process_updates` does a bunch of really useful things, like detecting whether the Flow server needs to crash and filtering out ignored files. `Lazy_mode_utils.focus_and_check` wasn't calling it, and so you could trick a Flow server into checking a lazy file. Reviewed By: nmote Differential Revision: D7493998 fbshipit-source-id: 85b90f312b99c1f2d5518e9c8bb310dad3a26ca6
1 parent 75713d8 commit 1d27f14

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed

newtests/ide/lazy/_flowconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[ignore]
2+
<PROJECT_ROOT>/ignored\.js
23

34
[include]
45

newtests/ide/lazy/ignored.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var x: string = 123;

newtests/ide/lazy/test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,82 @@ import {suite, test} from 'flow-dev-tools/src/test/Tester';
99
export default suite(({
1010
addCode, addFile, addFiles, removeFile, ideStart, ideNotification, flowCmd
1111
}) => [
12+
test('Opening and closing ignored file', [
13+
ideStart()
14+
.ideNotification('subscribeToDiagnostics')
15+
.ideNewMessagesWithTimeout(
16+
10000,
17+
[
18+
{
19+
"method": "diagnosticsNotification",
20+
"params": [
21+
{
22+
"flowVersion": "<VERSION STUBBED FOR TEST>",
23+
"jsonVersion": "1",
24+
"errors": [],
25+
"passed": true
26+
}
27+
]
28+
}
29+
],
30+
),
31+
32+
addFile('ignored.js')
33+
.ideNoNewMessagesAfterSleep(500)
34+
.noNewErrors()
35+
.because('The IDE has not opened ignored.js yet'),
36+
37+
ideNotification('didOpen', 'ignored.js')
38+
.ideNewMessagesWithTimeout(
39+
50000,
40+
[
41+
{
42+
"method": "diagnosticsNotification",
43+
"params": [
44+
{
45+
"flowVersion": "<VERSION STUBBED FOR TEST>",
46+
"jsonVersion": "1",
47+
"errors": [],
48+
"passed": true
49+
}
50+
]
51+
}
52+
],
53+
)
54+
.because('The file is ignored'),
55+
56+
ideNotification('didClose', 'ignored.js')
57+
.ideNewMessagesWithTimeout(
58+
50000,
59+
[
60+
{
61+
"method": "diagnosticsNotification",
62+
"params": [
63+
{
64+
"flowVersion": "<VERSION STUBBED FOR TEST>",
65+
"jsonVersion": "1",
66+
"errors": [],
67+
"passed": true
68+
}
69+
]
70+
}
71+
],
72+
)
73+
.because('Closing the file does not trigger recheck, just sends errors'),
74+
75+
flowCmd(['status', '--strip-root'])
76+
.stdout(
77+
`
78+
No errors!
79+
80+
The Flow server is currently in IDE lazy mode and is only checking 0/1 files.
81+
To learn more, visit flow.org/en/docs/lang/lazy-modes
82+
83+
`,
84+
)
85+
.because('Still no errors'),
86+
]).lazy('ide'),
87+
1288
test('Opening and closing single file with no dependents or dependencies', [
1389
ideStart()
1490
.ideNotification('subscribeToDiagnostics')

src/server/lazy_mode_utils.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ open ServerEnv
99
open Utils_js
1010

1111
let focus_and_check genv env filenames =
12-
let options = genv.options in
13-
let file_options = Options.file_options options in
14-
let focused = Nel.fold_left
15-
(fun acc fn ->
16-
FilenameSet.add (Files.filename_from_string ~options:file_options fn) acc)
17-
FilenameSet.empty
18-
filenames in
12+
let filenames = SSet.of_list (Nel.to_list filenames) in
13+
let focused = Rechecker.process_updates genv env filenames in
1914
let checked_files = CheckedSet.add ~focused env.checked_files in
2015

2116
let new_focused_files = focused

0 commit comments

Comments
 (0)