-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include expected Lean outputs and have the compiler check them
- Loading branch information
1 parent
edc878a
commit 76f2881
Showing
2 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Lean | ||
|
||
namespace LeanDoc.Doc.Suggestion | ||
|
||
open Lean Elab Server RequestM | ||
|
||
structure Suggestion where | ||
summary : String | ||
replacement : String | ||
deriving TypeName | ||
|
||
def saveSuggestion [Monad m] [MonadInfoTree m] (stx : Syntax) (summary replacement: String) : m Unit := do | ||
pushInfoLeaf <| .ofCustomInfo {stx := stx, value := Dynamic.mk (Suggestion.mk summary replacement) } | ||
|
||
@[code_action_provider] | ||
def provideSuggestions : CodeActionProvider := fun params snap => do | ||
let doc ← readDoc | ||
let text := doc.meta.text | ||
let startPos := text.lspPosToUtf8Pos params.range.start | ||
let endPos := text.lspPosToUtf8Pos params.range.end | ||
let suggestions := snap.infoTree.foldInfo (init := #[]) fun ctx info result => Id.run do | ||
let .ofCustomInfo ⟨stx, data⟩ := info | result | ||
let some suggestions := data.get? Suggestion | result | ||
let (some head, some tail) := (stx.getPos? true, stx.getTailPos? true) | result | ||
unless head ≤ endPos && startPos ≤ tail do return result | ||
result.push (ctx, head, tail, suggestions) | ||
pure <| suggestions.map fun (_, head, tail, ⟨summary, replacement⟩) => | ||
{ | ||
eager := { | ||
title := s!"Replace with {summary}", | ||
kind? := some "quickfix", | ||
edit? := some <| .ofTextDocumentEdit { | ||
textDocument := doc.versionedIdentifier, | ||
edits := #[{newText := replacement, range := ⟨text.utf8PosToLspPos head, text.utf8PosToLspPos tail⟩}] | ||
} | ||
} | ||
} |