Commit graph

61 commits

Author SHA1 Message Date
Mario Carneiro
fb82428f2d
feat: hover / go-to-def for attribute cmd (#3896)
`attribute [attr] foo` was missing a hover on `foo`.
2024-04-13 07:13:25 +00:00
Mario Carneiro
49f66dc485
perf: rewrite UnusedVariables lint (#3186)
This is a rewrite of the `UnusedVariables` lint to inline and simplify
many of the dependent functions to try to improve the performance of
this lint, which quite often shows up in perf reports.

* The mvar assignment scanning is one of the most expensive parts of the
process, so we do two things to improve this:
  * Lazily perform the scan only if we need it
* Use an object-pointer hashmap to ensure that we don't have quadratic
behavior when there are many mvar assignments with slight differences.
* The dependency on `Lean.Server` is removed, meaning we don't need to
do the LSP conversion stuff anymore. The main logic of reference finding
is inlined.
* We take `fvarAliases` into account, and union together fvars which are
aliases of a base fvar. (It would be great if we had `UnionFind` here.)

More docs will be added once we confirm an actual perf improvement.

---------

Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
2024-03-21 12:28:57 +00:00
Kyle Miller
45fccc5906
feat: custom eliminators for induction and cases tactics, and beautiful eliminators for Nat (#3629)
Replaces `@[eliminator]` with two attributes `@[induction_eliminator]`
and `@[cases_eliminator]` for defining custom eliminators for the
`induction` and `cases` tactics, respectively.

Adds `Nat.recAux` and `Nat.casesAuxOn`, which are eliminators that are
defeq to `Nat.rec` and `Nat.casesOn`, but these use `0` and `n + 1`
rather than `Nat.zero` and `Nat.succ n`.

For example, using `induction` to prove that the factorial function is
positive now has the following goal states (thanks also to #3616 for the
goal state after unfolding).
```lean
example : 0 < fact x := by
  induction x with
  | zero => decide
  | succ x ih =>
    /-
    x : Nat
    ih : 0 < fact x
    ⊢ 0 < fact (x + 1)
    -/
    unfold fact
    /-
    ...
    ⊢ 0 < (x + 1) * fact x
    -/
    simpa using ih
```

Thanks to @adamtopaz for initial work on splitting the `@[eliminator]`
attribute.
2024-03-09 15:31:51 +00:00
Kyle Miller
f336525f31
fix: make delabConstWithSignature avoid using inaccessible names (#3625)
The `delabConstWithSignature` delaborator is responsible for pretty
printing constants with a declaration-like signature, with binders, a
colon, and a type. This is used by the `#check` command when it is given
just an identifier.

It used to accumulate binders from pi types indiscriminately, but this
led to unfriendly behavior. For example, `#check String.append` would
give
```
String.append (a✝ : String) (a✝¹ : String) : String
```
with inaccessible names. These appear because `String.append` is defined
using patterns, so it never names these parameters.

Now the delaborator stops accumulating binders once it reaches an
inaccessible name, and for example `#check String.append` now gives
```
String.append : String → String → String
```
We do not synthesize names for the sake of enabling binder syntax
because the binder names are part of the API of a function — one can use
`(arg := ...)` syntax to pass arguments by name. The delaborator also
now stops accumulating binders once it reaches a parameter with a name
already seen before — we then rely on the main delaborator to provide
that parameter with a fresh name when pretty printing the pi type.

As a special case, instance parameters with inaccessible names are
included as binders, pretty printing like `[LT α]`, rather than
relegating them (and all the remaining parameters) to after the colon.
It would be more accurate to pretty print this as `[inst✝ : LT α]`, but
we make the simplifying assumption that such instance parameters are
generally used via typeclass inference. Likely `inst✝` would not
directly appear in pretty printer output, and even if it appears in a
hover, users can likely figure out what is going on. (We may consider
making such `inst✝` variables pretty print as `‹LT α›` or
`infer_instance` in the future, to make this more consistent.)

Something we note here is that we do not do anything to make sure
parameters that can be used as named arguments actually appear named
after the colon (nor do we assure that the names are the correct names).
For example, one sees `foo : String → String → String` rather than `foo
: String → (baz : String) → String`. We can investigate this later if it
is wanted.

We also give `delabConstWithSignature` a `universes` flag to enable
turning off pretty printing universe levels parameters.

Closes #2846
2024-03-07 18:14:06 +00:00
Marcus Rossel
509f35df02
doc: fix typos (#3236) 2024-02-01 19:03:58 +00:00
Mario Carneiro
d1a15dea03
fix: hover info for cases h : ... (#3084)
This makes hover info, go to definition, etc work for the `h` in `cases
h : e`. The implementation is similar to that used for the `generalize h
: e = x` tactic.
2023-12-21 22:39:23 +00:00
Marc Huisinga
7ff7cf9b5a
feat: per-package server options (#2858)
This PR adds per-package server options to resolve #2455. It is based on
the previous work in #2456, but takes a different approach: options are
loaded for the specific file in the file worker when `print-paths` is
called, instead of loading them in the watchdog with a separate Lake
command. This change addresses review comments made in #2456.

In doing so, it introduces two new Lake config fields: 
- `leanOptions`: `-D` flag options that are passed to both the language
server and `lean` when building.
- `moreServerOptions`: `-D` flag options that are passed to the language
server.

Since `print-paths` must also accept a file path to compute the options
for that file, this PR is changing the API for `print-paths`. As there
have been numerous complaints about the name `print-paths`, I also
decided to change it to `setup-file` in this PR, since it would break
compatibility with the old Lake API anyways.

This PR deprecates the Lakefile field `moreServerArgs` in favor of
`moreGlobalServerArgs`, as suggested in the review for #2456.

Fixes #2455

---------

Co-authored-by: digama0 <mcarneir@andrew.cmu.edu>
2023-11-26 13:42:38 +00:00
Mario Carneiro
82196efe94 feat: hovers on open and export decls 2023-11-02 17:01:51 +01:00
Joachim Breitner
ae470e038e
docs: fix doc comment syntax in declModifiers doc comment (#2590)
The hover on `declModifiers` says doc comments are `/-! … -/`, when it
should say `/-- … -/`.
2023-09-27 11:57:40 +10:00
Mario Carneiro
e6fe3bee71 fix: hover term/tactic confusion 2023-09-26 10:16:37 +02:00
Mario Carneiro
2037094f8c
doc: document all parser aliases (#2499) 2023-09-06 09:02:25 +00:00
Mario Carneiro
b4cf1dd943 feat: binder info for generalize 2023-06-09 14:41:00 -07:00
Sebastian Ullrich
b6bd2dea35 feat: signature pretty printer for hovers 2022-12-21 21:59:05 +01:00
Sebastian Ullrich
39f2322f35 fix: save correct environment in info tree for example 2022-11-24 13:11:14 -08:00
Sebastian Ullrich
4c11743f4b refactor: split paren parser, part 2 2022-11-11 13:45:41 +01:00
Mario Carneiro
4fefb2097f feat: hover/go-to-def/refs for options 2022-11-07 20:01:13 +01:00
Mario Carneiro
32b6bd0d8b feat: empty type ascription syntax (e :) (part 2) 2022-11-07 19:10:56 +01:00
Sebastian Ullrich
1893857f15 fix: expandCDot? should create canonical syntax 2022-10-25 12:23:13 +02:00
Sebastian Ullrich
f39281f6b4 fix: hoverableInfoAt? in presence of canonical syntax 2022-10-25 12:23:13 +02:00
Mario Carneiro
9aa57f9959 fix: .ident hover in patterns 2022-09-30 15:18:06 -07:00
Mario Carneiro
7a6f7cb0ac fix: induction info tree nesting 2022-09-29 19:07:18 +02:00
Mario Carneiro
73f44ccb7b feat: hover for cases/induction case names 2022-09-29 19:07:18 +02:00
Mario Carneiro
d843e2a418 chore: add docs and test 2022-09-27 22:09:54 +02:00
Mario Carneiro
5644bd7a3f feat: show decl module in hover 2022-09-25 06:43:48 -07:00
Sebastian Ullrich
a657a638f0 feat: sub-info tree level hover 2022-08-31 17:49:43 -07:00
Mario Carneiro
9bd886f37d fix: @[inheritDoc] on notation 2022-08-27 07:11:39 -07:00
Mario Carneiro
37a12b635b feat: add declId hover for syntax/notation/mixfix 2022-08-17 05:55:06 -07:00
Mario Carneiro
e0221db2e2 feat: add @[inheritDoc] attribute 2022-08-16 18:31:55 -07:00
Mario Carneiro
b201db4bf7 feat: add hover info for quot precheck 2022-08-13 17:31:57 -07:00
Mario Carneiro
1302d8f7fc feat: prefer syntax doc over elab when both are present
closes #1443
2022-08-12 08:14:55 -07:00
Mario Carneiro
7cc8f7c4c4 feat: go to definition for antiquot kinds 2022-08-11 17:46:36 +02:00
Mario Carneiro
6026894f9f doc: finish Init.Prelude docs 2022-08-09 14:25:44 -07:00
Mario Carneiro
37d3479e7c doc: add more docs to Init.Prelude 2022-08-06 09:32:16 -07:00
Mario Carneiro
59b32da2d9 feat: go to def on parser aliases 2022-08-06 12:44:14 +02:00
Leonardo de Moura
659300597d doc: some doc strings for Prelude.lean 2022-08-04 20:55:13 -07:00
Leonardo de Moura
f295a76b69 chore: fix test output 2022-08-04 15:29:17 -07:00
Sebastian Ullrich
2f0b65fad3 fix: do not show inaccessible variable in hover 2022-08-04 11:28:46 -07:00
Sebastian Ullrich
a44472962d fix: replace uses of token antiquotations in tactics with with_annotate_state 2022-08-02 04:54:48 -07:00
Sebastian Ullrich
759a7d771f fix: do not show inferred type on attribute application 2022-07-31 16:36:54 +02:00
Leonardo de Moura
3846dd60fd fix: evalTactic
This commit fixes bug reported by Patrick Massot.
It happened when using `macro_rules` and `elab_rules` for the same
`SyntaxNodeKind`.

It also fixes missing error messages when there is more than one
elaboration functions and there is `abortTactic` exception.

Remark: this commit also changes the evaluation order. Macros are
now tried before elaboration rules. The motivation is that macros are
already applied before elaboration functions in the term elaborator.
2022-07-19 23:28:14 -04:00
Leonardo de Moura
989d8f04e1 chore: fix tests 2022-06-14 17:27:13 -07:00
Sebastian Ullrich
ddfbf6bf9b fix: show namespace when hovering over declaration name 2022-06-02 18:17:21 +02:00
Sebastian Ullrich
46df02877d fix: elab info for decreasing_by 2022-05-16 10:20:49 +02:00
Leonardo de Moura
37b321229f feat: make sure hover information does not include @ for constants 2022-04-07 18:40:04 -07:00
Leonardo de Moura
36e032cf94 chore: fix test 2022-04-06 14:55:27 -07:00
Leonardo de Moura
1107705525 fix: jump to definition inside recursive definitions was not working on VS Code
Remark: it was working on Emacs.
2022-04-06 14:27:49 -07:00
Leonardo de Moura
149cd1ee82 chore: fix test 2022-04-05 21:04:55 -07:00
Mario Carneiro
c29da66c5a
fix: annotate binders in intro for hover / go to def 2022-03-22 12:10:51 +00:00
Sebastian Ullrich
312944e784 fix: hover etc. on complex declaration name 2022-01-19 12:27:03 +01:00
Gabriel Ebner
50abc3e295 fix: correctly pretty-print @Eq 2022-01-12 09:41:41 +01:00