Diagnostics at the compiler's ranges, and a link to one in another file
- A diagnostic is marked from where the compiler's range of it starts to where it ends (Diagnostics.rangeOf, in the compiler). A quoted list, an array literal and an interpolated string were marked as one character. A location with no range behind it is read from the message, as before. - A diagnostic in an included or an imported file has its place there as related information. - The README and the smoke test name bin/Release/net11.0, where the build is since the compiler's target changed. - smoke: the prelude's definitions are in prelude/core.bjo. Needs the compiler at its commit "Diagnostics.rangeOf". Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
ceb6f1b93a
commit
d421ec9363
4 changed files with 175 additions and 32 deletions
|
|
@ -13,7 +13,7 @@ import sys
|
|||
import tempfile
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SERVER = os.path.join(ROOT, "bin", "Release", "net10.0", "BjolangLsp.dll")
|
||||
SERVER = os.path.join(ROOT, "bin", "Release", "net11.0", "BjolangLsp.dll")
|
||||
|
||||
|
||||
def frame(message):
|
||||
|
|
@ -219,7 +219,8 @@ def symbols_and_definitions(server, tmp):
|
|||
d,
|
||||
)
|
||||
d = definition(SYMBOLS, "(list-map")
|
||||
expect("a name from the prelude", d and d["uri"].endswith("/lib/std/prelude.bjo"), d)
|
||||
# The prelude's definitions are in (std prelude core), which it re-exports.
|
||||
expect("a name from the prelude", d and d["uri"].endswith("/lib/std/prelude/core.bjo"), d)
|
||||
# `n` is a parameter: it goes to where the parameter is written.
|
||||
d = definition(SYMBOLS, "(* 2 n)", 5)
|
||||
expect(
|
||||
|
|
@ -879,6 +880,97 @@ FIELDS = """(type (: Leg (Record (: distance double) (: name string))))
|
|||
"""
|
||||
|
||||
|
||||
# Each function has one mistake, at a form that the text alone does not show
|
||||
# the end of.
|
||||
RANGES = """(import (std prelude))
|
||||
|
||||
(: (-> int int))
|
||||
(defun (takes-int n) n)
|
||||
|
||||
(: (-> int))
|
||||
(defun (quoted)
|
||||
(takes-int '(1 2)))
|
||||
|
||||
(: (-> int))
|
||||
(defun (array)
|
||||
(takes-int #[1 2 3]))
|
||||
|
||||
(: (-> int))
|
||||
(defun (interpolated)
|
||||
(takes-int #"a ${(int->string 1)} b"))
|
||||
|
||||
(: (-> (Option int) int))
|
||||
(defun (pattern o)
|
||||
(match o
|
||||
((Some "x") 1)
|
||||
(_ 0)))
|
||||
|
||||
(: (-> int string))
|
||||
(defun (returned n)
|
||||
(println "working")
|
||||
(+ n 1))
|
||||
|
||||
(defun (main) 0)
|
||||
"""
|
||||
|
||||
INCLUDED = """(: (-> int string))
|
||||
(defun (from-include n)
|
||||
(+ n 1))
|
||||
"""
|
||||
|
||||
INCLUDES = """(import (std prelude))
|
||||
(include "ranges-included.bjo")
|
||||
|
||||
(defun (main) (println (from-include 1)) 0)
|
||||
"""
|
||||
|
||||
|
||||
def ranges(server, tmp):
|
||||
"""A diagnostic is marked from where the compiler's range starts to where
|
||||
it ends, and one in another file names the place there."""
|
||||
path = os.path.join(tmp, "ranges.bjo")
|
||||
uri = "file://" + path
|
||||
with open(path, "w") as f:
|
||||
f.write(RANGES)
|
||||
found = server.diagnostics_after("textDocument/didOpen", uri, RANGES)
|
||||
errors = [d for d in found if d["severity"] == 1]
|
||||
|
||||
def marked(needle, length=None):
|
||||
at = position_of(RANGES, needle, 0, 0)
|
||||
end = {"line": at["line"], "character": at["character"] + (length or len(needle))}
|
||||
return any(d["range"]["start"] == at and d["range"]["end"] == end for d in errors)
|
||||
|
||||
detail = json.dumps([d["range"] for d in errors])
|
||||
expect("ranges: a quoted list is marked whole", marked("'(1 2)"), detail)
|
||||
expect("ranges: an array literal is marked whole", marked("#[1 2 3]"), detail)
|
||||
expect("ranges: an interpolated string is marked whole", marked('#"a ${(int->string 1)} b"'), detail)
|
||||
expect("ranges: a pattern is marked, not its match", marked('"x"'), detail)
|
||||
expect("ranges: what a function returns is marked at its last form", marked("(+ n 1))", 7), detail)
|
||||
|
||||
included = os.path.join(tmp, "ranges-included.bjo")
|
||||
with open(included, "w") as f:
|
||||
f.write(INCLUDED)
|
||||
path = os.path.join(tmp, "ranges-includes.bjo")
|
||||
uri = "file://" + path
|
||||
with open(path, "w") as f:
|
||||
f.write(INCLUDES)
|
||||
found = server.diagnostics_after("textDocument/didOpen", uri, INCLUDES)
|
||||
errors = [d for d in found if d["severity"] == 1]
|
||||
related = [r for d in errors for r in d.get("relatedInformation", [])]
|
||||
detail = json.dumps(errors, indent=1)
|
||||
expect("ranges: an error of an included file is on the first line", any(d["range"]["start"]["line"] == 0 for d in errors), detail)
|
||||
expect(
|
||||
"ranges: and names the place in that file",
|
||||
any(
|
||||
r["location"]["uri"].endswith("/ranges-included.bjo")
|
||||
and r["location"]["range"]["start"] == {"line": 2, "character": 2}
|
||||
and r["location"]["range"]["end"] == {"line": 2, "character": 9}
|
||||
for r in related
|
||||
),
|
||||
detail,
|
||||
)
|
||||
|
||||
|
||||
def fields(server, tmp):
|
||||
path = os.path.join(tmp, "fields.bjo")
|
||||
uri = "file://" + path
|
||||
|
|
@ -1014,7 +1106,7 @@ def renaming(server, tmp):
|
|||
("a binding the new name would take a use from", "((n (helper", 2, "xs", "'xs' is bound at"),
|
||||
("a use of the new name the renamed binding would take", "((n (helper", 2, "count", "'count' is used at"),
|
||||
("an exported name", "(defun (area w", 8, "size", "is exported at"),
|
||||
("a name defined elsewhere", "(length xs)", 1, "len", "is defined in prelude.bjo"),
|
||||
("a name defined elsewhere", "(length xs)", 1, "len", "is defined in core.bjo"),
|
||||
("a keyword parameter", "(str greeting", 5, "hi", "keyword parameter"),
|
||||
("main", "(defun (main)", 8, "start", "entry point"),
|
||||
("a name of a definition the module sees", "(defun (helper x)", 8, "length", "is already defined"),
|
||||
|
|
@ -1482,6 +1574,7 @@ with tempfile.TemporaryDirectory() as tmp:
|
|||
declarations(server, tmp)
|
||||
inferred(server, tmp)
|
||||
fields(server, tmp)
|
||||
ranges(server, tmp)
|
||||
renaming(server, tmp)
|
||||
referencing(server, tmp)
|
||||
acting(server, tmp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue