From bcfcc5500bb01abbfe45ea53a0abbb74a81b1dea162dab32cbbb1b5551c71d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Bj=C3=B6rnstam?= Date: Thu, 22 Oct 2026 14:03:56 +0200 Subject: [PATCH] A name a body form defines is bound where it is written MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A def, a pattern def and a defun in a body made their names visible to the forms after them only, so at the name itself nothing bound it: no inlay hint, and no local hover. A position on such a name is now that name's binding. 🤖 Generated with [ECA](https://eca.dev) Co-Authored-By: eca-agent --- README.md | 3 +-- Scope.fs | 13 ++++++++++--- test/smoke.py | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 308f0c1..a24edce 100644 --- a/README.md +++ b/README.md @@ -192,8 +192,7 @@ 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. -- 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. +- The type of an expression that is not a name. - 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. diff --git a/Scope.fs b/Scope.fs index f5f2339..884f570 100644 --- a/Scope.fs +++ b/Scope.fs @@ -198,9 +198,16 @@ and private inBody (line: int) (column: int) (env: Binder list) (forms: SExpr li match forms with | [] -> env | form :: rest -> - match inForm line column env form with - | Some found -> found - | None -> go (env @ definedBy form) rest + let defined = definedBy form + + // On a name the form defines, that is where the name is bound. + // Anywhere else in the form, the name is not in scope yet. + match defined |> List.tryFind (fun b -> holds line column b.Range) with + | Some own -> env @ [ own ] + | None -> + match inForm line column env form with + | Some found -> found + | None -> go (env @ defined) rest go env forms diff --git a/test/smoke.py b/test/smoke.py index a312da4..c12c5cf 100755 --- a/test/smoke.py +++ b/test/smoke.py @@ -519,7 +519,8 @@ INFERRED = """(import (std prelude)) (: annotated (-> int int)) (defun (annotated k) (def (: m int) (+ k 1)) - m) + (def bumped (+ m 1)) + bumped) """ # One declaration that does not check, and one that does. @@ -582,6 +583,11 @@ def inferred(server, tmp): and labels.get("s") == ": string", found, ) + expect( + "inlay hints: a def and a defun in a body, at their names", + labels.get("bumped") == ": int" and labels.get("twice") == ": (-?-> string int)", + found, + ) expect( "inlay hints: none for a top-level function's parameters", "xs" not in labels and "names" not in labels and "k" not in labels,