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: widget messages #730

Merged
merged 1 commit into from Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Lean/Server/FileWorker/WidgetRequests.lean
Expand Up @@ -68,6 +68,8 @@ builtin_initialize
FileWorker.getInteractiveTermGoal

structure GetInteractiveDiagnosticsParams where
/-- Return diagnostics for these lines only if present,
otherwise return all diagnostics. -/
lineRange? : Option Lsp.LineRange
deriving Inhabited, FromJson, ToJson

Expand All @@ -76,12 +78,15 @@ def getInteractiveDiagnostics (params : GetInteractiveDiagnosticsParams) : Reque
let doc ← readDoc
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
let t ← doc.cmdSnaps.waitAll fun snap => rangeEnd.all (snap.beginPos < ·)
t.map fun (snaps, _) =>
let diags? := snaps.getLast?.map 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
diags?.getD #[]

builtin_initialize
registerRpcCallHandler
Expand Down
6 changes: 3 additions & 3 deletions src/Lean/Server/Requests.lean
Expand Up @@ -95,9 +95,9 @@ def bindTask (t : Task α) (f : α → RequestM (RequestTask β)) : RequestM (Re
| Except.error e => throwThe RequestError e
| Except.ok v => v

/-- Create a task which waits for a snapshot matching `p`, handles various errors,
and if a matching snapshot was found executes `x` with it. If not found, the task
executes `notFoundX`. -/
/-- Create a task which waits for the first snapshot matching `p`, handles various errors,
and if a matching snapshot was found executes `x` with it. If not found, the task executes
`notFoundX`. -/
def withWaitFindSnap (doc : EditableDocument) (p : Snapshot → Bool)
(notFoundX : RequestM β)
(x : Snapshot → RequestM β)
Expand Down
1 change: 1 addition & 0 deletions src/Lean/Widget/InteractiveCode.lean
Expand Up @@ -78,6 +78,7 @@ private def formatWithOpts (e : Expr) (optsPerPos : Delaborator.OptionsPerPos)
let currNamespace ← getCurrNamespace
let openDecls ← getOpenDecls
let opts ← getOptions
let e ← Meta.instantiateMVars e
let (stx, infos) ← PrettyPrinter.delabCore currNamespace openDecls e optsPerPos
let stx := sanitizeSyntax stx |>.run' { options := opts }
let stx ← PrettyPrinter.parenthesizeTerm stx
Expand Down