feat: add range parameter to getInteractiveDiagnostics

This commit is contained in:
Gabriel Ebner 2021-10-11 18:59:03 +02:00 committed by Sebastian Ullrich
parent e068833e8d
commit d6ba8e597a
2 changed files with 22 additions and 4 deletions

View file

@ -137,4 +137,12 @@ structure RpcKeepAliveParams where
sessionId : UInt64
deriving FromJson, ToJson
/--
Range of lines in a document, including `start` but excluding `end`.
-/
structure LineRange where
start : Nat
«end» : Nat
deriving Inhabited, Repr, FromJson, ToJson
end Lean.Lsp

View file

@ -67,16 +67,26 @@ builtin_initialize
(Option InteractiveTermGoal)
FileWorker.getInteractiveTermGoal
structure GetInteractiveDiagnosticsParams where
lineRange? : Option Lsp.LineRange
deriving Inhabited, FromJson, ToJson
open RequestM in
def getInteractiveDiagnostics (_ : Json) : RequestM (RequestTask (Array InteractiveDiagnostic)) := do
def getInteractiveDiagnostics (params : GetInteractiveDiagnosticsParams) : RequestM (RequestTask (Array InteractiveDiagnostic)) := do
let doc ← readDoc
let t₁ ← doc.cmdSnaps.waitAll
t₁.map fun (snaps, _) => snaps.getLast!.interactiveDiags.toArray
let rangeEnd ← params.lineRange?.map fun range =>
doc.meta.text.lspPosToUtf8Pos ⟨range.«end», 0⟩
withWaitFindSnap doc (fun snap => rangeEnd.all (· ≤ snap.endPos)) #[]
fun snap => snap.interactiveDiags.toArray.filter fun diag =>
params.lineRange?.all fun ⟨s, e⟩ =>
-- does [s,e) intersect [diag.fullRange.start.line,diag.fullRange.end.line)?
s ≤ diag.fullRange.start.line ∧ diag.fullRange.start.line < e
diag.fullRange.start.line ≤ s ∧ s < diag.fullRange.end.line
builtin_initialize
registerRpcCallHandler
`Lean.Widget.getInteractiveDiagnostics
Json
GetInteractiveDiagnosticsParams
(Array InteractiveDiagnostic)
getInteractiveDiagnostics