From a17a9c434261d932cdf0aba1917789a4da241714 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Mon, 9 Feb 2026 10:36:59 -0800 Subject: [PATCH] fix pipe issue in REPL, add ability to dump top in repl --- playground/src/emul.ts | 3 +++ playground/src/main.ts | 1 + src/Lib/ReplParser.newt | 2 ++ src/Main.newt | 3 +++ src/Prelude.newt | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/playground/src/emul.ts b/playground/src/emul.ts index 5879b6a..52f89ba 100644 --- a/playground/src/emul.ts +++ b/playground/src/emul.ts @@ -47,6 +47,9 @@ export let shim: NodeShim = { writeFileSync(name: string, data: string, enc?: string) { shim.files[name] = new TextEncoder().encode(data) }, + writeSync(fd: number, data: string) { + shim.stdout += data; + } }, process: { argv: ["", ""], diff --git a/playground/src/main.ts b/playground/src/main.ts index d0fa026..1a1bea9 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -484,6 +484,7 @@ const processOutput = ( let endLineNumber = +eline; let endColumn = +ecol // FIXME - pass the real path in + if (file.startsWith("./")) file = file.slice(2); if (fn && fn !== file) { startLineNumber = startColumn = 0; } diff --git a/src/Lib/ReplParser.newt b/src/Lib/ReplParser.newt index 5ac3fab..a07f63b 100644 --- a/src/Lib/ReplParser.newt +++ b/src/Lib/ReplParser.newt @@ -14,6 +14,7 @@ data ReplCommand | GetDoc String | BrowseCmd QName | HelpCmd + | DumpTop kw : String → Parser String kw s = satisfy (\t => t.val.text == s) "Expected \{show s}" @@ -61,6 +62,7 @@ commands :: MkCmd ":d" "document function" ArgIdent GetDoc :: MkCmd ":doc" "document function" ArgIdent GetDoc :: MkCmd ":b" "browse namespace" ArgQName BrowseCmd + :: MkCmd ":top" "dump top context as json" ArgNone DumpTop -- type at point -- solve hole -- search by prefix (for autocomplete - ideally include types at point, but we'd need recovery) diff --git a/src/Main.newt b/src/Main.newt index 116f3fb..42b1d4d 100644 --- a/src/Main.newt +++ b/src/Main.newt @@ -304,6 +304,9 @@ runCommand (GetDoc name) = getDoc name runCommand (Verbose Nothing) = modifyTop [ verbose $= _+_ 1 ] runCommand (Verbose (Just v)) = modifyTop [ verbose := v ] runCommand (OutputJS fn) = writeSource fn +runCommand DumpTop = do + json <- jsonTopContext + putStrLn "TOP:\{renderJson json}" -- Broken out to a separate function so I can hook it. runString : String → M Unit diff --git a/src/Prelude.newt b/src/Prelude.newt index 3a5d37e..a287e3d 100644 --- a/src/Prelude.newt +++ b/src/Prelude.newt @@ -389,7 +389,7 @@ instance HasIO IO where liftIO a = a pfunc primPutStrLn uses (MkIORes MkUnit) : String → IO Unit := `(s) => (w) => { - console.log(s) + require('fs').writeSync(1, s + '\n') return Prelude_MkIORes(Prelude_MkUnit,w) }`