chore: remove addInfo flag from elabSetOption (#13736)
This PR removes the `addInfo` flag from `elabSetOption` introduced in #11313, instead allowing callers to use `withEnableInfoTree` to control whether infotrees are added.
This commit is contained in:
parent
ce5814043b
commit
2bdc67756c
3 changed files with 9 additions and 8 deletions
|
|
@ -49,21 +49,20 @@ where
|
||||||
| _ => throwUnconfigurable optionName
|
| _ => throwUnconfigurable optionName
|
||||||
|
|
||||||
/--
|
/--
|
||||||
Elaborates `id` as an identifier representing an option name with value given by `val`.
|
Elaborates `id` as an identifier representing an option name with value given by `val`, adding
|
||||||
|
appropriate info to the infotrees.
|
||||||
|
|
||||||
Validates that `val` has the correct type for values of the option `id`, and returns the updated
|
Validates that `val` has the correct type for values of the option `id`, and returns the updated
|
||||||
`Options`. Does **not** update the options in the monad `m`.
|
`Options`. Does **not** update the options in the monad `m`.
|
||||||
|
|
||||||
If `addInfo := true` (the default), adds completion info and elaboration info to the infotrees.
|
|
||||||
-/
|
-/
|
||||||
def elabSetOption (id : Syntax) (val : Syntax) (addInfo := true) : m (Options × OptionDecl) := do
|
def elabSetOption (id : Syntax) (val : Syntax) : m (Options × OptionDecl) := do
|
||||||
let ref ← getRef
|
let ref ← getRef
|
||||||
-- For completion purposes, we discard `val` and any later arguments.
|
-- For completion purposes, we discard `val` and any later arguments.
|
||||||
-- We include the first argument (the keyword) for position information in case `id` is `missing`.
|
-- We include the first argument (the keyword) for position information in case `id` is `missing`.
|
||||||
if addInfo then addCompletionInfo <| CompletionInfo.option (ref.setArgs (ref.getArgs[*...3]))
|
addCompletionInfo <| CompletionInfo.option (ref.setArgs (ref.getArgs[*...3]))
|
||||||
let optionName := id.getId.eraseMacroScopes
|
let optionName := id.getId.eraseMacroScopes
|
||||||
let decl ← IO.toEIO (fun (ex : IO.Error) => Exception.error ref ex.toString) (getOptionDecl optionName)
|
let decl ← IO.toEIO (fun (ex : IO.Error) => Exception.error ref ex.toString) (getOptionDecl optionName)
|
||||||
if addInfo then pushInfoLeaf <| .ofOptionInfo { stx := id, optionName, declName := decl.declName }
|
pushInfoLeaf <| .ofOptionInfo { stx := id, optionName, declName := decl.declName }
|
||||||
let rec setOption (val : DataValue) : m (Options × OptionDecl) := do
|
let rec setOption (val : DataValue) : m (Options × OptionDecl) := do
|
||||||
validateOptionValue optionName decl val
|
validateOptionValue optionName decl val
|
||||||
return ((← getOptions).set optionName val, decl)
|
return ((← getOptions).set optionName val, decl)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@ partial def withSetOptionIn (cmd : CommandElab) : CommandElab := fun stx => do
|
||||||
if stx.getKind == ``Lean.Parser.Command.in &&
|
if stx.getKind == ``Lean.Parser.Command.in &&
|
||||||
stx[0].getKind == ``Lean.Parser.Command.set_option then
|
stx[0].getKind == ``Lean.Parser.Command.set_option then
|
||||||
-- Do not modify the infotrees when elaborating, and silently ignore errors.
|
-- Do not modify the infotrees when elaborating, and silently ignore errors.
|
||||||
let opts ← try (·.1) <$> elabSetOption stx[0][1] stx[0][3] (addInfo := false)
|
let opts ← withEnableInfoTree false try
|
||||||
|
(·.1) <$> elabSetOption stx[0][1] stx[0][3]
|
||||||
catch _ => getOptions
|
catch _ => getOptions
|
||||||
withScope ({ · with opts }) do withSetOptionIn cmd stx[2]
|
withScope ({ · with opts }) do withSetOptionIn cmd stx[2]
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -317,7 +317,8 @@ def handleIn : Handler := fun _ stx => do
|
||||||
-- `set_option ... in`. This is unlike `withSetOptionIn`, which stops at the first `in` not of
|
-- `set_option ... in`. This is unlike `withSetOptionIn`, which stops at the first `in` not of
|
||||||
-- the form `set_option ... in`; as such, we must inline the functionality.
|
-- the form `set_option ... in`; as such, we must inline the functionality.
|
||||||
if stx[0].getKind == ``«set_option» then
|
if stx[0].getKind == ``«set_option» then
|
||||||
let opts ← try (·.1) <$> Elab.elabSetOption stx[0][1] stx[0][3] (addInfo := false)
|
let opts ← Elab.withEnableInfoTree false try
|
||||||
|
(·.1) <$> Elab.elabSetOption stx[0][1] stx[0][3]
|
||||||
catch _ => getOptions
|
catch _ => getOptions
|
||||||
withScope ({ · with opts }) do missingDocs.run stx[2]
|
withScope ({ · with opts }) do missingDocs.run stx[2]
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue