Hover on fields, and on locals of record types
A field read shows the field's type and its declaration; a local of a record, struct or union type shows the type. Structs and opaque types get their symbols, and the file's own types drop their module qualifier.
This commit is contained in:
parent
29977ca301
commit
78d18c9854
6 changed files with 166 additions and 11 deletions
|
|
@ -691,6 +691,59 @@ def inferred(server, tmp):
|
|||
server.diagnostics_after("textDocument/didClose", uri)
|
||||
|
||||
|
||||
FIELDS = """(type (: Leg (Record (: distance double) (: name string))))
|
||||
(type (: Pos (Struct (: x int) (: y int))))
|
||||
|
||||
(:doc Leg
|
||||
(summary "A part of a trip.")
|
||||
(field distance "How far it goes.")
|
||||
(field name "Where it ends."))
|
||||
|
||||
(: far? (-> Leg bool))
|
||||
(defun (far? leg) (> (.distance leg) 10.0))
|
||||
|
||||
(: across (-> Pos int))
|
||||
(defun (across p) (+ (.x p) (.y p)))
|
||||
"""
|
||||
|
||||
|
||||
def fields(server, tmp):
|
||||
path = os.path.join(tmp, "fields.bjo")
|
||||
uri = "file://" + path
|
||||
with open(path, "w") as f:
|
||||
f.write(FIELDS)
|
||||
found = server.diagnostics_after("textDocument/didOpen", uri, FIELDS)
|
||||
errors = [d for d in found if d["severity"] == 1]
|
||||
expect("fields: the file checks", errors == [], json.dumps(errors, indent=1))
|
||||
|
||||
def hover(needle, offset=1):
|
||||
at = position_of(FIELDS, needle, 0, offset)
|
||||
h = server.send("textDocument/hover", {"textDocument": {"uri": uri}, "position": at}, request=True)["result"]
|
||||
return h and h["contents"]["value"]
|
||||
|
||||
h = hover("(.distance leg)", 2)
|
||||
expect(
|
||||
"fields hover: a record field's type, its declaration and its doc",
|
||||
h
|
||||
and "(: .distance double)" in h
|
||||
and "(: distance double)" in h
|
||||
and "How far it goes." in h
|
||||
and "A field of `Leg`" in h,
|
||||
h,
|
||||
)
|
||||
h = hover("(.y p)", 2)
|
||||
expect("fields hover: a struct's field", h and "(: .y int)" in h and "A field of `Pos`" in h, h)
|
||||
h = hover("leg) 10.0", 0)
|
||||
expect(
|
||||
"fields hover: a local of a record type shows the record",
|
||||
h and "(: leg Leg)" in h and "(: Leg (Record (: distance double) (: name string)))" in h and "A part of a trip." in h,
|
||||
h,
|
||||
)
|
||||
h = hover("p) (.y", 0)
|
||||
expect("fields hover: a local of a struct type shows the struct", h and "(: Pos (Struct" in h, h)
|
||||
server.diagnostics_after("textDocument/didClose", uri)
|
||||
|
||||
|
||||
RENAMING = """(export area)
|
||||
|
||||
(:doc helper
|
||||
|
|
@ -1254,6 +1307,7 @@ with tempfile.TemporaryDirectory() as tmp:
|
|||
completing(server, tmp)
|
||||
locals_(server, tmp)
|
||||
inferred(server, tmp)
|
||||
fields(server, tmp)
|
||||
renaming(server, tmp)
|
||||
referencing(server, tmp)
|
||||
acting(server, tmp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue