Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vtec234 committed Aug 3, 2021
1 parent 3198f11 commit c19deef
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
34 changes: 12 additions & 22 deletions src/Lean/Server/FileWorker.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 "<input>"
let (headerStx, headerParserState, msgLog) ← Parser.parseHeader inputCtx
Expand All @@ -180,7 +170,7 @@ section Initialization
catch e => -- should be from `leanpkg print-paths`
let msgs := MessageLog.empty.add { fileName := "<ignored>", 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 := {
Expand All @@ -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 ({
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Lean/Widget.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ import Lean.Widget.ExprWithCtx
import Lean.Widget.InteractiveGoals
import Lean.Widget.InteractiveDiagnostics
import Lean.Widget.TaggedText
import Lean.Widget.ToHtmlFormat
17 changes: 17 additions & 0 deletions src/Lean/Widget/InteractiveDiagnostics.lean
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
5 changes: 0 additions & 5 deletions src/Lean/Widget/TaggedText.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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 β
Expand Down
6 changes: 0 additions & 6 deletions src/Lean/Widget/ToHtmlFormat.lean

This file was deleted.

0 comments on commit c19deef

Please sign in to comment.