diff options
Diffstat (limited to 'cli/lsp/utils.rs')
-rw-r--r-- | cli/lsp/utils.rs | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/cli/lsp/utils.rs b/cli/lsp/utils.rs index 0c3d5a635..3bdd00875 100644 --- a/cli/lsp/utils.rs +++ b/cli/lsp/utils.rs @@ -1,71 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use deno_core::error::custom_error; use deno_core::error::AnyError; -use deno_core::serde_json::Value; use deno_core::url::Position; use deno_core::url::Url; use deno_core::ModuleSpecifier; -use lsp_server::Notification; -use serde::de::DeserializeOwned; -use std::error::Error; -use std::fmt; - -// TODO(@kitsonk) support actually supporting cancellation requests from the -// client. - -pub struct Canceled { - _private: (), -} - -impl Canceled { - #[allow(unused)] - pub fn new() -> Self { - Self { _private: () } - } - - #[allow(unused)] - pub fn throw() -> ! { - std::panic::resume_unwind(Box::new(Canceled::new())) - } -} - -impl fmt::Display for Canceled { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "cancelled") - } -} - -impl fmt::Debug for Canceled { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Canceled") - } -} - -impl Error for Canceled {} - -pub fn from_json<T: DeserializeOwned>( - what: &'static str, - json: Value, -) -> Result<T, AnyError> { - let response = T::deserialize(&json).map_err(|err| { - custom_error( - "DeserializeFailed", - format!("Failed to deserialize {}: {}; {}", what, err, json), - ) - })?; - Ok(response) -} - -pub fn is_canceled(e: &(dyn Error + 'static)) -> bool { - e.downcast_ref::<Canceled>().is_some() -} - -pub fn notification_is<N: lsp_types::notification::Notification>( - notification: &Notification, -) -> bool { - notification.method == N::METHOD -} /// Normalizes a file name returned from the TypeScript compiler into a URI that /// should be sent by the language server to the client. |