fix: account for namespaces/open decls in inlineExpr (#9108)
This PR fixes an issue that may have caused inline expressions in messages to be unnecessarily rendered on a separate line.
This commit is contained in:
parent
a018ed3f0f
commit
d31dfe92de
2 changed files with 36 additions and 9 deletions
|
|
@ -618,7 +618,9 @@ actually rendered. Consider using this function in lazy message data to avoid un
|
|||
computation for messages that are not displayed.
|
||||
-/
|
||||
private def MessageData.formatLength (ctx : PPContext) (msg : MessageData) : BaseIO Nat := do
|
||||
let { env, mctx, lctx, opts, ..} := ctx
|
||||
let { env, mctx, lctx, opts, currNamespace, openDecls } := ctx
|
||||
-- Simulate the naming context that will be added to the actual message
|
||||
let msg := MessageData.withNamingContext { currNamespace, openDecls } msg
|
||||
let fmt ← msg.format (some { env, mctx, lctx, opts })
|
||||
return fmt.pretty.length
|
||||
|
||||
|
|
|
|||
|
|
@ -16,23 +16,48 @@ def runTest (e : Expr) : MetaM Unit := do
|
|||
let msg := inlineExpr e (maxInlineLength := 30)
|
||||
logInfo m!"Before{msg}After"
|
||||
|
||||
def testShort : MetaM Unit := do
|
||||
runTest <| .app (.const ``shortFun []) (.const ``shortConst [])
|
||||
|
||||
/-- info: Before `shortFun shortConst` After -/
|
||||
#guard_msgs in
|
||||
#eval testShort
|
||||
#eval runTest <| .app (.const ``shortFun []) (.const ``shortConst [])
|
||||
|
||||
opaque functionWithLongName : Nat → Nat
|
||||
opaque constantWithLongName : Nat
|
||||
|
||||
def testLong : MetaM Unit := do
|
||||
runTest <| .app (.const ``functionWithLongName []) (.const ``constantWithLongName [])
|
||||
|
||||
/--
|
||||
info: Before
|
||||
functionWithLongName constantWithLongName
|
||||
After
|
||||
-/
|
||||
#guard_msgs in
|
||||
#eval testLong
|
||||
#eval runTest <| .app (.const ``functionWithLongName []) (.const ``constantWithLongName [])
|
||||
|
||||
/-! Ensure that length computation accounts for namespace occlusion: -/
|
||||
|
||||
namespace ExceptionallyLongNamespaceThatWillNotBePrinted
|
||||
opaque Bar.Baz : Nat → Nat
|
||||
|
||||
/--
|
||||
info: Before `Bar.Baz Nat.zero` After
|
||||
-/
|
||||
#guard_msgs in
|
||||
#eval runTest <| .app (.const ``Bar.Baz []) (.const ``Nat.zero [])
|
||||
|
||||
end ExceptionallyLongNamespaceThatWillNotBePrinted
|
||||
|
||||
/-! Test `trailing` variant: -/
|
||||
|
||||
def runTestTrailing (e : Expr) : MetaM Unit := do
|
||||
let msg := inlineExprTrailing e (maxInlineLength := 30)
|
||||
logInfo m!"Before{msg}"
|
||||
|
||||
|
||||
/-- info: Before `shortFun shortConst` -/
|
||||
#guard_msgs in
|
||||
#eval runTestTrailing <| .app (.const ``shortFun []) (.const ``shortConst [])
|
||||
|
||||
/--
|
||||
info: Before
|
||||
functionWithLongName constantWithLongName
|
||||
-/
|
||||
#guard_msgs in
|
||||
#eval runTestTrailing <| .app (.const ``functionWithLongName []) (.const ``constantWithLongName [])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue