Checks run on a thread of their own
A check held up every request, because the compiler could run one compilation at a time. It can now run each in a context of its own. - A check runs on a checking thread, in Compilation.inNew. The thread reports a check to the thread that serves requests, which writes to the client. - The outline, definitions, references, completion, signature help and formatting are answered while a check runs. - A hover, a code action and bjolang/expandMacro are answered when the check of their file ends, with the results of the text as it stands. Other requests are served meanwhile. - A file that changes again before its check starts is checked once. - The tables that a check writes are concurrent dictionaries. - Standard output is the protocol's; the console's output goes to standard error. - smoke: with a check of 1.6 s running, an outline is answered in 0.1 s. Needs the compiler at its commit "Diagnostics.captured collects the output of its own context". Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
c5acafd5dd
commit
5e4ac7d9aa
6 changed files with 273 additions and 49 deletions
|
|
@ -1091,6 +1091,70 @@ def formatting(server, tmp):
|
|||
expect("formatting: a text that does not read is refused, with why", "never closed" in answer.get("error", {}).get("message", ""), answer)
|
||||
|
||||
|
||||
def slow_text(probe):
|
||||
"""A file whose check takes a second or more: many small functions. The
|
||||
last one binds `probe` to a local, for a hover of its type."""
|
||||
parts = ["(import (std prelude))\n"]
|
||||
for i in range(2500):
|
||||
parts.append(f"(: (-> int int))\n(defun (f{i} n) (if (> n {i}) (+ n {i}) (* n 2)))\n")
|
||||
parts.append(f"(defun (main)\n (let ((probed {probe}))\n (ignore probed)\n 0))\n")
|
||||
return "\n".join(parts)
|
||||
|
||||
|
||||
def responding(server, tmp):
|
||||
"""A check runs on a thread of its own: a request that does not need it
|
||||
is answered while it runs, and one that does is answered when it ends."""
|
||||
import time
|
||||
path = os.path.join(tmp, "slow.bjo")
|
||||
uri = "file://" + path
|
||||
first = slow_text("1")
|
||||
with open(path, "w") as f:
|
||||
f.write(first)
|
||||
started = time.time()
|
||||
found = server.diagnostics_after("textDocument/didOpen", uri, first)
|
||||
check_time = time.time() - started
|
||||
errors = [d for d in found if d["severity"] == 1]
|
||||
expect("responding: the slow file checks", errors == [], json.dumps(errors[:2], indent=1))
|
||||
print(f" the check takes {check_time:.2f} s")
|
||||
expect("responding: the file is slow enough for the test to mean something", check_time > 0.5, f"{check_time:.2f} s")
|
||||
|
||||
# A change, and the check of it starts after the pause. While it runs:
|
||||
second = slow_text('"text"')
|
||||
server.published(uri)
|
||||
server.change(uri, second, 2)
|
||||
time.sleep(0.55)
|
||||
started = time.time()
|
||||
symbols = server.send("textDocument/documentSymbol", {"textDocument": {"uri": uri}}, request=True)["result"]
|
||||
symbol_time = time.time() - started
|
||||
before_answer = server.published(uri)
|
||||
expect("responding: the outline is answered while the check runs", len(symbols) > 2500 and before_answer == [],
|
||||
f"{len(symbols)} symbols, {len(before_answer)} diagnostics before the answer")
|
||||
expect("responding: and much sooner than a check takes", symbol_time < check_time / 2, f"{symbol_time:.2f} s against {check_time:.2f} s")
|
||||
print(f" the outline takes {symbol_time:.2f} s")
|
||||
|
||||
started = time.time()
|
||||
at = position_of(second, "(probed ", 0, 2)
|
||||
items = server.send("textDocument/completion", {"textDocument": {"uri": uri}, "position": at}, request=True)["result"]
|
||||
expect("responding: so is a completion", items is not None and server.published(uri) == [], "")
|
||||
|
||||
# A hover needs the check's types. It is asked while the check runs, and
|
||||
# answered when the check ends, with the types of the new text.
|
||||
at = position_of(second, "(ignore probed)", 0, 9)
|
||||
h = server.send("textDocument/hover", {"textDocument": {"uri": uri}, "position": at}, request=True)["result"]
|
||||
value = h["contents"]["value"] if h else ""
|
||||
expect("responding: a hover waits for the check, and has the new text's type", "(: probed string)" in value, value[:300])
|
||||
after = server.next_diagnostics(uri)
|
||||
expect("responding: the check of the change is published", [d for d in after if d["severity"] == 1] == [], after[:2])
|
||||
|
||||
# A hover asked before the pause is over starts the check at once.
|
||||
third = slow_text("2.5")
|
||||
server.change(uri, third, 3)
|
||||
h = server.send("textDocument/hover", {"textDocument": {"uri": uri}, "position": at}, request=True)["result"]
|
||||
value = h["contents"]["value"] if h else ""
|
||||
expect("responding: a hover of text not yet checked is of that text", "(: probed double)" in value, value[:300])
|
||||
server.diagnostics_after("textDocument/didClose", uri)
|
||||
|
||||
|
||||
def fields(server, tmp):
|
||||
path = os.path.join(tmp, "fields.bjo")
|
||||
uri = "file://" + path
|
||||
|
|
@ -1764,6 +1828,7 @@ with tempfile.TemporaryDirectory() as tmp:
|
|||
ranges(server, tmp)
|
||||
helping(server, tmp)
|
||||
formatting(server, tmp)
|
||||
responding(server, tmp)
|
||||
renaming(server, tmp)
|
||||
referencing(server, tmp)
|
||||
acting(server, tmp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue