diff --git a/src/Lean/Server/FileWorker.lean b/src/Lean/Server/FileWorker.lean
index a8582ccdf3f9..c57479690214 100644
--- a/src/Lean/Server/FileWorker.lean
+++ b/src/Lean/Server/FileWorker.lean
@@ -51,17 +51,7 @@ open IO
open Snapshots
open Std (RBMap RBMap.empty)
open JsonRpc
-
-def publishInteractiveMessages (m : DocumentMeta) (msgLog : MessageLog) (hOut : FS.Stream) (rpcSesh : RpcSession) : IO Unit := do
- let diagnostics ← msgLog.msgs.mapM (Widget.msgToDiagnostic m.text · rpcSesh)
- let diagParams : PublishDiagnosticsParams :=
- { uri := m.uri
- version? := some m.version
- diagnostics := diagnostics.toArray }
- hOut.writeLspNotification {
- method := "textDocument/publishDiagnostics"
- param := toJson diagParams
- }
+open Widget (publishMessages)
/- Asynchronous snapshot elaboration. -/
section Elab
@@ -85,10 +75,10 @@ section Elab
because we cannot guarantee that no further diagnostics are emitted after clearing
them. -/
if snap.msgLog.msgs.size > parentSnap.msgLog.msgs.size then
- publishInteractiveMessages m snap.msgLog hOut rpcSesh
+ publishMessages m snap.msgLog hOut rpcSesh
snap
| Sum.inr msgLog =>
- publishInteractiveMessages m msgLog hOut rpcSesh
+ publishMessages m msgLog hOut rpcSesh
publishProgressDone m hOut
throw ElabTaskError.eof
@@ -160,7 +150,7 @@ section Initialization
else
throwServerError s!"`leanpkg print-paths` failed:\n{stdout}\nstderr:\n{stderr}"
- def compileHeader (m : DocumentMeta) (hOut : FS.Stream) : IO (Snapshot × SearchPath) := do
+ def compileHeader (m : DocumentMeta) (hOut : FS.Stream) (rpcSesh : RpcSession) : IO (Snapshot × SearchPath) := do
let opts := {} -- TODO
let inputCtx := Parser.mkInputContext m.text.source ""
let (headerStx, headerParserState, msgLog) ← Parser.parseHeader inputCtx
@@ -180,7 +170,7 @@ section Initialization
catch e => -- should be from `leanpkg print-paths`
let msgs := MessageLog.empty.add { fileName := "", pos := ⟨0, 0⟩, data := e.toString }
pure (← mkEmptyEnvironment, msgs)
- --publishMessages m msgLog hOut
+ publishMessages m msgLog hOut rpcSesh
let cmdState := Elab.Command.mkState headerEnv msgLog opts
let cmdState := { cmdState with infoState.enabled := true, scopes := [{ header := "", opts := opts }] }
let headerSnap := {
@@ -193,14 +183,9 @@ section Initialization
def initializeWorker (meta : DocumentMeta) (i o e : FS.Stream)
: IO (WorkerContext × WorkerState) := do
- /- NOTE(WN): `toFileMap` marks line beginnings as immediately following
- "\n", which should be enough to handle both LF and CRLF correctly.
- This is because LSP always refers to characters by (line, column),
- so if we get the line number correct it shouldn't matter that there
- is a CR there. -/
- let (headerSnap, srcSearchPath) ← compileHeader meta o
- let cancelTk ← CancelToken.new
let rpcSesh ← RpcSession.new false
+ let (headerSnap, srcSearchPath) ← compileHeader meta o rpcSesh
+ let cancelTk ← CancelToken.new
let cmdSnaps ← unfoldCmdSnaps meta headerSnap cancelTk o (initial := true) rpcSesh
let doc : EditableDocument := ⟨meta, headerSnap, cmdSnaps, cancelTk⟩
return ({
@@ -392,6 +377,11 @@ def initAndRunWorker (i o e : FS.Stream) : IO UInt32 := do
let _ ← i.readLspRequestAs "initialize" InitializeParams
let ⟨_, param⟩ ← i.readLspNotificationAs "textDocument/didOpen" DidOpenTextDocumentParams
let doc := param.textDocument
+ /- NOTE(WN): `toFileMap` marks line beginnings as immediately following
+ "\n", which should be enough to handle both LF and CRLF correctly.
+ This is because LSP always refers to characters by (line, column),
+ so if we get the line number correct it shouldn't matter that there
+ is a CR there. -/
let meta : DocumentMeta := ⟨doc.uri, doc.version, doc.text.toFileMap⟩
let e ← e.withPrefix s!"[{param.textDocument.uri}] "
let _ ← IO.setStderr e
diff --git a/src/Lean/Widget.lean b/src/Lean/Widget.lean
index 146de08bf09e..54db7242a6f4 100644
--- a/src/Lean/Widget.lean
+++ b/src/Lean/Widget.lean
@@ -8,4 +8,3 @@ import Lean.Widget.ExprWithCtx
import Lean.Widget.InteractiveGoals
import Lean.Widget.InteractiveDiagnostics
import Lean.Widget.TaggedText
-import Lean.Widget.ToHtmlFormat
diff --git a/src/Lean/Widget/InteractiveDiagnostics.lean b/src/Lean/Widget/InteractiveDiagnostics.lean
index b32a1038bedd..e2ec56a1619c 100644
--- a/src/Lean/Widget/InteractiveDiagnostics.lean
+++ b/src/Lean/Widget/InteractiveDiagnostics.lean
@@ -1,3 +1,9 @@
+/-
+Copyright (c) 2021 Microsoft Corporation. All rights reserved.
+Released under Apache 2.0 license as described in the file LICENSE.
+
+Authors: Wojciech Nawrocki
+-/
import Lean.Data.Lsp
import Lean.Message
import Lean.Server.Rpc.Basic
@@ -111,4 +117,15 @@ def msgToDiagnostic (text : FileMap) (m : Message) : ReaderT RpcSession IO Diagn
taggedMsg? := ttJson
}
+def publishMessages (m : DocumentMeta) (msgLog : MessageLog) (hOut : IO.FS.Stream) (rpcSesh : RpcSession) : IO Unit := do
+ let diagnostics ← msgLog.msgs.mapM (msgToDiagnostic m.text · rpcSesh)
+ let diagParams : PublishDiagnosticsParams :=
+ { uri := m.uri
+ version? := some m.version
+ diagnostics := diagnostics.toArray }
+ hOut.writeLspNotification {
+ method := "textDocument/publishDiagnostics"
+ param := toJson diagParams
+ }
+
end Lean.Widget
diff --git a/src/Lean/Widget/TaggedText.lean b/src/Lean/Widget/TaggedText.lean
index 22267a97ca6a..fd3ba7ad419d 100644
--- a/src/Lean/Widget/TaggedText.lean
+++ b/src/Lean/Widget/TaggedText.lean
@@ -65,11 +65,6 @@ def appendTag (acc : TaggedText α) (t₀ : α) (a₀ : TaggedText α) : TaggedT
| append as => append (as.push <| tag t₀ a₀)
| a => append #[a, tag t₀ a₀]
-partial def toString [ToString α] : TaggedText α → String
- | text s => s
- | append as => " ++ ".intercalate (as.toList.map toString)
- | tag t a => s!"([{t}] {toString a})"
-
partial def map (f : α → β) : TaggedText α → TaggedText β :=
go
where go : TaggedText α → TaggedText β
diff --git a/src/Lean/Widget/ToHtmlFormat.lean b/src/Lean/Widget/ToHtmlFormat.lean
deleted file mode 100644
index 521b3dfedf91..000000000000
--- a/src/Lean/Widget/ToHtmlFormat.lean
+++ /dev/null
@@ -1,6 +0,0 @@
-/-- Types implementing this can displayed in HTML, for example as a SVG.
-This is non-interactive -- for interactivity, see widgets. -/
--- should suffice for Dynkin
--- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Dynkin.20diagrams
-class ToHtmlFormat (α : Type u) where
- toHtmlFormat : α → String -- TODO HTML