Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Clear Diagnostics when file is closed #1591

Merged
merged 21 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a0440fc
fix: LSP Change 'info' to 'hint' to eliminate noisy blue squiggles sh…
lovettchris Sep 12, 2022
b66b2a7
undo change to .hint for informational messages.
lovettchris Sep 13, 2022
ebb1e57
fix: CR feedback, move the exitWorker function.
lovettchris Sep 13, 2022
811c32d
fix: remove blank line
lovettchris Sep 13, 2022
9cdac72
Merge remote-tracking branch 'upstream/master' into clovett/clear_pro…
lovettchris Sep 19, 2022
1b98766
fix hang in the tests
lovettchris Sep 19, 2022
8f30109
fix: code review feedback.
lovettchris Sep 19, 2022
380728d
fix: add lspShutdown helper method that does the property handshake.
lovettchris Sep 20, 2022
85cfbda
fix: move shutdown code out of Communication.lean.
lovettchris Sep 23, 2022
c42a70b
fix: move clear diagnostics on file close to Watchdog.
lovettchris Sep 23, 2022
79c331b
Merge branch 'master' into clovett/clear_problems
lovettchris Sep 26, 2022
761460d
fix: revert unnecessary changes.
lovettchris Sep 26, 2022
665bf37
fix: use repeat instead of while True
lovettchris Sep 26, 2022
bde17e8
Merge branch 'master' into clovett/clear_problems
lovettchris Oct 4, 2022
3d27b26
fix: remove blank lines
lovettchris Oct 4, 2022
c9832a9
fix: fix race condition to ensure clearing of diagnostics is really a…
lovettchris Oct 4, 2022
36a531d
fix: ensure forwardMessages finds the updated WorkState.
lovettchris Oct 4, 2022
7ca3a41
fix: remove trace statement.
lovettchris Oct 4, 2022
8969ee8
fix: code review feedback.
lovettchris Oct 6, 2022
6f614a6
fix: code review - revert unneccesary edits.
lovettchris Oct 7, 2022
6d8b8a5
Merge branch 'master' into clovett/clear_problems
lovettchris Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Lean/Server/FileWorker.lean
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ section MainLoop
let state ← get
let doc := state.doc
doc.cancelTk.set
-- this is acting like an acknowledgement back to the Watchdog that exit was in fact received.
publishDiagnostics doc.meta #[] ctx.hOut
lovettchris marked this conversation as resolved.
Show resolved Hide resolved

partial def mainLoop : WorkerM Unit := do
Expand Down
18 changes: 10 additions & 8 deletions src/Lean/Server/Watchdog.lean
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ section FileWorker
doc : OpenDocument
proc : Process.Child workerCfg
commTask : Task WorkerEvent
state : WorkerState
state : IO.Ref WorkerState
-- This should not be mutated outside of namespace FileWorker, as it is used as shared mutable state
/-- The pending requests map contains all requests
that have been received from the LSP client, but were not answered yet.
Expand Down Expand Up @@ -249,11 +249,13 @@ section ServerM
handleIleanInfoFinal fw params
| _ => o.writeLspMessage msg

match fw.state with
match (← fw.state.get) with
| .exiting =>
-- the above may have just sent the response to the "exit" command,
-- and clear diagnostics is the last thing we should do.
-- and now we ensure that clear diagnostics is the last thing we should do
-- so we never leave stale diagnostics around for this file.
let meta := fw.doc.meta
dbg_trace "sending clear diagnostics from Watchdog!"
publishDiagnostics meta #[] o
return WorkerEvent.terminated
| _ => pure
Expand Down Expand Up @@ -296,7 +298,7 @@ section ServerM
doc := ⟨m, headerAst⟩
proc := workerProc
commTask := Task.pure WorkerEvent.terminated
state := WorkerState.running
state := ← IO.mkRef WorkerState.running
pendingRequestsRef := pendingRequestsRef
groupedEditsRef := ← IO.mkRef none
}
Expand All @@ -319,7 +321,7 @@ section ServerM
def terminateFileWorker (uri : DocumentUri) : ServerM Unit := do
let fw ← findFileWorker! uri
try
updateFileWorkers { fw with state := WorkerState.exiting }
fw.state.modify (λ _ => WorkerState.exiting)
fw.stdin.writeLspMessage (Message.notification "exit" none)
catch _ =>
/- The file worker must have crashed just when we were about to terminate it!
Expand All @@ -332,7 +334,7 @@ section ServerM
eraseFileWorker uri

def handleCrash (uri : DocumentUri) (queuedMsgs : Array JsonRpc.Message) : ServerM Unit := do
updateFileWorkers { ←findFileWorker! uri with state := WorkerState.crashed queuedMsgs }
(←findFileWorker! uri).state.modify (λ _ => WorkerState.crashed queuedMsgs)

/-- Tries to write a message, sets the state of the FileWorker to `crashed` if it does not succeed
and restarts the file worker if the `crashed` flag was already set. Just logs an error if there
Expand All @@ -350,7 +352,7 @@ section ServerM
| none => (false, none)
if pendingEdit then
return
match fw.state with
match (← fw.state.get) with
| WorkerState.crashed queuedMsgs =>
let mut queuedMsgs := queuedMsgs
if queueFailedMessage then
Expand Down Expand Up @@ -601,7 +603,7 @@ section MainLoop
let workers ← st.fileWorkersRef.get
let mut workerTasks := #[]
for (_, fw) in workers do
if let WorkerState.running := fw.state then
if let WorkerState.running := (← fw.state.get) then
workerTasks := workerTasks.push <| fw.commTask.map (ServerEvent.workerEvent fw)
if let some ge ← fw.groupedEditsRef.get then
workerTasks := workerTasks.push <| ge.signalTask.map (ServerEvent.workerEvent fw)
Expand Down