From 873ded35895022fc1dbb1a8caeae314165eee32f Mon Sep 17 00:00:00 2001 From: Adrian Stanciu Date: Wed, 13 Oct 2021 20:04:50 +0300 Subject: [PATCH] changed #[repr(u8)] enums to structs --- src/completion.rs | 102 ++++++++++++++-------------- src/document_highlight.rs | 14 ++-- src/lib.rs | 136 ++++++++++++++++++++------------------ src/rename.rs | 11 ++- src/signature_help.rs | 15 +++-- src/window.rs | 20 +++--- 6 files changed, 154 insertions(+), 144 deletions(-) diff --git a/src/completion.rs b/src/completion.rs index 6d832b1..91c80e9 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; use crate::{ Command, Documentation, MarkupKind, PartialResultParams, TagSupport, @@ -12,42 +11,44 @@ use crate::Range; use serde_json::Value; /// Defines how to interpret the insert text in a completion item -#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr)] -#[repr(u8)] -pub enum InsertTextFormat { - PlainText = 1, - Snippet = 2, +#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] +#[serde(transparent)] +pub struct InsertTextFormat(u8); +impl InsertTextFormat { + pub const PlainText: InsertTextFormat = InsertTextFormat(1); + pub const Snippet: InsertTextFormat = InsertTextFormat(2); } /// The kind of a completion entry. -#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr)] -#[repr(u8)] -pub enum CompletionItemKind { - Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19, - EnumMember = 20, - Constant = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25, +#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] +#[serde(transparent)] +pub struct CompletionItemKind(u8); +impl CompletionItemKind { + pub const Text: CompletionItemKind = CompletionItemKind(1); + pub const Method: CompletionItemKind = CompletionItemKind(2); + pub const Function: CompletionItemKind = CompletionItemKind(3); + pub const Constructor: CompletionItemKind = CompletionItemKind(4); + pub const Field: CompletionItemKind = CompletionItemKind(5); + pub const Variable: CompletionItemKind = CompletionItemKind(6); + pub const Class: CompletionItemKind = CompletionItemKind(7); + pub const Interface: CompletionItemKind = CompletionItemKind(8); + pub const Module: CompletionItemKind = CompletionItemKind(9); + pub const Property: CompletionItemKind = CompletionItemKind(10); + pub const Unit: CompletionItemKind = CompletionItemKind(11); + pub const Value: CompletionItemKind = CompletionItemKind(12); + pub const Enum: CompletionItemKind = CompletionItemKind(13); + pub const Keyword: CompletionItemKind = CompletionItemKind(14); + pub const Snippet: CompletionItemKind = CompletionItemKind(15); + pub const Color: CompletionItemKind = CompletionItemKind(16); + pub const File: CompletionItemKind = CompletionItemKind(17); + pub const Reference: CompletionItemKind = CompletionItemKind(18); + pub const Folder: CompletionItemKind = CompletionItemKind(19); + pub const EnumMember: CompletionItemKind = CompletionItemKind(20); + pub const Constant: CompletionItemKind = CompletionItemKind(21); + pub const Struct: CompletionItemKind = CompletionItemKind(22); + pub const Event: CompletionItemKind = CompletionItemKind(23); + pub const Operator: CompletionItemKind = CompletionItemKind(24); + pub const TypeParameter: CompletionItemKind = CompletionItemKind(25); } #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] @@ -140,15 +141,16 @@ pub struct InsertTextModeSupport { /// item insertion. /// /// @since 3.16.0 -#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr)] -#[repr(u8)] -pub enum InsertTextMode { +#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] +#[serde(transparent)] +pub struct InsertTextMode(u8); +impl InsertTextMode { /// The insertion or replace strings is taken as it is. If the /// value is multi line the lines below the cursor will be /// inserted using the indentation defined in the string value. /// The client will not apply any kind of adjustments to the /// string. - AsIs = 1, + pub const AsIs: InsertTextMode = InsertTextMode(1); /// The editor adjusts leading whitespace of new lines so that /// they match the indentation up to the cursor of the line for @@ -157,13 +159,14 @@ pub enum InsertTextMode { /// Consider a line like this: <2tabs><3tabs>foo. Accepting a /// multi line completion item is indented using 2 tabs all /// following lines inserted will be indented using 2 tabs as well. - AdjustIndentation = 2, + pub const AdjustIndentation: InsertTextMode = InsertTextMode(2); } -#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum CompletionItemTag { - Deprecated = 1, +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct CompletionItemTag(u8); +impl CompletionItemTag { + pub const Deprecated: CompletionItemTag = CompletionItemTag(1); } #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] @@ -362,12 +365,13 @@ pub struct CompletionContext { } /// How a completion was triggered. -#[derive(Debug, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum CompletionTriggerKind { - Invoked = 1, - TriggerCharacter = 2, - TriggerForIncompleteCompletions = 3, +#[derive(Debug, PartialEq, Clone, Copy, Deserialize, Serialize)] +#[serde(transparent)] +pub struct CompletionTriggerKind(u8); +impl CompletionTriggerKind { + pub const Invoked: CompletionTriggerKind = CompletionTriggerKind(1); + pub const TriggerCharacter: CompletionTriggerKind = CompletionTriggerKind(2); + pub const TriggerForIncompleteCompletions: CompletionTriggerKind = CompletionTriggerKind(3); } /// Represents a collection of [completion items](#CompletionItem) to be presented diff --git a/src/document_highlight.rs b/src/document_highlight.rs index a5d47f8..0558f73 100644 --- a/src/document_highlight.rs +++ b/src/document_highlight.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; use crate::{ DynamicRegistrationClientCapabilities, PartialResultParams, Range, TextDocumentPositionParams, @@ -35,15 +34,16 @@ pub struct DocumentHighlight { } /// A document highlight kind. -#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum DocumentHighlightKind { +#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct DocumentHighlightKind(u8); +impl DocumentHighlightKind { /// A textual occurrance. - Text = 1, + pub const Text: DocumentHighlightKind = DocumentHighlightKind(1); /// Read-access of a symbol, like reading a variable. - Read = 2, + pub const Read: DocumentHighlightKind = DocumentHighlightKind(2); /// Write-access of a symbol, like writing to a variable. - Write = 3, + pub const Write: DocumentHighlightKind = DocumentHighlightKind(3); } diff --git a/src/lib.rs b/src/lib.rs index abb52ca..47c8c7f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ able to parse any URI, such as `urn:isbn:0451450523`. extern crate bitflags; use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; pub use url::Url; @@ -289,17 +288,18 @@ impl Diagnostic { } /// The protocol currently supports the following diagnostic severities: -#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum DiagnosticSeverity { +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Deserialize, Serialize)] +#[serde(transparent)] +pub struct DiagnosticSeverity(u8); +impl DiagnosticSeverity { /// Reports an error. - Error = 1, + pub const Error: DiagnosticSeverity = DiagnosticSeverity(1); /// Reports a warning. - Warning = 2, + pub const Warning: DiagnosticSeverity = DiagnosticSeverity(2); /// Reports an information. - Information = 3, + pub const Information: DiagnosticSeverity = DiagnosticSeverity(3); /// Reports a hint. - Hint = 4, + pub const Hint: DiagnosticSeverity = DiagnosticSeverity(4); } /// Represents a related message and source code location for a diagnostic. This @@ -315,17 +315,18 @@ pub struct DiagnosticRelatedInformation { } /// The diagnostic tags. -#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum DiagnosticTag { +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct DiagnosticTag(u8); +impl DiagnosticTag { /// Unused or unnecessary code. /// Clients are allowed to render diagnostics with this tag faded out instead of having /// an error squiggle. - Unnecessary = 1, + pub const Unnecessary: DiagnosticTag = DiagnosticTag(1); /// Deprecated or obsolete code. /// Clients are allowed to rendered diagnostics with this tag strike through. - Deprecated = 2, + pub const Deprecated: DiagnosticTag = DiagnosticTag(2); } /// Represents a reference to a command. Provides a title which will be used to represent a command in the UI. @@ -1066,38 +1067,39 @@ pub enum FailureHandlingKind { } /// A symbol kind. -#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize_repr, Deserialize_repr)] -#[repr(u8)] -pub enum SymbolKind { - File = 1, - Module = 2, - Namespace = 3, - Package = 4, - Class = 5, - Method = 6, - Property = 7, - Field = 8, - Constructor = 9, - Enum = 10, - Interface = 11, - Function = 12, - Variable = 13, - Constant = 14, - String = 15, - Number = 16, - Boolean = 17, - Array = 18, - Object = 19, - Key = 20, - Null = 21, - EnumMember = 22, - Struct = 23, - Event = 24, - Operator = 25, - TypeParameter = 26, +#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] +#[serde(transparent)] +pub struct SymbolKind(u8); +impl SymbolKind { + pub const File: SymbolKind = SymbolKind(1); + pub const Module: SymbolKind = SymbolKind(2); + pub const Namespace: SymbolKind = SymbolKind(3); + pub const Package: SymbolKind = SymbolKind(4); + pub const Class: SymbolKind = SymbolKind(5); + pub const Method: SymbolKind = SymbolKind(6); + pub const Property: SymbolKind = SymbolKind(7); + pub const Field: SymbolKind = SymbolKind(8); + pub const Constructor: SymbolKind = SymbolKind(9); + pub const Enum: SymbolKind = SymbolKind(10); + pub const Interface: SymbolKind = SymbolKind(11); + pub const Function: SymbolKind = SymbolKind(12); + pub const Variable: SymbolKind = SymbolKind(13); + pub const Constant: SymbolKind = SymbolKind(14); + pub const String: SymbolKind = SymbolKind(15); + pub const Number: SymbolKind = SymbolKind(16); + pub const Boolean: SymbolKind = SymbolKind(17); + pub const Array: SymbolKind = SymbolKind(18); + pub const Object: SymbolKind = SymbolKind(19); + pub const Key: SymbolKind = SymbolKind(20); + pub const Null: SymbolKind = SymbolKind(21); + pub const EnumMember: SymbolKind = SymbolKind(22); + pub const Struct: SymbolKind = SymbolKind(23); + pub const Event: SymbolKind = SymbolKind(24); + pub const Operator: SymbolKind = SymbolKind(25); + pub const TypeParameter: SymbolKind = SymbolKind(26); // Capturing all unknown enums by this lib. - Unknown = 255, + pub const Unknown: SymbolKind = SymbolKind(255); } /// Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. @@ -1504,18 +1506,19 @@ pub struct InitializeError { // The server can signal the following capabilities: /// Defines how the host (editor) should sync document changes to the language server. -#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum TextDocumentSyncKind { +#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] +#[serde(transparent)] +pub struct TextDocumentSyncKind(u8); +impl TextDocumentSyncKind { /// Documents should not be synced at all. - None = 0, + pub const None: TextDocumentSyncKind = TextDocumentSyncKind(0); /// Documents are synced by always sending the full content of the document. - Full = 1, + pub const Full: TextDocumentSyncKind = TextDocumentSyncKind(1); /// Documents are synced by sending the full content on open. After that only /// incremental updates to the document are sent. - Incremental = 2, + pub const Incremental: TextDocumentSyncKind = TextDocumentSyncKind(2); } pub type ExecuteCommandClientCapabilities = DynamicRegistrationClientCapabilities; @@ -2006,18 +2009,19 @@ pub struct WillSaveTextDocumentParams { } /// Represents reasons why a text document is saved. -#[derive(Copy, Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum TextDocumentSaveReason { +#[derive(Copy, Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct TextDocumentSaveReason(u8); +impl TextDocumentSaveReason { /// Manually triggered, e.g. by the user pressing save, by starting debugging, /// or by an API call. - Manual = 1, + pub const Manual: TextDocumentSaveReason = TextDocumentSaveReason(1); /// Automatic after a delay. - AfterDelay = 2, + pub const AfterDelay: TextDocumentSaveReason = TextDocumentSaveReason(2); /// When the editor lost focus. - FocusOut = 3, + pub const FocusOut: TextDocumentSaveReason = TextDocumentSaveReason(3); } #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] @@ -2059,17 +2063,18 @@ pub struct DidChangeWatchedFilesParams { } /// The file event type. -#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum FileChangeType { +#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct FileChangeType(u8); +impl FileChangeType { /// The file got created. - Created = 1, + pub const Created: FileChangeType = FileChangeType(1); /// The file got changed. - Changed = 2, + pub const Changed: FileChangeType = FileChangeType(2); /// The file got deleted. - Deleted = 3, + pub const Deleted: FileChangeType = FileChangeType(3); } /// An event describing a file change. @@ -2355,11 +2360,12 @@ pub struct PartialResultParams { /// Symbol tags are extra annotations that tweak the rendering of a symbol. /// Since 3.15 -#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum SymbolTag { +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct SymbolTag(u8); +impl SymbolTag { /// Render a symbol as obsolete, usually using a strike-out. - Deprecated = 1, + pub const Deprecated: SymbolTag = SymbolTag(1); } #[cfg(test)] diff --git a/src/rename.rs b/src/rename.rs index 7ae2cf0..472d5f4 100644 --- a/src/rename.rs +++ b/src/rename.rs @@ -1,8 +1,6 @@ use crate::{Range, TextDocumentPositionParams, WorkDoneProgressOptions, WorkDoneProgressParams}; use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; - #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct RenameParams { @@ -63,12 +61,13 @@ pub struct RenameClientCapabilities { pub honors_change_annotations: Option, } -#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize_repr, Deserialize_repr)] -#[repr(u8)] -pub enum PrepareSupportDefaultBehavior { +#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] +#[serde(transparent)] +pub struct PrepareSupportDefaultBehavior(u8); +impl PrepareSupportDefaultBehavior { /// The client's default behavior is to select the identifier /// according the to language's syntax rule - Identifier = 1, + pub const Identifier: PrepareSupportDefaultBehavior = PrepareSupportDefaultBehavior(1); } #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] diff --git a/src/signature_help.rs b/src/signature_help.rs index 7ce697a..bf6d1ce 100644 --- a/src/signature_help.rs +++ b/src/signature_help.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use serde_repr::{Deserialize_repr, Serialize_repr}; use crate::{ Documentation, MarkupKind, TextDocumentPositionParams, TextDocumentRegistrationOptions, @@ -82,16 +81,18 @@ pub struct SignatureHelpRegistrationOptions { #[serde(flatten)] pub text_document_registration_options: TextDocumentRegistrationOptions, } + /// Signature help options. -#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum SignatureHelpTriggerKind { +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(transparent)] +pub struct SignatureHelpTriggerKind(u8); +impl SignatureHelpTriggerKind { /// Signature help was invoked manually by the user or by a command. - Invoked = 1, + pub const Invoked: SignatureHelpTriggerKind = SignatureHelpTriggerKind(1); /// Signature help was triggered by a trigger character. - TriggerCharacter = 2, + pub const TriggerCharacter: SignatureHelpTriggerKind = SignatureHelpTriggerKind(2); /// Signature help was triggered by the cursor moving or by the document content changing. - ContentChange = 3, + pub const ContentChange: SignatureHelpTriggerKind = SignatureHelpTriggerKind(3); } #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] diff --git a/src/window.rs b/src/window.rs index aa7312c..b29c188 100644 --- a/src/window.rs +++ b/src/window.rs @@ -4,23 +4,23 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; -use serde_repr::{Deserialize_repr, Serialize_repr}; - use url::Url; use crate::Range; -#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)] -#[repr(u8)] -pub enum MessageType { +#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] +#[serde(transparent)] + +pub struct MessageType(u8); +impl MessageType { /// An error message. - Error = 1, + pub const Error: MessageType = MessageType(1); /// A warning message. - Warning = 2, - /// An information message. - Info = 3, + pub const Warning: MessageType = MessageType(2); + /// An information message; + pub const Info: MessageType = MessageType(3); /// A log message. - Log = 4, + pub const Log: MessageType = MessageType(4); } /// Window specific client capabilities.