lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

fix: attribute info nesting

Open digama0 opened this issue 3 years ago • 2 comments

This fixes an issue with hovers inside user attributes caused by the fact that the info nodes generated by the user attribute are not nested correctly under the attribute itself, owing to the fact that the info node for the attribute itself is generated at elaboration time while the info nodes generated by the attribute are added at application time, which may be much later.

Now the attribute node is generated immediately before the user function is called, and the nodes generated by the user code nest inside the attribute node.

It is difficult to add a test case for this, though, since all of the tests/lean/interactive tests are single-file and none of the builtin attributes add an info span over the attribute name (which is where the original bug manifests). This was extracted from this mathlib4 issue.

import Lean
open Lean Elab

syntax (name := test) "test" ident : attr

initialize registerBuiltinAttribute {
    name := `test
    descr := "test"
    add := fun decl stx _ => do
      pushInfoLeaf <| .ofTermInfo {
        elaborator := .anonymous, lctx := {}, expectedType? := none
        stx := stx[0]
        expr := (← mkConstWithLevelParams decl)
      }
  }
import Test.Attr

/-- doc -/
@[test x] def foo := 1
--^ textDocument/hover
-- should show "foo : Nat" instead of fooAttr

digama0 avatar Oct 10 '22 08:10 digama0

@Kha Do you see a quick hack to add the test @digama0 provided above to our test suite?

leodemoura avatar Oct 10 '22 11:10 leodemoura

Not really, no.

Kha avatar Oct 10 '22 11:10 Kha

This fixes an issue with hovers inside user attributes caused by the fact that the info nodes generated by the user attribute are not nested correctly under the attribute itself

Is this resolved by https://github.com/leanprover/lean4/pull/1753/files#diff-83bd7ca17a546fdf495692949c7412fc3a059f292c59e667898804da030dba22R156-R160?

Kha avatar Oct 23 '22 19:10 Kha

I think we concluded last week that we can merge this?

Kha avatar Nov 02 '22 10:11 Kha