update dependencies

This commit is contained in:
tezlm 2024-04-21 18:28:13 -07:00
parent 7339d61b1c
commit e1e87f4dc1
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
2 changed files with 605 additions and 229 deletions

715
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,20 +1,17 @@
use std::collections::HashMap;
use anyhow::Error;
use lsp_server::{Connection, Message, Response};
use lsp_types::{
DidChangeTextDocumentParams, Position,
TextDocumentSyncCapability, TextDocumentSyncKind,
InlayHint, InlayHintParams, DidOpenTextDocumentParams, DidCloseTextDocumentParams,
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, InlayHint,
InlayHintParams, Position, TextDocumentSyncCapability, TextDocumentSyncKind,
};
use lsp_types::{InitializeParams, ServerCapabilities};
use lsp_server::{Connection, Message, Response};
use anyhow::Error;
use numbat::InterpreterResult;
use numbat::module_importer::BuiltinModuleImporter;
use numbat::resolver::CodeSource;
use numbat::InterpreterResult;
fn main() -> Result<(), Error> {
eprintln!("starting generic LSP server");
let (connection, io_threads) = Connection::stdio();
let server_capabilities = serde_json::to_value(ServerCapabilities {
@ -27,14 +24,10 @@ fn main() -> Result<(), Error> {
main_loop(connection, initialization_params)?;
io_threads.join()?;
eprintln!("shutting down server");
Ok(())
}
fn main_loop(
connection: Connection,
params: serde_json::Value,
) -> Result<(), Error> {
fn main_loop(connection: Connection, params: serde_json::Value) -> Result<(), Error> {
let _params: InitializeParams = serde_json::from_value(params).unwrap();
let mut docs: HashMap<lsp_types::Url, Vec<String>> = HashMap::new();
@ -43,14 +36,17 @@ fn main_loop(
numbat::Context::new(importer)
};
let mut settings = numbat::InterpreterSettings { print_fn: Box::new(|_| ()) };
let mut settings = numbat::InterpreterSettings {
print_fn: Box::new(|_| ()),
};
eprintln!("starting example main loop");
let _ = context
.interpret_with_settings(&mut settings, "use prelude", CodeSource::Text)
.expect("failed to import prelude");
for msg in &connection.receiver {
match msg {
Message::Request(req) => {
eprintln!("got request: {req:?}");
if connection.handle_shutdown(&req)? {
return Ok(());
}
@ -67,18 +63,26 @@ fn main_loop(
continue;
}
let result = context.interpret_with_settings(&mut settings, line, CodeSource::Text);
let result =
context.interpret_with_settings(&mut settings, line, CodeSource::Text);
let label = match result {
Ok((_, result)) => match result {
InterpreterResult::Value(value) => Some(format!("= {}", value)),
InterpreterResult::Continue => None,
InterpreterResult::Exit(_) => None,
},
Err(numbat::NumbatError::NameResolutionError(err)) => {
Some(format!("-> {}", err))
}
Err(numbat::NumbatError::ResolverError(err)) => {
Some(format!("-> {}", err))
}
Err(numbat::NumbatError::TypeCheckError(err)) => {
Some(format!("-> {}", err))
}
Err(numbat::NumbatError::RuntimeError(err)) => {
Some(format!("-> {}", err))
}
Err(numbat::NumbatError::NameResolutionError(err)) => Some(format!("-> {}", err)),
Err(numbat::NumbatError::ResolverError(err)) => Some(format!("-> {}", err)),
Err(numbat::NumbatError::TypeCheckError(err)) => Some(format!("-> {}", err)),
Err(numbat::NumbatError::RuntimeError(err)) => Some(format!("-> {}", err)),
};
if let Some(label) = label {
@ -100,8 +104,6 @@ fn main_loop(
}
}
eprintln!("calculated hints: {hints:?}");
let hints = Response {
id: req.id,
result: Some(serde_json::to_value(hints)?),
@ -111,28 +113,37 @@ fn main_loop(
connection.sender.send(Message::Response(hints))?;
}
}
Message::Response(resp) => {
eprintln!("got response: {resp:?}");
}
Message::Notification(not) => {
eprintln!("got notification: {not:?}");
match not.method.as_str() {
Message::Response(_) => {}
Message::Notification(not) => match not.method.as_str() {
"textDocument/didChange" => {
let params: DidChangeTextDocumentParams = serde_json::from_value(not.params)?;
docs.insert(params.text_document.uri, params.content_changes[0].text.split('\n').map(String::from).collect());
docs.insert(
params.text_document.uri,
params.content_changes[0]
.text
.split('\n')
.map(String::from)
.collect(),
);
}
"textDocument/didOpen" => {
let params: DidOpenTextDocumentParams = serde_json::from_value(not.params)?;
docs.insert(params.text_document.uri, params.text_document.text.split('\n').map(String::from).collect());
docs.insert(
params.text_document.uri,
params
.text_document
.text
.split('\n')
.map(String::from)
.collect(),
);
}
"textDocument/didClose" => {
let params: DidCloseTextDocumentParams = serde_json::from_value(not.params)?;
docs.remove(&params.text_document.uri);
}
_ => {},
}
}
_ => {}
},
}
}
Ok(())