Skip to content

Commit

Permalink
[lsp] fix tracking of open files on didClose
Browse files Browse the repository at this point in the history
Summary:
the LSP process keeps track of the open files and current buffer, so that if the server restarts, we can get it back up to speed.

however, it was not removing those opened files' state when the files were closed. so if the server restarts, the LSP process tells the server about all the "opened" files even including the closed files.

this leads to stale errors in those closed files: it's actually showing "live" type errors for the outdated buffer that we still think is open. thankfully, it doesn't spread to any other files because live type errors only impact the current file.

reopening the file would update the buffer, but if you changed revisions and the file no longer exists, then you can't reopen it. `flow stop` didn't help because that only restarts the server, not the LSP process. however, using `flow-for-vscode`, the `Flow: Restart Client` command restarts the LSP so that would've cleared the bad state.

the fix is simple: clear out the state when we receive the `didClose` notification.

Changelog:

- fix(lsp): Fixed a bug in which stale errors could continue to appear in the IDE if the errors were fixed outside the IDE (e.g. by changing revisions).

Reviewed By: nmote

Differential Revision: D20684757

fbshipit-source-id: 4c55dde4ea2510263d08f29c593eada86495cfec
  • Loading branch information
mroch authored and facebook-github-bot committed Mar 30, 2020
1 parent 77bf9b3 commit efed734
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lsp/flowLsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,11 @@ let track_to_server (state : state) (c : Lsp.lsp_message) : state * track_effect
(state, Some uri)
| (_, NotificationMessage (DidCloseNotification params)) ->
let uri = params.DidClose.textDocument.TextDocumentIdentifier.uri |> Lsp.string_of_uri in
let state = state |> update_errors (LspErrors.clear_all_live_errors_and_send to_stdout uri) in
let state =
state
|> update_open_file uri None
|> update_errors (LspErrors.clear_all_live_errors_and_send to_stdout uri)
in
(state, None)
| (Some open_files, NotificationMessage (DidChangeNotification params)) ->
let uri = params.DidChange.textDocument.VersionedTextDocumentIdentifier.uri in
Expand Down

0 comments on commit efed734

Please sign in to comment.