early prototype of a language server

currently only provides hover info (but that's already quite useful for debugging)
This commit is contained in:
Mark
2023-12-05 23:04:17 +01:00
parent 8b60da8d99
commit 0759b769e0
42 changed files with 892 additions and 26 deletions

View File

@@ -112,7 +112,8 @@ impl Config {
}
}
unreachable!("try: no function found")
})
}),
inner_statements: None,
}))
.add_var("lock_update".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
@@ -160,7 +161,8 @@ impl Config {
let func = func.as_any().downcast_ref::<data::function::Function>().unwrap();
*arg = func.run(arg.clone());
Data::empty_tuple()
})
}),
inner_statements: None,
}))
.add_var("sleep".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
@@ -183,7 +185,8 @@ impl Config {
unreachable!("sleep called on non-int/non-float")
});
Data::empty_tuple()
})
}),
inner_statements: None,
}))
.add_var("panic".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
@@ -195,7 +198,8 @@ impl Config {
}),
run: Arc::new(|a, _i| {
std::process::exit(a.get().as_any().downcast_ref::<data::int::Int>().map(|i| i.0 as _).unwrap_or(1));
})
}),
inner_statements: None,
}))
.add_var(
"len".to_string(),
@@ -222,6 +226,7 @@ impl Config {
unreachable!("called len on {a:?}, which isn't a tuple or a string")
}))
}),
inner_statements: None,
}),
).add_var(
"loop".to_string(),
@@ -270,6 +275,7 @@ impl Config {
}
}
}),
inner_statements: None,
}),
)
.add_var(
@@ -303,6 +309,7 @@ impl Config {
false
}))
}),
inner_statements: None,
}),
)
.add_var(
@@ -323,6 +330,7 @@ impl Config {
unreachable!("called deref on non-reference")
}
}),
inner_statements: None,
}),
)
}

View File

@@ -76,6 +76,7 @@ impl Config {
unreachable!("run_command called with non-tuple argument")
}
}),
inner_statements: None,
}),
)
}

View File

@@ -66,6 +66,7 @@ impl Config {
unreachable!("get called with less than 2 args")
}
}),
inner_statements: None,
}),
)
}

View File

@@ -98,6 +98,7 @@ impl Config {
unreachable!("for_each called on non-tuple")
}
}),
inner_statements: None,
}),
)
.add_var(
@@ -133,6 +134,7 @@ impl Config {
Ok(Type::new(IterT::new(ItersT::Enumerate, data)?))
}),
run: Arc::new(|a, _i| Data::new(Iter(Iters::Enumerate, a.clone()))),
inner_statements: None,
}),
)
}
@@ -203,6 +205,7 @@ fn genfunc_iter_and_arg<T: MersType, D: MersData>(
unreachable!("{name} called on non-tuple")
}
}),
inner_statements: None,
}
}
@@ -408,5 +411,6 @@ fn genfunc_iter_in_val_out(
}
}),
run: Arc::new(run),
inner_statements: None,
}
}

View File

@@ -94,6 +94,7 @@ impl Config {
};
o
}),
inner_statements: None,
}))
.add_var(
"pop".to_string(),
@@ -140,6 +141,7 @@ impl Config {
None => Data::empty_tuple(),
}
}),
inner_statements: None,
}),
)
.add_var(
@@ -202,6 +204,7 @@ impl Config {
.push(Arc::new(RwLock::new(tuple.0[1].clone())));
Data::empty_tuple()
}),
inner_statements: None,
}),
)
.add_var(
@@ -225,6 +228,7 @@ impl Config {
unreachable!("as_list called on non-iterable")
}
}),
inner_statements: None,
}),
)
}

View File

@@ -75,7 +75,8 @@ impl Config {
} else {
Data::empty_tuple()
}
})
}),
inner_statements: None,
})).add_var("parse_int".to_string(), Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -95,7 +96,8 @@ impl Config {
} else {
Data::empty_tuple()
}
})
}),
inner_statements: None,
})).add_var("signum".to_string(), Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -118,7 +120,8 @@ impl Config {
} else { 0
}
} else { unreachable!("called signum on non-number type")}))
})
}),
inner_statements: None,
})) .add_var("div".to_string(), Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -137,6 +140,7 @@ impl Config {
_ => unreachable!(),
}
} else { unreachable!() }),
inner_statements: None,
})).add_var("modulo".to_string(), Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -155,6 +159,7 @@ impl Config {
_ => unreachable!(),
}
} else { unreachable!() }),
inner_statements: None,
}))
.add_var(
"sum".to_string(),
@@ -215,6 +220,7 @@ impl Config {
unreachable!("sum called on non-tuple")
}
}),
inner_statements: None,
}),
)
.add_var(
@@ -288,6 +294,7 @@ impl Config {
unreachable!("sum called on non-tuple")
}
}),
inner_statements: None,
}),
)
.add_var(
@@ -349,6 +356,7 @@ impl Config {
unreachable!("product called on non-tuple")
}
}),
inner_statements: None,
}),
)
}
@@ -428,6 +436,7 @@ fn ltgtoe_function(
}
Data::new(data::bool::Bool(true))
}),
inner_statements: None,
}
}
#[derive(Clone, Copy)]

View File

@@ -58,6 +58,7 @@ impl Config {
unreachable!("thread called, but arg wasn't a function");
}
}),
inner_statements: None,
}),
)
.add_var("thread_finished".to_string(), Data::new(data::function::Function {
@@ -78,7 +79,8 @@ impl Config {
Ok(t) => t.is_finished(),
Err(_d) => true,
}))
})
}),
inner_statements: None,
}))
.add_var("thread_await".to_string(), Data::new(data::function::Function {
info: Arc::new(program::run::Info::neverused()),
@@ -103,7 +105,8 @@ impl Config {
};
*t = Err(d.clone());
d
})
}),
inner_statements: None,
}))
}
}

View File

@@ -42,6 +42,7 @@ impl Config {
_ = std::io::stdin().read_line(&mut line);
Data::new(data::string::String(line))
}),
inner_statements: None,
}),
)
.add_var(
@@ -55,6 +56,7 @@ impl Config {
eprintln!("{} :: {}", a.as_type(), a);
Data::empty_tuple()
}),
inner_statements: None,
}),
)
.add_var(
@@ -68,6 +70,7 @@ impl Config {
_ = std::io::stderr().lock().flush();
Data::empty_tuple()
}),
inner_statements: None,
}),
)
.add_var(
@@ -80,6 +83,7 @@ impl Config {
eprintln!("{}", a.get());
Data::empty_tuple()
}),
inner_statements: None,
}),
)
.add_var(
@@ -93,6 +97,7 @@ impl Config {
_ = std::io::stdout().lock().flush();
Data::empty_tuple()
}),
inner_statements: None,
}),
)
.add_var(
@@ -105,6 +110,7 @@ impl Config {
println!("{}", a.get());
Data::empty_tuple()
}),
inner_statements: None,
}),
)
}

View File

@@ -25,7 +25,8 @@ impl Config {
}),
run: Arc::new(|a, _i| {
Data::new(data::string::String(a.get().as_any().downcast_ref::<data::string::String>().unwrap().0.trim().to_owned()))
})
}),
inner_statements: None,
})).add_var("concat".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -35,11 +36,13 @@ impl Config {
Err(format!("concat called on non-iterable type {a}").into())
}),
run: Arc::new(|a, _i| Data::new(data::string::String(a.get().iterable().unwrap().map(|v| v.get().to_string()).collect()))),
inner_statements: None,
})).add_var("to_string".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
out: Arc::new(|_a, _i| Ok(Type::new(data::string::StringT))),
run: Arc::new(|a, _i| Data::new(data::string::String(a.get().to_string()))),
inner_statements: None,
})).add_var("index_of".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -52,6 +55,7 @@ impl Config {
Err(format!("wrong args for index_of: must be (string, string)").into())
}),
run: Arc::new(|a, _i| index_of(a, false)),
inner_statements: None,
})).add_var("index_of_rev".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -64,6 +68,7 @@ impl Config {
Err(format!("wrong args for index_of: must be (string, string)").into())
}),
run: Arc::new(|a, _i| index_of(a, true)),
inner_statements: None,
})).add_var("substring".to_string(), Data::new(data::function::Function {
info: Arc::new(Info::neverused()),
info_check: Arc::new(Mutex::new(CheckInfo::neverused())),
@@ -113,6 +118,7 @@ impl Config {
Data::new(data::string::String(s[start..end].to_owned()))
}),
inner_statements: None,
}))
}
}