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 10 commits
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/Data/Lsp/Communication.lean
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ section

def writeLspResponseErrorWithData (h : FS.Stream) (e : ResponseError α) : IO Unit :=
h.writeLspMessage e

end

end IO.FS.Stream
17 changes: 17 additions & 0 deletions src/Lean/Data/Lsp/Ipc.lean
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ def writeRequest (r : Request α) : IpcM Unit := do
def writeNotification (n : Notification α) : IpcM Unit := do
(←stdin).writeLspNotification n

def shutdown (requestNo : Nat) : IpcM Unit := do
let hIn ← stdout
let hOut ← stdin
hOut.writeLspRequest ⟨requestNo, "shutdown", Json.null⟩
while True do
lovettchris marked this conversation as resolved.
Show resolved Hide resolved
let shutMsg ← hIn.readLspMessage
match shutMsg with
| Message.response id result =>
assert! result.isNull
if id != requestNo then
throw <| IO.userError s!"Expected id {requestNo}, got id {id}"

hOut.writeLspNotification ⟨"exit", Json.null⟩
break
| _ => -- ignore other messages in between.
pure ()

def readMessage : IpcM JsonRpc.Message := do
(←stdout).readLspMessage

Expand Down
10 changes: 8 additions & 2 deletions src/Lean/Server/FileWorker.lean
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ section MessageHandling
end MessageHandling

section MainLoop

/-- called when document is closed so we can clear any diagnostics and cancel pending work -/
def exitWorker : WorkerM Unit := do
let state ← get
let doc := state.doc
doc.cancelTk.set

partial def mainLoop : WorkerM Unit := do
let ctx ← read
let mut st ← get
Expand Down Expand Up @@ -450,8 +457,7 @@ section MainLoop
handleRequest id method (toJson params)
mainLoop
| Message.notification "exit" none =>
let doc := (←get).doc
doc.cancelTk.set
exitWorker
lovettchris marked this conversation as resolved.
Show resolved Hide resolved
return ()
| Message.notification method (some params) =>
handleNotification method (toJson params)
Expand Down
3 changes: 3 additions & 0 deletions src/Lean/Server/Watchdog.lean
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ section ServerM
def terminateFileWorker (uri : DocumentUri) : ServerM Unit := do
let fw ← findFileWorker! uri
try
let ctx ← read
let meta := fw.doc.meta
publishDiagnostics meta #[] ctx.hOut
lovettchris marked this conversation as resolved.
Show resolved Hide resolved
fw.stdin.writeLspMessage (Message.notification "exit" none)
catch _ =>
/- The file worker must have crashed just when we were about to terminate it!
Expand Down
6 changes: 2 additions & 4 deletions tests/lean/interactive/run.lean
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ partial def main (args : List String) : IO Unit := do
| _ =>
lastActualLineNo := lineNo
lineNo := lineNo + 1
Ipc.writeRequest ⟨requestNo, "shutdown", Json.null⟩
let shutResp ← Ipc.readResponseAs requestNo Json
assert! shutResp.result.isNull
Ipc.writeNotification ⟨"exit", Json.null⟩

Ipc.shutdown requestNo
discard <| Ipc.waitForExit
8 changes: 4 additions & 4 deletions tests/lean/server/diags.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Lean.Data.Lsp
open IO Lean Lsp
open Lean
open Lean.Lsp
open Lean.JsonRpc
lovettchris marked this conversation as resolved.
Show resolved Hide resolved

def main : IO Unit := do
Ipc.runWith (←IO.appPath) #["--server", "-Dlinter.all=false"] do
Expand All @@ -25,8 +28,5 @@ def main : IO Unit := do
else
throw $ userError "Failed parsing test file."

Ipc.writeRequest ⟨2, "shutdown", Json.null⟩
let shutResp ← Ipc.readResponseAs 2 Json
assert! shutResp.result.isNull
Ipc.writeNotification ⟨"exit", Json.null⟩
Ipc.shutdown 2
discard $ Ipc.waitForExit
5 changes: 1 addition & 4 deletions tests/lean/server/edits.lean
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,5 @@ def main : IO Unit := do
else
throw $ userError "Failed parsing test file."

Ipc.writeRequest ⟨3, "shutdown", Json.null⟩
let shutResp ← Ipc.readResponseAs 3 Json
assert! shutResp.result.isNull
Ipc.writeNotification ⟨"exit", Json.null⟩
Ipc.shutdown 3
discard $ Ipc.waitForExit
7 changes: 2 additions & 5 deletions tests/lean/server/init_exit.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def main : IO Unit := do
hIn.flush
let initResp ← Ipc.readResponseAs 0 InitializeResult
let regWatchReq ← Ipc.readRequestAs "client/registerCapability" Json
Ipc.writeNotification ⟨"initialized", InitializedParams.mk⟩
Ipc.writeNotification ⟨"initialized", InitializedParams.mk⟩

Ipc.writeRequest ⟨1, "shutdown", Json.null⟩
let shutdownResp ← Ipc.readResponseAs 1 Json
assert! shutdownResp.result.isNull
Ipc.writeNotification ⟨"exit", Json.null⟩
Ipc.shutdown 1
discard Ipc.waitForExit