Modules are known by their file: import button from ui/menu.fch and import ui/button are one module, two util.fch are two; min/max/abs/clamp win over C's int-only abs; completion after an import's other name; hover docs; engineers' guides

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GzNP6r8dg6WDxUVZy8wjL
This commit is contained in:
Nexoniarz 2026-10-29 09:52:04 +01:00
commit 3ba2dcd5d6
16 changed files with 152 additions and 18 deletions

View file

@ -186,6 +186,19 @@ c.notify("textDocument/didChange", {"textDocument": {"uri": uri2, "version": 4},
diags = c.diagnostics(uri2)
check("error: unhandled failure", diags and "can fail" in diags[0]["message"], diags)
# a module imported under another name: completion after its name
src3 = "import path as pt\n\nfn main() {\n print(pt.base(\"a/b\"))\n}\n"
path3 = os.path.join(d, "alias.fch")
open(path3, "w").write(src3)
uri3 = pathlib.Path(path3).resolve().as_uri()
c.notify("textDocument/didOpen", {"textDocument": {"uri": uri3, "languageId": "finch", "version": 1, "text": src3}})
check("import as: compiles", c.diagnostics(uri3) == [])
e3 = src3.replace(" print(", " pt.\n print(")
c.notify("textDocument/didChange", {"textDocument": {"uri": uri3, "version": 2}, "contentChanges": [{"text": e3}]})
comp = c.request("textDocument/completion", {"textDocument": {"uri": uri3}, "position": {"line": 3, "character": 7}})
labels = [i["label"] for i in comp["items"]]
check("completion: a module under another name", "base" in labels and "join" in labels, labels)
c.request("shutdown", None)
c.notify("exit", None)
c.p.wait(timeout=5)

View file

@ -1,5 +1,6 @@
// C unions (SDL_Event-style) and #defines that are expressions, strings or casts
import "cunion.h"
import "stdlib.h"
link "cunion.c"
fn main() {
@ -22,4 +23,5 @@ fn main() {
Tagged t
t.as.f = 0.5
print(t.as.f)
print(abs(-2.5), abs(-3), min(EV_KEY, 7)) // Finch's abs, not C's int-only one
}

View file

@ -4,3 +4,4 @@ motion 1.5 -2
true 32
32 2
0.5
2.5 3 7

View file

@ -0,0 +1,10 @@
// a module is its file: ui/menu's "import button" is this file's "import ui/button",
// and ui/util.fch and util.fch are two different modules
import ui/button
import ui/menu
import util
fn main() {
button.Button b = menu.first()
print(b.label, b.w, menu.whoami(), util.who())
}

View file

@ -0,0 +1 @@
menu 30 ui/util util

11
tests/new/ui/menu.fch Normal file
View file

@ -0,0 +1,11 @@
// for tests/new/modules_by_file.fch: its sibling, imported without the folder
import button
import util
fn first() -> button.Button {
return button.make("menu")
}
fn whoami() -> str {
return util.who()
}

4
tests/new/ui/util.fch Normal file
View file

@ -0,0 +1,4 @@
// for tests/new/modules_by_file.fch: a util.fch in a folder
fn who() -> str {
return "ui/util"
}

4
tests/new/util.fch Normal file
View file

@ -0,0 +1,4 @@
// for tests/new/modules_by_file.fch: the top-level util.fch
fn who() -> str {
return "util"
}