2024-01-01 19:58:21 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-05-11 04:54:10 +00:00
|
|
|
|
2020-12-21 13:44:26 +00:00
|
|
|
use deno_core::error::AnyError;
|
2023-11-22 04:08:48 +00:00
|
|
|
use deno_core::unsync::spawn;
|
|
|
|
use tokio_util::sync::CancellationToken;
|
2022-04-03 04:17:30 +00:00
|
|
|
use tower_lsp::LspService;
|
|
|
|
use tower_lsp::Server;
|
2020-12-07 10:46:39 +00:00
|
|
|
|
2022-04-03 04:17:30 +00:00
|
|
|
use crate::lsp::language_server::LanguageServer;
|
2021-12-15 18:23:43 +00:00
|
|
|
pub use repl::ReplCompletionItem;
|
|
|
|
pub use repl::ReplLanguageServer;
|
|
|
|
|
2023-05-26 06:10:18 +00:00
|
|
|
use self::diagnostics::should_send_diagnostic_batch_index_notifications;
|
|
|
|
|
2020-12-07 10:46:39 +00:00
|
|
|
mod analysis;
|
2021-10-10 21:26:22 +00:00
|
|
|
mod cache;
|
2020-12-07 10:46:39 +00:00
|
|
|
mod capabilities;
|
2021-12-15 18:23:43 +00:00
|
|
|
mod client;
|
2021-06-04 21:31:44 +00:00
|
|
|
mod code_lens;
|
2021-03-25 00:13:37 +00:00
|
|
|
mod completions;
|
2020-12-07 10:46:39 +00:00
|
|
|
mod config;
|
|
|
|
mod diagnostics;
|
2021-01-22 10:03:16 +00:00
|
|
|
mod documents;
|
2024-03-01 21:34:13 +00:00
|
|
|
mod jsr;
|
2022-03-23 13:54:22 +00:00
|
|
|
pub mod language_server;
|
2021-12-15 18:23:43 +00:00
|
|
|
mod logging;
|
2021-06-01 11:53:08 +00:00
|
|
|
mod lsp_custom;
|
2023-08-29 15:22:05 +00:00
|
|
|
mod npm;
|
2021-06-17 23:57:58 +00:00
|
|
|
mod parent_process_checker;
|
2021-04-09 01:27:27 +00:00
|
|
|
mod path_to_regex;
|
2021-01-27 00:32:49 +00:00
|
|
|
mod performance;
|
2021-08-06 01:46:32 +00:00
|
|
|
mod refactor;
|
2021-04-09 01:27:27 +00:00
|
|
|
mod registries;
|
2021-12-15 18:23:43 +00:00
|
|
|
mod repl;
|
2024-04-26 20:39:33 +00:00
|
|
|
mod resolver;
|
2024-03-01 21:34:13 +00:00
|
|
|
mod search;
|
2021-04-20 01:26:36 +00:00
|
|
|
mod semantic_tokens;
|
2022-03-29 22:59:27 +00:00
|
|
|
mod testing;
|
2020-12-07 10:46:39 +00:00
|
|
|
mod text;
|
|
|
|
mod tsc;
|
2021-02-18 04:37:05 +00:00
|
|
|
mod urls;
|
2020-12-07 10:46:39 +00:00
|
|
|
|
2021-06-23 01:48:01 +00:00
|
|
|
pub async fn start() -> Result<(), AnyError> {
|
2020-12-21 13:44:26 +00:00
|
|
|
let stdin = tokio::io::stdin();
|
|
|
|
let stdout = tokio::io::stdout();
|
2020-12-07 10:46:39 +00:00
|
|
|
|
2023-11-22 04:08:48 +00:00
|
|
|
let token = CancellationToken::new();
|
2023-05-26 06:10:18 +00:00
|
|
|
let builder = LspService::build(|client| {
|
2023-11-22 04:08:48 +00:00
|
|
|
language_server::LanguageServer::new(
|
|
|
|
client::Client::from_tower(client),
|
|
|
|
token.clone(),
|
|
|
|
)
|
2022-04-03 04:17:30 +00:00
|
|
|
})
|
|
|
|
.custom_method(
|
|
|
|
lsp_custom::PERFORMANCE_REQUEST,
|
|
|
|
LanguageServer::performance_request,
|
|
|
|
)
|
2023-10-12 15:07:27 +00:00
|
|
|
.custom_method(lsp_custom::TASK_REQUEST, LanguageServer::task_definitions)
|
|
|
|
// TODO(nayeemrmn): Rename this to `deno/taskDefinitions` in vscode_deno and
|
|
|
|
// remove this alias.
|
|
|
|
.custom_method("deno/task", LanguageServer::task_definitions)
|
2022-04-03 04:17:30 +00:00
|
|
|
.custom_method(testing::TEST_RUN_REQUEST, LanguageServer::test_run_request)
|
|
|
|
.custom_method(
|
|
|
|
testing::TEST_RUN_CANCEL_REQUEST,
|
|
|
|
LanguageServer::test_run_cancel_request,
|
|
|
|
)
|
|
|
|
.custom_method(
|
|
|
|
lsp_custom::VIRTUAL_TEXT_DOCUMENT,
|
|
|
|
LanguageServer::virtual_text_document,
|
2023-09-26 20:57:14 +00:00
|
|
|
);
|
2023-05-26 06:10:18 +00:00
|
|
|
|
|
|
|
let builder = if should_send_diagnostic_batch_index_notifications() {
|
|
|
|
builder.custom_method(
|
|
|
|
lsp_custom::LATEST_DIAGNOSTIC_BATCH_INDEX,
|
|
|
|
LanguageServer::latest_diagnostic_batch_index_request,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
builder
|
|
|
|
};
|
|
|
|
|
|
|
|
let (service, socket) = builder.finish();
|
2022-04-03 04:17:30 +00:00
|
|
|
|
2023-11-22 04:08:48 +00:00
|
|
|
// TODO(nayeemrmn): This cancellation token is a workaround for
|
|
|
|
// https://github.com/denoland/deno/issues/20700. Remove when
|
|
|
|
// https://github.com/ebkalderon/tower-lsp/issues/399 is fixed.
|
|
|
|
// Force end the server 8 seconds after receiving a shutdown request.
|
|
|
|
tokio::select! {
|
|
|
|
biased;
|
|
|
|
_ = Server::new(stdin, stdout, socket).serve(service) => {}
|
|
|
|
_ = spawn(async move {
|
|
|
|
token.cancelled().await;
|
|
|
|
tokio::time::sleep(std::time::Duration::from_secs(8)).await;
|
|
|
|
}) => {}
|
|
|
|
}
|
2020-12-07 10:46:39 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|