"Try this" code action and tactic suggestions #
This implements a mechanism for tactics to print a message saying Try this: <suggestion>,
where <suggestion> is a link to a replacement tactic. Users can either click on the link
in the suggestion (provided by a widget), or use a code action which applies the suggestion.
Raw widget #
Code action #
Formatting #
Delaborate e into syntax suitable for use by refine.
Equations
Instances For
Delaborate e into a suggestion suitable for use by refine.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add a "try this" suggestion. This has two effects:
- A widget diagnostic is displayed, saying Try this: <suggestion>with a link on<suggestion>to apply the suggestion
- A code action is added, which will apply the suggestion.
The parameters are:
- ref: the span of the widget diagnostic
- s: a- Suggestion, which contains- suggestion: the replacement text
- preInfo?: an optional string shown immediately before the replacement text in the widget message (only)
- postInfo?: an optional string shown immediately after the replacement text in the widget message (only)
- messageData?: an optional- MessageDatadisplayed instead of- suggestion. If set, implies- diffGranularity = .none.
- toCodeActionTitle?: an optional function- String → Stringdescribing how to transform the pretty-printed suggestion text into the code action text which appears in the lightbulb menu. If- none, we simply prepend- "Try This: "to the suggestion text.
 
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- header: a string that begins the display. By default, it is- "Try this:".
- codeActionPrefix?: an optional string to be used as the prefix of the replacement text if the suggestion does not have a custom- toCodeActionTitle?. If not provided,- "Try this: "is used.
- diffGranularity: How to compute the diff display in the suggestion. Defaults to only displaying the inserted string.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add a list of "try this" suggestions as a single "try these" suggestion. This has two effects:
- A widget diagnostic is displayed, saying Try these: <list of suggestions>with a link on each suggestion in<list of suggestions>to apply each suggestion
- A code action for each suggestion is added, which will apply the suggestion.
The parameters are:
- ref: the span of the widget diagnostic
- suggestions: an array of- Suggestions, which each contain- suggestion: the replacement text
- preInfo?: an optional string shown immediately before the replacement text in the widget message (only)
- postInfo?: an optional string shown immediately after the replacement text in the widget message (only)
- messageData?: an optional- MessageDatadisplayed instead of- suggestion. If set, implies- diffGranularity = .none.
- toCodeActionTitle?: an optional function- String → Stringdescribing how to transform the pretty-printed suggestion text into the code action text which appears in the lightbulb menu. If- none, we simply prepend- "Try this: "to the suggestion text.
 
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- header: a string that precedes the list. By default, it is- "Try these:".
- style?(deprecated): unused.
- codeActionPrefix?: an optional string to be used as the prefix of the replacement text for all suggestions which do not have a custom- toCodeActionTitle?. If not provided,- "Try this: "is used.
- diffGranularity: How to compute the diff display in the suggestion. Defaults to only displaying the inserted string.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Tactic-specific widget hooks #
Add an exact e or refine e suggestion.
The parameters are:
- ref: the span of the widget diagnostic
- e: the replacement expression
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- addSubgoalsMsg: if true (default false), any remaining subgoals will be shown after- Remaining subgoals:
- codeActionPrefix?: an optional string to be used as the prefix of the replacement text if the suggestion does not have a custom- toCodeActionTitle?. If not provided,- "Try this: "is used.
- checkState?: if passed, the tactic state in which the generated tactic will be validated, inserting- expose_namesif necessary.
- tacticErrorAsInfo: if true (default false), if a generated tactic is invalid (e.g., due to a pretty-printing issue), the resulting error message will be logged as an info message instead of being thrown as an error. Has no effect if- checkState?is- none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add exact e or refine e suggestions if they can be successfully generated; for those that
cannot, display messages indicating the invalid generated tactics.
The parameters are:
- ref: the span of the widget diagnostic
- es: the array of replacement expressions
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- addSubgoalsMsg: if true (default false), any remaining subgoals will be shown after- Remaining subgoals:
- codeActionPrefix?: an optional string to be used as the prefix of the replacement text for all suggestions which do not have a custom- toCodeActionTitle?. If not provided,- "Try this: "is used.
- checkState?: if passed, the tactic state in which the generated tactics will be validated, inserting- expose_namesif necessary.
- tacticErrorAsInfo: if true (default true), invalid generated tactics will log info messages instead of throwing an error. The default behavior differs from- addExactSuggestionbecause throwing an error means that any subsequent suggestions will not be displayed. Has no effect if- checkState?is- none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add a term suggestion.
The parameters are:
- ref: the span of the widget diagnostic
- e: the replacement expression
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- header: a string which precedes the suggestion. By default, it's- "Try this:".
- codeActionPrefix?: an optional string to be used as the prefix of the replacement text if the suggestion does not have a custom- toCodeActionTitle?. If not provided,- "Try this: "is used.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add term suggestions.
The parameters are:
- ref: the span of the widget diagnostic
- es: an array of the replacement expressions
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- header: a string which precedes the list of suggestions. By default, it's- "Try these:".
- codeActionPrefix?: an optional string to be used as the prefix of the replacement text for all suggestions which do not have a custom- toCodeActionTitle?. If not provided,- "Try this: "is used.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add a suggestion for have h : t := e.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add a suggestion for rw [h₁, ← h₂] at loc.
Parameters:
- ref: the span of the widget diagnostic
- rules: a list of arguments to- rw, with the second component- trueif the rewrite is reversed
- type?: the goal after the suggested rewrite,- .noneif the rewrite closes the goal, or- .undefif the resulting goal is unknown
- loc?: the hypothesis at which the rewrite is performed, or- noneif the goal is targeted
- origSpan?: a syntax object whose span is the actual text to be replaced by- suggestion. If not provided it defaults to- ref.
- checkState?: if passed, the tactic state in which the generated tactic will be validated, inserting- expose_namesif necessary