Compare commits

..

4 Commits

Author SHA1 Message Date
697c5f2641 fix updating of javascript/scheme in playground
Some checks failed
Publish Playground / build (push) Has been cancelled
Publish Playground / deploy (push) Has been cancelled
2026-03-28 09:36:05 -07:00
babbd01975 Fix LSP crash and tokenizer issue 2026-03-27 20:21:57 -07:00
c014233987 debug lsp crashes 2026-03-27 20:20:08 -07:00
aa6604038b cleanup 2026-03-27 20:19:27 -07:00
11 changed files with 40 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
let serverOptions: ServerOptions let serverOptions: ServerOptions
if (cmd) { if (cmd) {
serverOptions = { serverOptions = {
run: { command: "node", args: [cmd], transport: TransportKind.pipe }, run: { command: "node", args: ['--heapsnapshot-signal=SIGUSR2',cmd], transport: TransportKind.pipe },
debug: { command: "node", args: [cmd], transport: TransportKind.pipe }, debug: { command: "node", args: [cmd], transport: TransportKind.pipe },
} }
} else { } else {

View File

@@ -16,6 +16,8 @@ import {
Location, Location,
TextDocumentIdentifier, TextDocumentIdentifier,
} from "vscode-languageserver/node"; } from "vscode-languageserver/node";
import fs from 'node:fs';
import path from 'node:path';
import { TextDocument } from "vscode-languageserver-textdocument"; import { TextDocument } from "vscode-languageserver-textdocument";
const connection = createConnection(ProposedFeatures.all); const connection = createConnection(ProposedFeatures.all);
@@ -70,16 +72,18 @@ async function runChange() {
console.log('STALE result not sent for', uri) console.log('STALE result not sent for', uri)
} }
} }
} catch (e) {
console.error(e);
} finally { } finally {
running = false; running = false;
} }
} }
documents.onDidChangeContent(async (change) => { documents.onDidChangeContent(async (change) => {
console.log('DIDCHANGE', change.document.uri) console.log('DIDCHANGE', change.document.uri)
const uri = change.document.uri; const uri = change.document.uri;
const text = change.document.getText(); const text = change.document.getText();
// update/invalidate happens now, check happens on quiesce. // update/invalidate happens now, check happens on quiesce.
writeCache(path.basename(uri), text);
LSP_updateFile(uri, text); LSP_updateFile(uri, text);
addChange(change.document); addChange(change.document);
}); });
@@ -138,6 +142,21 @@ connection.onInitialize((_params: InitializeParams): InitializeResult => ({
}, },
})); }));
function writeCache(fn: string, content: string) {
const home = process.env.HOME;
if (!home) return;
const dname = path.join(home, '.cache/newt-lsp');
const fname = path.join(dname, fn);
try {
fs.mkdirSync(dname, {recursive: true});
} catch (e) {
}
try {
fs.writeFileSync(fname, content, 'utf8');
} catch (e) {
console.error(e);
}
}
documents.listen(connection); documents.listen(connection);
connection.listen(); connection.listen();
console.log('STARTED') console.log('STARTED')

View File

@@ -283,11 +283,8 @@ const language: EditorDelegate = {
}); });
} }
setOutput(res.output) setOutput(res.output)
// less flashy version state.javascript.value = ""
if (state.selected.value === JAVASCRIPT) state.scheme.value = ""
ipc.sendMessage("compile", [fileName, "javascript"]).then(js => state.javascript.value = bundle(js));
if (state.selected.value === SCHEME)
ipc.sendMessage("compile", [fileName, "scheme"]).then(scheme=> state.scheme.value = scheme);
return diags; return diags;
} catch (e) { } catch (e) {
console.log("ERR", e); console.log("ERR", e);

View File

@@ -300,7 +300,7 @@ termToJS {e} env (CCase t alts) f =
termToJSAlt : JSEnv -> JSExp -> CAlt -> JAlt termToJSAlt : JSEnv -> JSExp -> CAlt -> JAlt
termToJSAlt env nm (CConAlt ix name info args qs u) = JConAlt ix (termToJS (conAltEnv nm 0 env args) u f) termToJSAlt env nm (CConAlt ix name info args qs u) = JConAlt ix (termToJS (conAltEnv nm 0 env args) u f)
-- intentionally reusing scrutinee name here -- intentionally reusing scrutinee name here
termToJSAlt env nm (CDefAlt u) = JDefAlt (termToJS (env) u f) termToJSAlt env nm (CDefAlt u) = JDefAlt (termToJS (env) u f)
termToJSAlt env nm (CLitAlt lit u) = JLitAlt (litToJS lit) (termToJS env u f) termToJSAlt env nm (CLitAlt lit u) = JLitAlt (litToJS lit) (termToJS env u f)
getArgs : CAlt List String getArgs : CAlt List String

View File

@@ -96,7 +96,7 @@ erase env t sp = case t of
eraseSpine env (LetRec fc nm ty u' v') sp Nothing eraseSpine env (LetRec fc nm ty u' v') sp Nothing
(Bnd fc k) => do (Bnd fc k) => do
case getAt (cast k) env of case getAt (cast k) env of
Nothing => error fc "bad index \{show k}" Nothing => error fc "Erase: bad index \{show k}"
Just (nm, Zero, ty) => error fc "used erased value \{show nm} (FIXME FC may be wrong here)" Just (nm, Zero, ty) => error fc "used erased value \{show nm} (FIXME FC may be wrong here)"
Just (nm, Many, ty) => eraseSpine env t sp ty Just (nm, Many, ty) => eraseSpine env t sp ty
(UU fc) => eraseSpine env t sp (Just $ UU fc) (UU fc) => eraseSpine env t sp (Just $ UU fc)

View File

@@ -12,7 +12,7 @@ import Data.SortedMap
eval : Env -> Tm -> M Val eval : Env -> Tm -> M Val
-- REVIEW everything is evalutated whether it's needed or not -- REVIEW everything is evaluated whether it's needed or not
-- It would be nice if the environment were lazy. -- It would be nice if the environment were lazy.
-- e.g. case is getting evaluated when passed to a function because -- e.g. case is getting evaluated when passed to a function because
-- of dependencies in pi-types, even if the dependency isn't used -- of dependencies in pi-types, even if the dependency isn't used
@@ -50,7 +50,7 @@ unlet : Env -> Val -> M Val
unlet env t@(VVar fc k sp) = case lookupVar env k of unlet env t@(VVar fc k sp) = case lookupVar env k of
Just tt@(VVar fc' k' sp') => do Just tt@(VVar fc' k' sp') => do
debug $ \ _ => "lookup \{show k} is \{show tt}" debug $ \ _ => "lookup \{show k} is \{show tt}"
if k' == k then pure t else (vappSpine (VVar fc' k' sp') sp >>= unlet env) if k' == k then pure t else (vappSpine tt sp >>= unlet env)
Just t => vappSpine t sp >>= unlet env Just t => vappSpine t sp >>= unlet env
Nothing => do Nothing => do
debug $ \ _ => "lookup \{show k} is Nothing in env \{show env}" debug $ \ _ => "lookup \{show k} is Nothing in env \{show env}"

View File

@@ -310,7 +310,6 @@ processInstance ns instfc ty decls = do
vdcty@(VPi _ nm icit rig a b) <- eval Nil dcty vdcty@(VPi _ nm icit rig a b) <- eval Nil dcty
| x => error (getFC x) "dcty not Pi" | x => error (getFC x) "dcty not Pi"
debug $ \ _ => "dcty \{render 90 $ pprint Nil dcty}" debug $ \ _ => "dcty \{render 90 $ pprint Nil dcty}"
let (_,args) = funArgs codomain
debug $ \ _ => "traverse \{show $ map show args}" debug $ \ _ => "traverse \{show $ map show args}"
-- This is a little painful because we're reverse engineering the -- This is a little painful because we're reverse engineering the

View File

@@ -165,7 +165,8 @@ rawTokenise ts@(TS sl sc toks chars) = case chars of
doChar : Char -> List Char -> Either Error TState doChar : Char -> List Char -> Either Error TState
doChar c cs = if elem c standalone doChar c cs = if elem c standalone
then rawTokenise (TS sl (sc + 1) (toks :< mktok True sl (sc + 1) Symbol (pack $ c :: Nil)) cs) then rawTokenise (TS sl (sc + 1) (toks :< mktok True sl (sc + 1) Symbol (pack $ c :: Nil)) cs)
else let kind = if isDigit c then Number else if isUpper c then UIdent else Ident in else if isDigit c then doRest (TS sl sc toks (c :: cs)) Number isDigit Lin
else let kind = if isUpper c then UIdent else Ident in
doRest (TS sl sc toks (c :: cs)) kind isIdent Lin doRest (TS sl sc toks (c :: cs)) kind isIdent Lin

View File

@@ -456,8 +456,7 @@ debugLog a = putStrLn (debugStr a)
pfunc stringToInt : String Int := `(s) => { pfunc stringToInt : String Int := `(s) => {
let rval = Number(s) let rval = Number(s)
if (isNaN(rval)) throw new Error(s + " is NaN") return isNaN(rval) ? 0 : rval
return rval
}` }`
class Foldable (m : U U) where class Foldable (m : U U) where

9
tests/Number.newt Normal file
View File

@@ -0,0 +1,9 @@
module Number
import Prelude
add : Int Int Int
add a b = a + b
main : IO Unit
main = printLn $ add 2$ 40

1
tests/Number.newt.golden Normal file
View File

@@ -0,0 +1 @@
42