update dependencies
This commit is contained in:
parent
7339d61b1c
commit
e1e87f4dc1
2 changed files with 605 additions and 229 deletions
715
Cargo.lock
generated
715
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
83
src/main.rs
83
src/main.rs
|
@ -1,20 +1,17 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use anyhow::Error;
|
||||||
|
use lsp_server::{Connection, Message, Response};
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
DidChangeTextDocumentParams, Position,
|
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, InlayHint,
|
||||||
TextDocumentSyncCapability, TextDocumentSyncKind,
|
InlayHintParams, Position, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||||
InlayHint, InlayHintParams, DidOpenTextDocumentParams, DidCloseTextDocumentParams,
|
|
||||||
};
|
};
|
||||||
use lsp_types::{InitializeParams, ServerCapabilities};
|
use lsp_types::{InitializeParams, ServerCapabilities};
|
||||||
use lsp_server::{Connection, Message, Response};
|
|
||||||
use anyhow::Error;
|
|
||||||
use numbat::InterpreterResult;
|
|
||||||
use numbat::module_importer::BuiltinModuleImporter;
|
use numbat::module_importer::BuiltinModuleImporter;
|
||||||
use numbat::resolver::CodeSource;
|
use numbat::resolver::CodeSource;
|
||||||
|
use numbat::InterpreterResult;
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
eprintln!("starting generic LSP server");
|
|
||||||
|
|
||||||
let (connection, io_threads) = Connection::stdio();
|
let (connection, io_threads) = Connection::stdio();
|
||||||
|
|
||||||
let server_capabilities = serde_json::to_value(ServerCapabilities {
|
let server_capabilities = serde_json::to_value(ServerCapabilities {
|
||||||
|
@ -27,14 +24,10 @@ fn main() -> Result<(), Error> {
|
||||||
main_loop(connection, initialization_params)?;
|
main_loop(connection, initialization_params)?;
|
||||||
io_threads.join()?;
|
io_threads.join()?;
|
||||||
|
|
||||||
eprintln!("shutting down server");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_loop(
|
fn main_loop(connection: Connection, params: serde_json::Value) -> Result<(), Error> {
|
||||||
connection: Connection,
|
|
||||||
params: serde_json::Value,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let _params: InitializeParams = serde_json::from_value(params).unwrap();
|
let _params: InitializeParams = serde_json::from_value(params).unwrap();
|
||||||
|
|
||||||
let mut docs: HashMap<lsp_types::Url, Vec<String>> = HashMap::new();
|
let mut docs: HashMap<lsp_types::Url, Vec<String>> = HashMap::new();
|
||||||
|
@ -43,14 +36,17 @@ fn main_loop(
|
||||||
numbat::Context::new(importer)
|
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 {
|
for msg in &connection.receiver {
|
||||||
match msg {
|
match msg {
|
||||||
Message::Request(req) => {
|
Message::Request(req) => {
|
||||||
eprintln!("got request: {req:?}");
|
|
||||||
if connection.handle_shutdown(&req)? {
|
if connection.handle_shutdown(&req)? {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -67,18 +63,26 @@ fn main_loop(
|
||||||
continue;
|
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 {
|
let label = match result {
|
||||||
Ok((_, result)) => match result {
|
Ok((_, result)) => match result {
|
||||||
InterpreterResult::Value(value) => Some(format!("= {}", value)),
|
InterpreterResult::Value(value) => Some(format!("= {}", value)),
|
||||||
InterpreterResult::Continue => None,
|
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 {
|
if let Some(label) = label {
|
||||||
|
@ -100,8 +104,6 @@ fn main_loop(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("calculated hints: {hints:?}");
|
|
||||||
|
|
||||||
let hints = Response {
|
let hints = Response {
|
||||||
id: req.id,
|
id: req.id,
|
||||||
result: Some(serde_json::to_value(hints)?),
|
result: Some(serde_json::to_value(hints)?),
|
||||||
|
@ -111,28 +113,37 @@ fn main_loop(
|
||||||
connection.sender.send(Message::Response(hints))?;
|
connection.sender.send(Message::Response(hints))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Response(resp) => {
|
Message::Response(_) => {}
|
||||||
eprintln!("got response: {resp:?}");
|
Message::Notification(not) => match not.method.as_str() {
|
||||||
}
|
|
||||||
Message::Notification(not) => {
|
|
||||||
eprintln!("got notification: {not:?}");
|
|
||||||
|
|
||||||
match not.method.as_str() {
|
|
||||||
"textDocument/didChange" => {
|
"textDocument/didChange" => {
|
||||||
let params: DidChangeTextDocumentParams = serde_json::from_value(not.params)?;
|
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" => {
|
"textDocument/didOpen" => {
|
||||||
let params: DidOpenTextDocumentParams = serde_json::from_value(not.params)?;
|
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" => {
|
"textDocument/didClose" => {
|
||||||
let params: DidCloseTextDocumentParams = serde_json::from_value(not.params)?;
|
let params: DidCloseTextDocumentParams = serde_json::from_value(not.params)?;
|
||||||
docs.remove(¶ms.text_document.uri);
|
docs.remove(¶ms.text_document.uri);
|
||||||
}
|
}
|
||||||
_ => {},
|
_ => {}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue