Inferred types: in hovers, and as inlay hints
A check keeps what the compiler inferred, through Inference.observe, as each use of a name with its type there and each binding with the type it binds. A hover shows (: name type) for a local, and a generic function's type at the use hovered. Inlay hints show the type after each local name where it is bound and no type is written. Hints before the first change since the last check are sent; the ones after it wait for the check, which then asks the client to ask again. A hover runs a check that is due first. 🤖 Generated with [ECA](https://eca.dev) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
parent
cc62a8a360
commit
471b49d9e4
9 changed files with 571 additions and 20 deletions
41
README.md
41
README.md
|
|
@ -26,7 +26,8 @@ packages (see "Projects"), and it does five things:
|
|||
`field` line. A builtin, which the compiler defines rather than a module,
|
||||
shows its type and its doc from the prelude's docs. A local name shows
|
||||
its binding as written, a typed parameter with its type, and what binds
|
||||
it.
|
||||
it. A hover also shows the types the compiler inferred (see "Inferred
|
||||
types").
|
||||
- Completion (`textDocument/completion`): the local names in scope, then
|
||||
the top-level names of the file and of every module it sees, the
|
||||
builtins, and the special forms, each name once and the nearest first. An
|
||||
|
|
@ -49,6 +50,34 @@ reader: no macro is expanded and nothing is type checked, so they answer on
|
|||
every request. A form being typed is read as if it were closed; text that
|
||||
does not read even so leaves the last outline in place.
|
||||
|
||||
## Inferred types
|
||||
|
||||
A check keeps what the compiler inferred: the compiler hands each program it
|
||||
type checked to `Inference.observe`, and `Types.fs` reads the names in it
|
||||
with their types. A hover then shows
|
||||
|
||||
- for a local name, `(: name type)` above its binding: a parameter written
|
||||
without a type, a `let` binding, a `fun`'s parameter, a pattern's
|
||||
variable, a loop variable, a local `defun`;
|
||||
- for a use of a generic function, the type it has there, under "At this
|
||||
use": `list-map` at the types of the list it is given.
|
||||
|
||||
The types are those of the last check. A hover runs a check that is due
|
||||
first, so that they are of the text as it stands. A declaration that does
|
||||
not check has no types until it does; the others keep theirs.
|
||||
|
||||
Inlay hints (`textDocument/inlayHint`) show the same types in the text,
|
||||
after each local name where it is bound, where no type is written:
|
||||
`(let ((n: int (length xs))) ...)`. A top-level function's parameters have
|
||||
none, as its signature above it says their types. A long type is cut short,
|
||||
and its tooltip is the whole of it.
|
||||
|
||||
An editor asks for hints as the text changes, before the check of the
|
||||
change has run. The hints before the first change since the last check are
|
||||
where they were and are sent; the ones after it wait for the check. When it
|
||||
has run, the server asks the editor to ask again
|
||||
(`workspace/inlayHint/refresh`), if the editor says it can be asked.
|
||||
|
||||
Local names are the ones the parser's own forms bind: parameters of a
|
||||
`defun`, `fun` and the other `def…` heads, `let`, `let*`, `letrec`,
|
||||
`let/mono`, named `let` and `with-open` bindings, `with-return`, `match`
|
||||
|
|
@ -119,6 +148,12 @@ would:
|
|||
(add-hook 'bjo-mode-hook #'lsp)
|
||||
```
|
||||
|
||||
lsp-mode shows inlay hints only when asked to:
|
||||
|
||||
```elisp
|
||||
(setq lsp-inlay-hint-enable t)
|
||||
```
|
||||
|
||||
`emacs/bjolang-dape.el` debugs a program with `dape` and
|
||||
[netcoredbg](https://github.com/Samsung/netcoredbg/releases):
|
||||
|
||||
|
|
@ -157,8 +192,8 @@ With eglot instead:
|
|||
location in the message.
|
||||
- Hover for a special form (`record-ref`, `loop`, `match`), which has no
|
||||
definition to find and no doc.
|
||||
- Types that are inferred rather than written. A hover shows the
|
||||
declaration if there is one, and nothing about a name without it.
|
||||
- The type of an expression that is not a name, and of a local `defun`'s
|
||||
name where it is defined, which is not seen as a local there.
|
||||
- Completion of record fields after `record-ref`, of module paths in an
|
||||
`import`, or of keyword arguments. A string that began on an earlier line
|
||||
is not seen as one, so a multi-line string gets completions.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue