lean4-htt/tests/lean/interactive/signatureHelp.lean
Marc Huisinga cb0284f98e
feat: signature help (#8511)
This PR implements signature help support. When typing a function
application, editors with support for signature help will now display a
popup that designates the current (remaining) function type. This
removes the need to remember the function signature while typing the
function application, or having to constantly cycle between hovering
over the function identifier and typing the application. In VS Code, the
signature help can be triggered manually using `Ctrl+Shift+Space`.


![Demo](https://github.com/user-attachments/assets/d1f6ed79-bb16-4593-8d28-68b1cce5d5dc)

### Other changes

- In order to support signature help for the partial syntax `f a <|` or
`f a $`, these notations now elaborate as `f a`, not `f a .missing`.
- The logic in `delabConstWithSignature` that delaborates parameters is
factored out into a function `delabForallParamsWithSignature` so that it
can be used for arbitrary `forall`s, not just constants.
- The `InfoTree` formatter is adjusted to produce output where it is
easier to identify the kind of `Info` in the `InfoTree`.
- A bug in `InfoTree.smallestInfo?` is fixed so that it doesn't panic
anymore when its predicate `p` does not ensure that both `pos?` and
`tailPos?` of the `Info` are present.
2025-06-03 17:26:33 +00:00

144 lines
5.3 KiB
Text

def simpleFun {_ : Type} (a b : Nat) : Nat → Nat → Nat := sorry
#check simpleFun -- Full signature help expected
--^ textDocument/signatureHelp
#check simpleFun -- Full signature help expected
--^ textDocument/signatureHelp
#check simpleFun 0 -- Shortened signature help expected (implicit is skipped)
--^ textDocument/signatureHelp
#check simpleFun 0 0 -- Shortened signature help without ∀ expected
--^ textDocument/signatureHelp
#check simpleFun 0 0 0 -- Shortened signature help without ∀ expected
--^ textDocument/signatureHelp
#check simpleFun 0 0 0 0 -- No signature help expected
--^ textDocument/signatureHelp
#check simpleFun 0 0 0 0 -- No signature help expected
--^ textDocument/signatureHelp
#check simpleFun -- No signature help expected in end-of-line comment
--^ textDocument/signatureHelp
#check simpleFun <| -- Full signature help expected
--^ textDocument/signatureHelp
#check simpleFun 0 0 0 <| -- Shortened signature help expected
--^ textDocument/signatureHelp
#check simpleFun 0 <| simpleFun -- Full signature help expected
--^ textDocument/signatureHelp
#check simpleFun $ -- Full signature help expected
--^ textDocument/signatureHelp
#check simpleFun 0 0 0 $ -- Shortened signature help expected
--^ textDocument/signatureHelp
#check simpleFun 0 $ simpleFun -- Full signature help expected
--^ textDocument/signatureHelp
#check simpleFun ( ) -- No signature help expected
--^ textDocument/signatureHelp
#check @simpleFun -- Full signature help expected
--^ textDocument/signatureHelp
#check @simpleFun _ -- Shortened signature help expected (implicit is not skipped)
--^ textDocument/signatureHelp
#check simpleFun (b := 0) -- Shortened signature help without `b` expected
--^ textDocument/signatureHelp
#check (simpleFun 0) -- Shortened signature help expected
--^ textDocument/signatureHelp
#check (simpleFun 0) 0 -- Shortened signature help expected
--^ textDocument/signatureHelp
def simpleProp (x y : Nat) : x = y → x = y := sorry
#check simpleProp -- Full signature help with `∀` expected
--^ textDocument/signatureHelp
#check simpleProp 0 -- Shortened signature help with `∀` expected
--^ textDocument/signatureHelp
#check simpleProp 0 0 -- Shortened signature help with remaining implication expected
--^ textDocument/signatureHelp
#check simpleProp 0 0 sorry -- No signature help expected
--^ textDocument/signatureHelp
def complexFun (f : Nat → Nat → Nat → Nat → Nat) (x : Nat) : Nat := sorry
#check complexFun simpleFun -- Shortened signature help of `complexFun` expected
--^ textDocument/signatureHelp
#check complexFun simpleFun 0 -- No signature help expected
--^ textDocument/signatureHelp
#check complexFun (simpleFun ) -- Signature help of `simpleFun` expected
--^ textDocument/signatureHelp
structure SomeStructure where
fieldFun (x : Nat) : Nat → Nat
def SomeStructure.dotFun (s : SomeStructure) (x : Nat) : Nat := sorry
def SomeStructure.dotIdFun (x : Nat) : SomeStructure := sorry
variable (s : SomeStructure) (s' : Nat → SomeStructure)
#check s.fieldFun -- Full signature help expected
--^ textDocument/signatureHelp
#check s.fieldFun 0 -- Shortened signature help expected
--^ textDocument/signatureHelp
#check s.fieldFun 0 0 -- No signature help expected
--^ textDocument/signatureHelp
#check (s' 0).fieldFun -- Full signature help expected
--^ textDocument/signatureHelp
#check (s' 0).fieldFun 0 -- Shortened signature help expected
--^ textDocument/signatureHelp
#check s.dotFun -- Full signature help expected
--^ textDocument/signatureHelp
#check s.dotFun 0 -- No signature help expected
--^ textDocument/signatureHelp
#check (s' 0).dotFun -- Full signature help expected
--^ textDocument/signatureHelp
#check (s' 0).dotFun 0 -- No signature help expected
--^ textDocument/signatureHelp
#check s |>.fieldFun -- Full signature help expected
--^ textDocument/signatureHelp
#check s |>.fieldFun 0 -- Shortened signature help expected
--^ textDocument/signatureHelp
#check s |>.fieldFun 0 0 -- No signature help expected
--^ textDocument/signatureHelp
#check s' 0 |>.fieldFun -- Full signature help expected
--^ textDocument/signatureHelp
#check s' 0 |>.fieldFun 0 -- Shortened signature help expected
--^ textDocument/signatureHelp
example : SomeStructure := .dotIdFun -- Full signature help expected
--^ textDocument/signatureHelp
example : SomeStructure := .dotIdFun 0 -- No signature help expected
--^ textDocument/signatureHelp