-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,029 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "aqua-ls" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
compiler = { path = "../compiler" } | ||
|
||
lsp-server = "0.7.6" | ||
lsp-types = "0.95.0" | ||
serde_json = "1.0.113" | ||
serde = { version = "1.0.113", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use std::error::Error; | ||
|
||
use lsp_types::request::GotoDefinition; | ||
use lsp_types::DiagnosticOptions; | ||
use lsp_types::DiagnosticServerCapabilities; | ||
use lsp_types::GotoDefinitionResponse; | ||
use lsp_types::InitializeParams; | ||
use lsp_types::ServerCapabilities; | ||
|
||
use lsp_server::Connection; | ||
use lsp_server::ExtractError; | ||
use lsp_server::Message; | ||
use lsp_server::Request; | ||
use lsp_server::RequestId; | ||
use lsp_server::Response; | ||
|
||
fn main() -> Result<(), Box<dyn Error + Sync + Send>> { | ||
let (connection, io_threads) = Connection::stdio(); | ||
let server_capabilities = serde_json::to_value(ServerCapabilities { | ||
diagnostic_provider: Some(DiagnosticServerCapabilities::Options(DiagnosticOptions { | ||
identifier: None, | ||
inter_file_dependencies: true, | ||
workspace_diagnostics: false, | ||
work_done_progress_options: lsp_types::WorkDoneProgressOptions { | ||
work_done_progress: None, | ||
}, | ||
})), | ||
..ServerCapabilities::default() | ||
}) | ||
.unwrap(); | ||
let initialization_params = match connection.initialize(server_capabilities) { | ||
Ok(it) => it, | ||
Err(e) => { | ||
if e.channel_is_disconnected() { | ||
io_threads.join()?; | ||
} | ||
return Err(e.into()); | ||
} | ||
}; | ||
main_loop(connection, initialization_params)?; | ||
io_threads.join()?; | ||
Ok(()) | ||
} | ||
|
||
fn main_loop( | ||
connection: Connection, | ||
params: serde_json::Value, | ||
) -> Result<(), Box<dyn Error + Sync + Send>> { | ||
let _params: InitializeParams = serde_json::from_value(params).unwrap(); | ||
for msg in &connection.receiver { | ||
match msg { | ||
Message::Request(req) => { | ||
if connection.handle_shutdown(&req)? { | ||
return Ok(()); | ||
} | ||
match cast::<GotoDefinition>(req) { | ||
Ok((id, params)) => { | ||
eprintln!("got gotoDefinition request #{id}: {params:?}"); | ||
let result = Some(GotoDefinitionResponse::Array(Vec::new())); | ||
let result = serde_json::to_value(&result).unwrap(); | ||
let resp = Response { | ||
id, | ||
result: Some(result), | ||
error: None, | ||
}; | ||
connection.sender.send(Message::Response(resp))?; | ||
continue; | ||
} | ||
Err(err @ ExtractError::JsonError { .. }) => panic!("{err:?}"), | ||
Err(ExtractError::MethodMismatch(req)) => req, | ||
}; | ||
// ... | ||
} | ||
Message::Response(resp) => { | ||
eprintln!("got response: {resp:?}"); | ||
} | ||
Message::Notification(not) => { | ||
eprintln!("got notification: {not:?}"); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn cast<R>(req: Request) -> Result<(RequestId, R::Params), ExtractError<Request>> | ||
where | ||
R: lsp_types::request::Request, | ||
R::Params: serde::de::DeserializeOwned, | ||
{ | ||
req.extract(R::METHOD) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.