From 5b32fe494a3a4455f60b7f184281e5cb57d5c2f1 Mon Sep 17 00:00:00 2001 From: Sidharth Kshatriya Date: Sun, 31 Oct 2021 16:33:05 +0530 Subject: [PATCH 1/2] Manual implementation of Debug trait for SymbolKind now that it is not an Enum --- src/lib.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0480623..1fb9a75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ able to parse any URI, such as `urn:isbn:0451450523`. extern crate bitflags; use serde::{Deserialize, Serialize}; - +use std::fmt::Debug; pub use url::Url; use std::collections::HashMap; @@ -1067,7 +1067,7 @@ pub enum FailureHandlingKind { } /// A symbol kind. -#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] +#[derive(Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] #[serde(transparent)] pub struct SymbolKind(i32); impl SymbolKind { @@ -1099,6 +1099,40 @@ impl SymbolKind { pub const TYPE_PARAMETER: SymbolKind = SymbolKind(26); } +impl Debug for SymbolKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + Self::FILE => write!(f, "File"), + Self::MODULE => write!(f, "Module"), + Self::NAMESPACE => write!(f, "Namespace"), + Self::PACKAGE => write!(f, "Package"), + Self::CLASS => write!(f, "Class"), + Self::METHOD => write!(f, "Method"), + Self::PROPERTY => write!(f, "Property"), + Self::FIELD => write!(f, "Field"), + Self::CONSTRUCTOR => write!(f, "Constructor"), + Self::ENUM => write!(f, "Enum"), + Self::INTERFACE => write!(f, "Interface"), + Self::FUNCTION => write!(f, "Function"), + Self::VARIABLE => write!(f, "Variable"), + Self::CONSTANT => write!(f, "Constant"), + Self::STRING => write!(f, "String"), + Self::NUMBER => write!(f, "Number"), + Self::BOOLEAN => write!(f, "Boolean"), + Self::ARRAY => write!(f, "Array"), + Self::OBJECT => write!(f, "Object"), + Self::KEY => write!(f, "Key"), + Self::NULL => write!(f, "Null"), + Self::ENUM_MEMBER => write!(f, "EnumMember"), + Self::STRUCT => write!(f, "Struct"), + Self::EVENT => write!(f, "Event"), + Self::OPERATOR => write!(f, "Operator"), + Self::TYPE_PARAMETER => write!(f, "TypeParameter"), + _ => write!(f, "SymbolKind({})", self.0), + } + } +} + /// Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] From f84415b0301c429bb103319c20b3b4fb0469930a Mon Sep 17 00:00:00 2001 From: Sidharth Kshatriya Date: Sun, 31 Oct 2021 18:11:02 +0530 Subject: [PATCH 2/2] Manual implementation of Debug trait for CompletionItemKind now that it is not an Enum --- src/completion.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/completion.rs b/src/completion.rs index 324627f..f828057 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -7,8 +7,8 @@ use crate::{ }; use crate::Range; - use serde_json::Value; +use std::fmt::Debug; /// Defines how to interpret the insert text in a completion item #[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] @@ -20,7 +20,7 @@ impl InsertTextFormat { } /// The kind of a completion entry. -#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] +#[derive(Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] #[serde(transparent)] pub struct CompletionItemKind(i32); impl CompletionItemKind { @@ -51,6 +51,39 @@ impl CompletionItemKind { pub const TYPE_PARAMETER: CompletionItemKind = CompletionItemKind(25); } +impl Debug for CompletionItemKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + Self::TEXT => write!(f, "Text"), + Self::METHOD => write!(f, "Method"), + Self::FUNCTION => write!(f, "Function"), + Self::CONSTRUCTOR => write!(f, "Constructor"), + Self::FIELD => write!(f, "Field"), + Self::VARIABLE => write!(f, "Variable"), + Self::CLASS => write!(f, "Class"), + Self::INTERFACE => write!(f, "Interface"), + Self::MODULE => write!(f, "Module"), + Self::PROPERTY => write!(f, "Property"), + Self::UNIT => write!(f, "Unit"), + Self::VALUE => write!(f, "Value"), + Self::ENUM => write!(f, "Enum"), + Self::KEYWORD => write!(f, "Keyword"), + Self::SNIPPET => write!(f, "Snippet"), + Self::COLOR => write!(f, "Color"), + Self::FILE => write!(f, "File"), + Self::REFERENCE => write!(f, "Reference"), + Self::FOLDER => write!(f, "Folder"), + Self::ENUM_MEMBER => write!(f, "EnumMember"), + Self::CONSTANT => write!(f, "Constant"), + Self::STRUCT => write!(f, "Struct"), + Self::EVENT => write!(f, "Event"), + Self::OPERATOR => write!(f, "Operator"), + Self::TYPE_PARAMETER => write!(f, "TypeParameter"), + _ => write!(f, "CompletionItemKind({})", self.0), + } + } +} + #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CompletionItemCapability {