Skip to content

Commit

Permalink
Merge pull request #221 from sidkshatriya/debug-trait-symbol-kind
Browse files Browse the repository at this point in the history
Manual implementation of Debug trait for `SymbolKind` and `CompletionItemKind` as they are no longer Enums
  • Loading branch information
Marwes authored Nov 1, 2021
2 parents 6c94dd6 + f84415b commit 6d9d04a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
37 changes: 35 additions & 2 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 36 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 6d9d04a

Please sign in to comment.