Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: derive Hash for all data structures #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ serde = { version = "1.0.34", features = ["derive"] }
serde_json = "1.0.50"
serde_repr = "0.1"
fluent-uri = "0.1.4"
ordermap = { version = "0.5.3", features = ["serde"], optional = true }

[features]
default = []
# Enables proposed LSP extensions.
# NOTE: No semver compatibility is guaranteed for types enabled by this feature.
proposed = []

hash = ["dep:ordermap"]
8 changes: 8 additions & 0 deletions src/call_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ pub type CallHierarchyClientCapabilities = DynamicRegistrationClientCapabilities

#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize, Copy)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Copy)]
#[serde(untagged)]
#[cfg_attr(feature = "hash", derive(Hash))]
pub enum CallHierarchyServerCapability {
Simple(bool),
Options(CallHierarchyOptions),
Expand All @@ -36,6 +38,7 @@ impl From<bool> for CallHierarchyServerCapability {

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyPrepareParams {
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
Expand All @@ -46,6 +49,7 @@ pub struct CallHierarchyPrepareParams {

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyItem {
/// The name of this item.
pub name: String,
Expand Down Expand Up @@ -78,6 +82,7 @@ pub struct CallHierarchyItem {

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyIncomingCallsParams {
pub item: CallHierarchyItem,

Expand All @@ -91,6 +96,7 @@ pub struct CallHierarchyIncomingCallsParams {
/// Represents an incoming call, e.g. a caller of a method or constructor.
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyIncomingCall {
/// The item that makes the call.
pub from: CallHierarchyItem,
Expand All @@ -102,6 +108,7 @@ pub struct CallHierarchyIncomingCall {

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyOutgoingCallsParams {
pub item: CallHierarchyItem,

Expand All @@ -115,6 +122,7 @@ pub struct CallHierarchyOutgoingCallsParams {
/// Represents an outgoing call, e.g. calling a getter from a method or a method from a constructor etc.
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CallHierarchyOutgoingCall {
/// The item that is called.
pub to: CallHierarchyItem,
Expand Down
15 changes: 14 additions & 1 deletion src/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use serde_json::Value;
use std::borrow::Cow;
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
#[cfg_attr(feature = "hash", derive(Hash))]
pub enum CodeActionProviderCapability {
Simple(bool),
Options(CodeActionOptions),
Expand All @@ -28,6 +29,7 @@ impl From<bool> for CodeActionProviderCapability {

#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionClientCapabilities {
///
/// This capability supports dynamic registration.
Expand Down Expand Up @@ -84,20 +86,23 @@ pub struct CodeActionClientCapabilities {
/// @since 3.16.0
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionCapabilityResolveSupport {
/// The properties that a client can resolve lazily.
pub properties: Vec<String>,
}

#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionLiteralSupport {
/// The code action kind is support with the following value set.
pub code_action_kind: CodeActionKindLiteralSupport,
}

#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionKindLiteralSupport {
/// The code action kind values the client supports. When this
/// property exists the client also guarantees that it will
Expand All @@ -109,6 +114,7 @@ pub struct CodeActionKindLiteralSupport {
/// Params for the CodeActionRequest
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionParams {
/// The document in which the command was invoked.
pub text_document: TextDocumentIdentifier,
Expand All @@ -131,6 +137,7 @@ pub type CodeActionResponse = Vec<CodeActionOrCommand>;

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
#[cfg_attr(feature = "hash", derive(Hash))]
pub enum CodeActionOrCommand {
Command(Command),
CodeAction(CodeAction),
Expand All @@ -148,7 +155,8 @@ impl From<CodeAction> for CodeActionOrCommand {
}
}

#[derive(Debug, Eq, PartialEq, Hash, PartialOrd, Clone, Deserialize, Serialize)]
#[derive(Debug, Eq, PartialEq, PartialOrd, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionKind(Cow<'static, str>);

impl CodeActionKind {
Expand Down Expand Up @@ -235,6 +243,7 @@ impl From<&'static str> for CodeActionKind {

#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeAction {
/// A short, human-readable, title for this code action.
pub title: String,
Expand Down Expand Up @@ -296,6 +305,7 @@ pub struct CodeAction {

#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionDisabled {
/// Human readable description of why the code action is currently disabled.
///
Expand All @@ -308,6 +318,7 @@ pub struct CodeActionDisabled {
/// @since 3.17.0
#[derive(Eq, PartialEq, Clone, Copy, Deserialize, Serialize)]
#[serde(transparent)]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionTriggerKind(i32);
lsp_enum! {
impl CodeActionTriggerKind {
Expand All @@ -326,6 +337,7 @@ impl CodeActionTriggerKind {
/// a code action is run.
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionContext {
/// An array of diagnostics.
pub diagnostics: Vec<Diagnostic>,
Expand All @@ -346,6 +358,7 @@ pub struct CodeActionContext {

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeActionOptions {
/// CodeActionKinds that this server may return.
///
Expand Down
4 changes: 4 additions & 0 deletions src/code_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub type CodeLensClientCapabilities = DynamicRegistrationClientCapabilities;
/// Code Lens options.
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Copy)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeLensOptions {
/// Code lens has a resolve provider as well.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -19,6 +20,7 @@ pub struct CodeLensOptions {

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeLensParams {
/// The document to request code lens for.
pub text_document: TextDocumentIdentifier,
Expand All @@ -37,6 +39,7 @@ pub struct CodeLensParams {
/// reasons the creation of a code lens and resolving should be done in two stages.
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeLens {
/// The range in which this code lens is valid. Should only span a single line.
pub range: Range,
Expand All @@ -53,6 +56,7 @@ pub struct CodeLens {

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct CodeLensWorkspaceClientCapabilities {
/// Whether the client implementation supports a refresh request sent from the
/// server to the client.
Expand Down
17 changes: 17 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ pub type DocumentColorClientCapabilities = DynamicRegistrationClientCapabilities

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct ColorProviderOptions {}

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct StaticTextDocumentColorProviderOptions {
/// A document selector to identify the scope of the registration. If set to null
/// the document selector provided on the client side will be used.
Expand All @@ -23,6 +25,7 @@ pub struct StaticTextDocumentColorProviderOptions {

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
#[cfg_attr(feature = "hash", derive(Hash))]
pub enum ColorProviderCapability {
Simple(bool),
ColorProvider(ColorProviderOptions),
Expand All @@ -49,6 +52,7 @@ impl From<bool> for ColorProviderCapability {

#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct DocumentColorParams {
/// The text document
pub text_document: TextDocumentIdentifier,
Expand All @@ -62,6 +66,7 @@ pub struct DocumentColorParams {

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct ColorInformation {
/// The range in the document where this color appears.
pub range: Range,
Expand All @@ -82,8 +87,19 @@ pub struct Color {
pub alpha: f32,
}

#[cfg(feature = "hash")]
impl std::hash::Hash for Color {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.red.to_bits().hash(state);
self.green.to_bits().hash(state);
self.blue.to_bits().hash(state);
self.alpha.to_bits().hash(state);
}
}

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct ColorPresentationParams {
/// The text document.
pub text_document: TextDocumentIdentifier,
Expand All @@ -103,6 +119,7 @@ pub struct ColorPresentationParams {

#[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Default, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "hash", derive(Hash))]
pub struct ColorPresentation {
/// The label of this color presentation. It will be shown on the color
/// picker header. By default this is also the text that is inserted when selecting
Expand Down
Loading