feat: add range parameter to getInteractiveDiagnostics
This commit is contained in:
parent
e068833e8d
commit
d6ba8e597a
2 changed files with 22 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue