Skip to content

Commit 1858e72

Browse files
Catherine Gasnierfacebook-github-bot
Catherine Gasnier
authored andcommitted
IDE: Properly update errors in open files upon file save
Summary: The IDE obtains errors from two sources: * for open files, it gets errors from its own typechecking. This allows to typecheck unsaved changes. * Files are rechecked upon refocusing on the tab for the file and only then * for non-open files, it gets errors from hh_server. These appear in the problem pane. Errors from hh_server for open files are ignored With this diff, errors from hh_server for open files do get accounted for, so long the file does not have unsaved changes. See the test plan for a better idea of how this is helpful. Reviewed By: mheiber Differential Revision: D71131447 fbshipit-source-id: 05e7d502127b3b519a8dde3ce18b9cda58bd52c6
1 parent 4eb8ed2 commit 1858e72

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

hphp/hack/src/client/clientLsp.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3550,7 +3550,7 @@ let handle_errors_file_item
35503550
lenv.Run_env.uris_with_standalone_diagnostics
35513551
|> UriMap.filter_map (fun uri (existing_time, diagnostics_from) ->
35523552
if
3553-
UriMap.mem uri lenv.Run_env.editor_open_files
3553+
UriSet.mem uri lenv.Run_env.uris_with_unsaved_changes
35543554
|| Float.(existing_time > start_time)
35553555
then begin
35563556
Some (existing_time, diagnostics_from)
@@ -3597,7 +3597,7 @@ let handle_errors_file_item
35973597
~f:(fun path file_errors acc ->
35983598
let path = Relative_path.to_absolute path in
35993599
let uri = path_string_to_lsp_uri path ~default_path:path in
3600-
if UriMap.mem uri lenv.Run_env.editor_open_files then
3600+
if UriSet.mem uri lenv.Run_env.uris_with_unsaved_changes then
36013601
acc
36023602
else
36033603
match UriMap.find_opt uri acc with

hphp/hack/test/integration/test_lsp.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -5751,17 +5751,41 @@ def test_standalone_errors(self) -> None:
57515751
notify=False,
57525752
)
57535753
.notification(
5754-
comment="actually open something that's different from what was on disk (with extra newline)",
5754+
comment="open errors_b.php",
5755+
method="textDocument/didOpen",
5756+
params={
5757+
"textDocument": {
5758+
"uri": "${errors_b_uri}",
5759+
"languageId": "hack",
5760+
"version": 1,
5761+
"text": "<?hh\nfunction bbb(): int { return 2 }\n",
5762+
}
5763+
},
5764+
)
5765+
.notification(
5766+
comment="open errors_a.php",
57555767
method="textDocument/didOpen",
57565768
params={
57575769
"textDocument": {
57585770
"uri": "${errors_a_uri}",
57595771
"languageId": "hack",
57605772
"version": 1,
5761-
"text": "<?hh\n\n\n\nfunction aaa(): int { return 1 }\n",
5773+
"text": "<?hh\nfunction aaa(): int { return 1 }\n",
57625774
}
57635775
},
57645776
)
5777+
.notification(
5778+
comment="edit errors_a.php",
5779+
method="textDocument/didChange",
5780+
params={
5781+
"textDocument": {"uri": "${errors_a_uri}", "version": 1},
5782+
"contentChanges": [
5783+
{
5784+
"text": "<?hh\n\n\n\nfunction aaa(): int { return 1 }\n",
5785+
}
5786+
],
5787+
},
5788+
)
57655789
.wait_for_notification(
57665790
comment="standalone should report a squiggle in errors_a.php from serverless",
57675791
method="textDocument/publishDiagnostics",

0 commit comments

Comments
 (0)