The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.Widget.SelectPanelUtils

15 declarations. Mathlib docs · Source

Selection panel utilities

The main declaration is mkSelectionPanelRPC which helps creating rpc methods for widgets generating tactic calls based on selected sub-expressions in the main goal.

There are also some minor helper functions.

theorem SelectInsertParams.mk.injEq E0 #

∀ (pos : Lean.Lsp.Position) (goals : Array Lean.Widget.InteractiveGoal)
  (selectedLocations : Array Lean.SubExpr.GoalsLocation) (replaceRange : Lean.Lsp.Range) (pos_1 : Lean.Lsp.Position)
  (goals_1 : Array Lean.Widget.InteractiveGoal) (selectedLocations_1 : Array Lean.SubExpr.GoalsLocation)
  (replaceRange_1 : Lean.Lsp.Range),
  ({ pos := pos, goals := goals, selectedLocations := selectedLocations, replaceRange := replaceRange } =
      { pos := pos_1, goals := goals_1, selectedLocations := selectedLocations_1, replaceRange := replaceRange_1 }) =
    (pos = pos_1 ∧ goals = goals_1 ∧ selectedLocations = selectedLocations_1 ∧ replaceRange = replaceRange_1)

theorem SelectInsertParams.mk.inj E1 #

∀ {pos : Lean.Lsp.Position} {goals : Array Lean.Widget.InteractiveGoal}
  {selectedLocations : Array Lean.SubExpr.GoalsLocation} {replaceRange : Lean.Lsp.Range} {pos_1 : Lean.Lsp.Position}
  {goals_1 : Array Lean.Widget.InteractiveGoal} {selectedLocations_1 : Array Lean.SubExpr.GoalsLocation}
  {replaceRange_1 : Lean.Lsp.Range},
  { pos := pos, goals := goals, selectedLocations := selectedLocations, replaceRange := replaceRange } =
      { pos := pos_1, goals := goals_1, selectedLocations := selectedLocations_1, replaceRange := replaceRange_1 } →
    pos = pos_1 ∧ goals = goals_1 ∧ selectedLocations = selectedLocations_1 ∧ replaceRange = replaceRange_1

def SelectInsertParams.ctorIdx E1 #

SelectInsertParams → ℕ

def getGoalLocations E1 #

Array Lean.SubExpr.GoalsLocation → Array Lean.SubExpr.Pos

Given a Array GoalsLocation return the array of SubExpr.Pos for all locations in the targets of the relevant goals.

def insertMetaVar E1 #

Lean.Expr → Lean.SubExpr.Pos → Lean.MetaM Lean.Expr

Replace the sub-expression at the given position by a fresh meta-variable.

def String.renameMetaVar E1 #

String → String

Replace all meta-variable names by "?_".

structure SelectInsertParams E1 #

Type

Structures providing parameters for a Select and insert widget.

ctor SelectInsertParams.mk E0 #

Lean.Lsp.Position →
  Array Lean.Widget.InteractiveGoal → Array Lean.SubExpr.GoalsLocation → Lean.Lsp.Range → SelectInsertParams

abbrev SelectInsertParams.pos E1 #

SelectInsertParams → Lean.Lsp.Position

Cursor position in the file at which the widget is being displayed.

abbrev SelectInsertParams.goals E1 #

SelectInsertParams → Array Lean.Widget.InteractiveGoal

The current tactic-mode goals.

abbrev SelectInsertParams.selectedLocations E1 #

SelectInsertParams → Array Lean.SubExpr.GoalsLocation

Locations currently selected in the goal state.

abbrev SelectInsertParams.replaceRange E1 #

SelectInsertParams → Lean.Lsp.Range

The range in the source document where the command will be inserted.

instance instRpcEncodableSelectInsertParams E0 #

Lean.Server.RpcEncodable SelectInsertParams

instance instSelectInsertParamsClassSelectInsertParams E0 #

SelectInsertParamsClass SelectInsertParams

def mkSelectionPanelRPC E1 #

{Params : Type} →
  [SelectInsertParamsClass Params] →
    (Array Lean.SubExpr.GoalsLocation →
        Lean.Expr → Params → Lean.MetaM (String × String × Option (String.Pos.Raw × String.Pos.Raw))) →
      String →
        String →
          optParam Bool true →
            optParam Bool false → Params → Lean.Server.RequestM (Lean.Server.RequestTask ProofWidgets.Html)

Helper function to create a widget allowing to select parts of the main goal and then display a link that will insert some tactic call.

The main argument is mkCmdStr which is a function creating the link text and the tactic call text. The helpMsg argument is displayed when nothing is selected and title is used as a panel title. The onlyGoal argument says whether the selected has to be in the goal. Otherwise it can be in the local context. The onlyOne argument says whether one should select only one sub-expression. In every cases, all selected subexpressions should be in the main goal or its local context.

The last arguments params should not be provided so that the output has type Params → RequestM (RequestTask ProofWidgets.Html) and can be fed to the mk_rpc_widget% elaborator.

Note that the pos and goalType arguments to mkCmdStr could be extracted for the Params argument but that extraction would happen in every example, hence it is factored out here. We also make sure mkCmdStr is executed in the right context.