From a6a855d903c4ef33fb5458b108c29bf95f713323 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Mon, 13 Feb 2023 17:31:47 +0800 Subject: [PATCH 1/2] doc: do some doc clean up, fix typo and clippy warning --- src/call_hierarchy.rs | 6 +-- src/code_action.rs | 24 +++++------ src/code_lens.rs | 2 +- src/color.rs | 2 +- src/completion.rs | 2 +- src/document_highlight.rs | 2 +- src/document_symbols.rs | 6 ++- src/file_operations.rs | 8 ++-- src/folding_range.rs | 1 + src/formatting.rs | 2 +- src/lib.rs | 85 ++++++++++++++++++++++----------------- src/lsif.rs | 4 +- src/progress.rs | 4 +- src/rename.rs | 4 +- src/request.rs | 6 +-- src/semantic_tokens.rs | 11 ++--- src/signature_help.rs | 2 +- src/trace.rs | 9 +---- src/window.rs | 5 +-- src/workspace_symbols.rs | 1 - tests/lsif.rs | 8 ++-- 21 files changed, 101 insertions(+), 93 deletions(-) diff --git a/src/call_hierarchy.rs b/src/call_hierarchy.rs index 21d3ec4..dea7880 100644 --- a/src/call_hierarchy.rs +++ b/src/call_hierarchy.rs @@ -9,14 +9,14 @@ use crate::{ pub type CallHierarchyClientCapabilities = DynamicRegistrationClientCapabilities; -#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize, Copy)] #[serde(rename_all = "camelCase")] pub struct CallHierarchyOptions { #[serde(flatten)] pub work_done_progress_options: WorkDoneProgressOptions, } -#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Copy)] #[serde(untagged)] pub enum CallHierarchyServerCapability { Simple(bool), @@ -72,7 +72,7 @@ pub struct CallHierarchyItem { /// Must be contained by the [`range`](#CallHierarchyItem.range). pub selection_range: Range, - /// A data entry field that is preserved between a call hierarchy prepare and incloming calls or outgoing calls requests. + /// A data entry field that is preserved between a call hierarchy prepare and incoming calls or outgoing calls requests. #[serde(skip_serializing_if = "Option::is_none")] pub data: Option, } diff --git a/src/code_action.rs b/src/code_action.rs index efac351..fe08299 100644 --- a/src/code_action.rs +++ b/src/code_action.rs @@ -42,13 +42,13 @@ pub struct CodeActionClientCapabilities { /// Whether code action supports the `isPreferred` property. /// - /// since 3.15.0 + /// @since 3.15.0 #[serde(skip_serializing_if = "Option::is_none")] pub is_preferred_support: Option, /// Whether code action supports the `disabled` property. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub disabled_support: Option, @@ -56,14 +56,14 @@ pub struct CodeActionClientCapabilities { /// preserved between a `textDocument/codeAction` and a /// `codeAction/resolve` request. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub data_support: Option, /// Whether the client supports resolving additional code action /// properties via a separate `codeAction/resolve` request. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub resolve_support: Option, @@ -79,9 +79,9 @@ pub struct CodeActionClientCapabilities { } /// Whether the client supports resolving additional code action -/// properties via a separate `codeAction/resolve` request. +/// properties via a separate `codeAction/resolve` request. /// -/// since 3.16.0 +/// @since 3.16.0 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CodeActionCapabilityResolveSupport { @@ -137,8 +137,8 @@ pub enum CodeActionOrCommand { } impl From for CodeActionOrCommand { - fn from(comand: Command) -> Self { - CodeActionOrCommand::Command(comand) + fn from(command: Command) -> Self { + CodeActionOrCommand::Command(command) } } @@ -263,7 +263,7 @@ pub struct CodeAction { /// A quick fix should be marked preferred if it properly addresses the underlying error. /// A refactoring should be marked preferred if it is the most reasonable choice of actions to take. /// - /// since 3.15.0 + /// @since 3.15.0 #[serde(skip_serializing_if = "Option::is_none")] pub is_preferred: Option, @@ -282,14 +282,14 @@ pub struct CodeAction { /// actions are returned, the client should show the user an error message with `reason` /// in the editor. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub disabled: Option, /// A data entry field that is preserved on a code action between /// a `textDocument/codeAction` and a `codeAction/resolve` request. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub data: Option, } @@ -360,7 +360,7 @@ pub struct CodeActionOptions { /// The server provides support to resolve additional /// information for a code action. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub resolve_provider: Option, } diff --git a/src/code_lens.rs b/src/code_lens.rs index 2e4fa79..c4c9c90 100644 --- a/src/code_lens.rs +++ b/src/code_lens.rs @@ -9,7 +9,7 @@ use crate::{ pub type CodeLensClientCapabilities = DynamicRegistrationClientCapabilities; /// Code Lens options. -#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Copy)] #[serde(rename_all = "camelCase")] pub struct CodeLensOptions { /// Code lens has a resolve provider as well. diff --git a/src/color.rs b/src/color.rs index ef9e858..584f979 100644 --- a/src/color.rs +++ b/src/color.rs @@ -69,7 +69,7 @@ pub struct ColorInformation { pub color: Color, } -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, Copy)] #[serde(rename_all = "camelCase")] pub struct Color { /// The red component of this color in the range [0-1]. diff --git a/src/completion.rs b/src/completion.rs index 1d29de7..bdf60fb 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -221,7 +221,7 @@ pub struct CompletionClientCapabilities { pub completion_item_kind: Option, /// The client supports to send additional context information for a - /// `textDocument/completion` requestion. + /// `textDocument/completion` request. #[serde(skip_serializing_if = "Option::is_none")] pub context_support: Option, diff --git a/src/document_highlight.rs b/src/document_highlight.rs index 9a97c10..f2954e6 100644 --- a/src/document_highlight.rs +++ b/src/document_highlight.rs @@ -39,7 +39,7 @@ pub struct DocumentHighlight { pub struct DocumentHighlightKind(i32); lsp_enum! { impl DocumentHighlightKind { - /// A textual occurrance. + /// A textual occurrence. pub const TEXT: DocumentHighlightKind = DocumentHighlightKind(1); /// Read-access of a symbol, like reading a variable. diff --git a/src/document_symbols.rs b/src/document_symbols.rs index f8b166f..d06ff2b 100644 --- a/src/document_symbols.rs +++ b/src/document_symbols.rs @@ -83,7 +83,8 @@ pub struct DocumentSymbol { /// The kind of this symbol. pub kind: SymbolKind, /// Tags for this completion item. - /// since 3.16.0 + /// + /// @since 3.15.0 #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, /// Indicates if this symbol is deprecated. @@ -114,7 +115,8 @@ pub struct SymbolInformation { pub kind: SymbolKind, /// Tags for this completion item. - /// since 3.16.0 + /// + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, diff --git a/src/file_operations.rs b/src/file_operations.rs index 4092d93..52572f9 100644 --- a/src/file_operations.rs +++ b/src/file_operations.rs @@ -90,9 +90,9 @@ pub struct FileOperationFilter { } /// A pattern kind describing if a glob pattern matches a file a folder or -/// both. +/// both. /// -/// @since 3.16.0 +/// @since 3.16.0 #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] #[serde(rename_all = "lowercase")] pub enum FileOperationPatternKind { @@ -147,9 +147,9 @@ pub struct FileOperationPattern { } /// The parameters sent in notifications/requests for user-initiated creation -/// of files. +/// of files. /// -/// @since 3.16.0 +/// @since 3.16.0 #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CreateFilesParams { diff --git a/src/folding_range.rs b/src/folding_range.rs index 8e7cf92..c9109eb 100644 --- a/src/folding_range.rs +++ b/src/folding_range.rs @@ -93,6 +93,7 @@ pub struct FoldingRangeClientCapabilities { pub folding_range_kind: Option, /// Specific options for the folding range. + /// /// @since 3.17.0 #[serde(skip_serializing_if = "Option::is_none")] pub folding_range: Option, diff --git a/src/formatting.rs b/src/formatting.rs index 2fb5e6b..4e5593c 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -50,7 +50,7 @@ pub struct FormattingOptions { #[serde(flatten)] pub properties: HashMap, - /// Trim trailing whitespaces on a line. + /// Trim trailing whitespace on a line. #[serde(skip_serializing_if = "Option::is_none")] pub trim_trailing_whitespace: Option, diff --git a/src/lib.rs b/src/lib.rs index 8dcd6ea..63fc5b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ able to parse any URI, such as `urn:isbn:0451450523`. */ #![allow(non_upper_case_globals)] -#[forbid(unsafe_code)] +#![forbid(unsafe_code)] #[macro_use] extern crate bitflags; @@ -359,7 +359,7 @@ pub struct Diagnostic { /// An optional property to describe the error code. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub code_description: Option, @@ -383,7 +383,7 @@ pub struct Diagnostic { /// A data entry field that is preserved between a `textDocument/publishDiagnostics` /// notification and `textDocument/codeAction` request. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub data: Option, } @@ -479,8 +479,10 @@ impl DiagnosticTag { } /// Represents a reference to a command. Provides a title which will be used to represent a command in the UI. -/// Commands are identitifed using a string identifier and the protocol currently doesn't specify a set of -/// well known commands. So executing a command requires some tool extension code. +/// Commands are identified by a string identifier. The recommended way to handle commands is to implement +/// their execution on the server side if the client and server provides the corresponding capabilities. +/// Alternatively the tool extension code could handle the command. +/// The protocol currently doesn’t specify a set of well-known commands. #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] pub struct Command { /// Title of the command, like `save`. @@ -528,12 +530,12 @@ impl TextEdit { /// An identifier referring to a change annotation managed by a workspace /// edit. /// -/// @since 3.16.0. +/// @since 3.16.0 pub type ChangeAnnotationIdentifier = String; /// A special text edit with an additional change annotation. /// -/// @since 3.16.0. +/// @since 3.16.0 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct AnnotatedTextEdit { @@ -564,7 +566,7 @@ pub struct TextDocumentEdit { /// Additional information that describes document changes. /// -/// @since 3.16.0. +/// @since 3.16.0 #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct ChangeAnnotation { @@ -615,7 +617,7 @@ pub struct CreateFile { #[serde(skip_serializing_if = "Option::is_none")] pub options: Option, - /// An optional annotation identifer describing the operation. + /// An optional annotation identifier describing the operation. /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] @@ -646,7 +648,7 @@ pub struct RenameFile { #[serde(skip_serializing_if = "Option::is_none")] pub options: Option, - /// An optional annotation identifer describing the operation. + /// An optional annotation identifier describing the operation. /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] @@ -664,7 +666,7 @@ pub struct DeleteFileOptions { #[serde(skip_serializing_if = "Option::is_none")] pub ignore_if_not_exists: Option, - /// An optional annotation identifer describing the operation. + /// An optional annotation identifier describing the operation. /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] @@ -716,7 +718,6 @@ pub struct WorkspaceEdit { /// `workspace.changeAnnotationSupport`. /// /// @since 3.16.0 - /// #[serde(skip_serializing_if = "Option::is_none")] pub change_annotations: Option>, } @@ -1160,16 +1161,14 @@ pub struct WorkspaceEditClientCapabilities { #[serde(skip_serializing_if = "Option::is_none")] pub resource_operations: Option>, - /// The failure handling strategy of a client if applying the workspace edit - /// failes. + /// The failure handling strategy of a client if applying the workspace edit fails. #[serde(skip_serializing_if = "Option::is_none")] pub failure_handling: Option, /// Whether the client normalizes line endings to the client specific /// setting. /// If set to `true` the client will normalize line ending characters - /// in a workspace edit containg to the client specific new line - /// character. + /// in a workspace edit to the client specific new line character(s). /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] @@ -1280,37 +1279,44 @@ pub struct WorkspaceClientCapabilities { pub execute_command: Option, /// The client has support for workspace folders. - /// since 3.6.0 + /// + /// @since 3.6.0 #[serde(skip_serializing_if = "Option::is_none")] pub workspace_folders: Option, /// The client supports `workspace/configuration` requests. - /// since 3.6.0 + /// + /// @since 3.6.0 #[serde(skip_serializing_if = "Option::is_none")] pub configuration: Option, - /// Capabilities specific to the semantic token requsts scoped to the workspace. - /// since 3.16.0 + /// Capabilities specific to the semantic token requests scoped to the workspace. + /// + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub semantic_tokens: Option, /// Capabilities specific to the code lens requests scoped to the workspace. - /// since 3.16.0 + /// + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub code_lens: Option, /// The client has support for file requests/notifications. - /// since 3.16.0 + /// + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub file_operations: Option, /// Client workspace capabilities specific to inline values. - /// since 3.17.0 + /// + /// @since 3.17.0 #[serde(skip_serializing_if = "Option::is_none")] pub inline_value: Option, /// Client workspace capabilities specific to inlay hints. - /// since 3.17.0 + /// + /// @since 3.17.0 #[serde(skip_serializing_if = "Option::is_none")] pub inlay_hint: Option, } @@ -1573,11 +1579,13 @@ pub struct ClientCapabilities { #[serde(rename_all = "camelCase")] pub struct GeneralClientCapabilities { /// Client capabilities specific to regular expressions. + /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub regular_expressions: Option, /// Client capabilities specific to the client's markdown parser. + /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub markdown: Option, @@ -1687,9 +1695,11 @@ pub struct ServerInfo { #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] pub struct InitializeError { - /// Indicates whether the client should retry to send the - /// initilize request after showing the message provided - /// in the ResponseError. + /// Indicates whether the client execute the following retry logic: + /// + /// - (1) show the message provided by the ResponseError to the user + /// - (2) user selects retry or cancel + /// - (3) if user selected retry the initialize method is sent again. pub retry: bool, } @@ -2065,7 +2075,7 @@ pub struct StaticRegistrationOptions { pub id: Option, } -#[derive(Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize, Copy)] #[serde(rename_all = "camelCase")] pub struct WorkDoneProgressOptions { #[serde(skip_serializing_if = "Option::is_none")] @@ -2205,7 +2215,7 @@ pub struct TextDocumentContentChangeEvent { pub text: String, } -/// Descibe options to be used when registered for text document change events. +/// Describe options to be used when registering for text document change events. /// /// Extends TextDocumentRegistrationOptions #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] @@ -2480,14 +2490,16 @@ pub enum Documentation { MarkupContent(MarkupContent), } -/// The marked string is rendered: -/// - as markdown if it is represented as a string -/// - as code block of the given langauge if it is represented as a pair of a language and a value +/// MarkedString can be used to render human readable text. It is either a +/// markdown string or a code-block that provides a language and a code snippet. +/// The language identifier is semantically equal to the optional language +/// identifier in fenced code blocks in GitHub issues. /// /// The pair of a language and a value is an equivalent to markdown: -/// ```${language} -/// ${value} -/// ``` +/// +/// ```${language} +/// ${value} +/// ``` #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(untagged)] pub enum MarkedString { @@ -2660,7 +2672,8 @@ pub struct PartialResultParams { } /// Symbol tags are extra annotations that tweak the rendering of a symbol. -/// Since 3.15 +/// +/// @since 3.16.0 #[derive(Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(transparent)] pub struct SymbolTag(i32); diff --git a/src/lsif.rs b/src/lsif.rs index 164d4eb..de34c94 100644 --- a/src/lsif.rs +++ b/src/lsif.rs @@ -4,8 +4,8 @@ //! //! Based on +use crate::{Range, Url}; use serde::{Deserialize, Serialize}; -use crate::{Url, Range}; pub type Id = crate::NumberOrString; @@ -84,7 +84,6 @@ pub struct DefinitionTag { detail: Option, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DeclarationTag { @@ -184,7 +183,6 @@ pub enum EventScope { Project, } - #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct Event { pub kind: EventKind, diff --git a/src/progress.rs b/src/progress.rs index 97d30e1..41fa74f 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -22,8 +22,8 @@ pub enum ProgressParamsValue { WorkDone(WorkDoneProgress), } -/// The `window/workDoneProgress/create` request is sent from the server -/// to the clientto ask the client to create a work done progress. +/// The `window/workDoneProgress/create` request is sent +/// from the server to the client to ask the client to create a work done progress. #[derive(Debug, PartialEq, Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct WorkDoneProgressCreateParams { diff --git a/src/rename.rs b/src/rename.rs index b84bdcf..bb57e9a 100644 --- a/src/rename.rs +++ b/src/rename.rs @@ -37,7 +37,7 @@ pub struct RenameClientCapabilities { /// Client supports testing for validity of rename operations before execution. /// - /// since 3.12.0 + /// @since 3.12.0 #[serde(skip_serializing_if = "Option::is_none")] pub prepare_support: Option, @@ -46,7 +46,7 @@ pub struct RenameClientCapabilities { /// The value indicates the default behavior used by the /// client. /// - /// since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub prepare_support_default_behavior: Option, diff --git a/src/request.rs b/src/request.rs index 067a4e0..ba647fc 100644 --- a/src/request.rs +++ b/src/request.rs @@ -498,7 +498,7 @@ impl Request for CodeActionRequest { /// This is usually used to compute the `edit` property of a code action to avoid its unnecessary computation /// during the `textDocument/codeAction` request. /// -/// since 3.16.0 +/// @since 3.16.0 #[derive(Debug)] pub enum CodeActionResolveRequest {} @@ -661,7 +661,7 @@ impl Request for WorkspaceFoldersRequest { } /// The `window/workDoneProgress/create` request is sent from the server -/// to the clientto ask the client to create a work done progress. +/// to the client to ask the client to create a work done progress. #[derive(Debug)] pub enum WorkDoneProgressCreate {} @@ -919,7 +919,7 @@ mod test { macro_rules! check_macro { ($name:tt) => { - // check whethe the macro name matches the method + // check whether the macro name matches the method assert_eq!(::METHOD, $name); // test whether type checking passes for each component fake_call::(); diff --git a/src/semantic_tokens.rs b/src/semantic_tokens.rs index 1c68c07..842558b 100644 --- a/src/semantic_tokens.rs +++ b/src/semantic_tokens.rs @@ -10,7 +10,8 @@ use crate::{ /// A set of predefined token types. This set is not fixed /// and clients can specify additional token types via the /// corresponding client capabilities. -/// since @3.16.0 +/// +/// @since 3.16.0 #[derive(Debug, Eq, PartialEq, Hash, PartialOrd, Clone, Deserialize, Serialize)] pub struct SemanticTokenType(Cow<'static, str>); @@ -38,7 +39,7 @@ impl SemanticTokenType { pub const REGEXP: SemanticTokenType = SemanticTokenType::new("regexp"); pub const OPERATOR: SemanticTokenType = SemanticTokenType::new("operator"); - /// since @3.17.0 + /// @since 3.17.0 pub const DECORATOR: SemanticTokenType = SemanticTokenType::new("decorator"); pub const fn new(tag: &'static str) -> Self { @@ -371,7 +372,7 @@ pub struct SemanticTokensClientCapabilities { /// ErrorCodes.ServerCancelled. If a server does the client /// needs to retrigger the request. /// - /// since @3.17.0 + /// @since 3.17.0 #[serde(skip_serializing_if = "Option::is_none")] pub server_cancel_support: Option, @@ -424,7 +425,7 @@ pub struct SemanticTokensOptions { /// The legend used by the server pub legend: SemanticTokensLegend, - /// Server supports providing semantic tokens for a sepcific range + /// Server supports providing semantic tokens for a specific range /// of a document. #[serde(skip_serializing_if = "Option::is_none")] pub range: Option, @@ -506,7 +507,7 @@ pub struct SemanticTokensDeltaParams { pub text_document: TextDocumentIdentifier, /// The result id of a previous response. The result Id can either point to a full response - /// or a delta response depending on what was recevied last. + /// or a delta response depending on what was received last. pub previous_result_id: String, } diff --git a/src/signature_help.rs b/src/signature_help.rs index 151f3bf..9abc960 100644 --- a/src/signature_help.rs +++ b/src/signature_help.rs @@ -19,7 +19,7 @@ pub struct SignatureInformationSettings { /// The client support the `activeParameter` property on `SignatureInformation` /// literal. /// - /// @since 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub active_parameter_support: Option, } diff --git a/src/trace.rs b/src/trace.rs index 3272925..7abcc56 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -11,22 +11,17 @@ pub struct SetTraceParams { /// /// The initial trace value is set by the client at initialization and can be modified /// later using the `SetTrace` notification. -#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize, Default)] #[serde(rename_all = "camelCase")] pub enum TraceValue { /// The server should not send any `$/logTrace` notification + #[default] Off, /// The server should not add the 'verbose' field in the `LogTraceParams` Messages, Verbose, } -impl Default for TraceValue { - fn default() -> TraceValue { - TraceValue::Off - } -} - #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct LogTraceParams { diff --git a/src/window.rs b/src/window.rs index 89d28aa..f583ded 100644 --- a/src/window.rs +++ b/src/window.rs @@ -39,14 +39,12 @@ pub struct WindowClientCapabilities { /// Capabilities specific to the showMessage request. /// /// @since 3.16.0 - /// #[serde(skip_serializing_if = "Option::is_none")] pub show_message: Option, /// Client capabilities for the show document request. /// /// @since 3.16.0 - /// #[serde(skip_serializing_if = "Option::is_none")] pub show_document: Option, } @@ -63,7 +61,7 @@ pub struct ShowMessageRequestClientCapabilities { #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct MessageActionItemCapabilities { - /// Whether the client supports additional attribues which + /// Whether the client supports additional attributes which /// are preserved and send back to the server in the /// request's response. #[serde(skip_serializing_if = "Option::is_none")] @@ -137,7 +135,6 @@ pub struct ShowDocumentClientCapabilities { /// Params to show a document. /// /// @since 3.16.0 -/// #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct ShowDocumentParams { diff --git a/src/workspace_symbols.rs b/src/workspace_symbols.rs index cdaeab7..9ba8089 100644 --- a/src/workspace_symbols.rs +++ b/src/workspace_symbols.rs @@ -20,7 +20,6 @@ pub struct WorkspaceSymbolClientCapabilities { /// Clients supporting tags have to handle unknown tags gracefully. /// /// @since 3.16.0 - /// #[serde( default, skip_serializing_if = "Option::is_none", diff --git a/tests/lsif.rs b/tests/lsif.rs index dd4a723..3b90c8b 100644 --- a/tests/lsif.rs +++ b/tests/lsif.rs @@ -1,8 +1,8 @@ -use lsp_types::lsif::Entry; - #[test] #[cfg(unix)] fn run() { + use lsp_types::lsif::Entry; + let jsonl = include_str!("tsc-unix.lsif"); for json in jsonl.lines() { let r = serde_json::from_str::(&json).expect(&format!("can not parse {}", json)); @@ -10,7 +10,9 @@ fn run() { assert_eq!( serde_json::from_str::(&x).unwrap(), serde_json::from_str::(json).unwrap(), - "and strings:\ntheir: {}\n our: {}", json, x, + "and strings:\ntheir: {}\n our: {}", + json, + x, ); } } From 33d565e6190d331d7e76a968505e64de816a0ea6 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Wed, 15 Feb 2023 10:27:30 +0800 Subject: [PATCH 2/2] more derive --- src/code_action.rs | 2 +- src/document_symbols.rs | 2 +- src/lib.rs | 15 ++++++++------- src/lsif.rs | 2 +- src/signature_help.rs | 8 ++++---- src/window.rs | 16 ++++++++-------- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/code_action.rs b/src/code_action.rs index fe08299..6cc39e0 100644 --- a/src/code_action.rs +++ b/src/code_action.rs @@ -344,7 +344,7 @@ pub struct CodeActionContext { pub trigger_kind: Option, } -#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Default)] #[serde(rename_all = "camelCase")] pub struct CodeActionOptions { /// CodeActionKinds that this server may return. diff --git a/src/document_symbols.rs b/src/document_symbols.rs index d06ff2b..3f482e1 100644 --- a/src/document_symbols.rs +++ b/src/document_symbols.rs @@ -83,7 +83,7 @@ pub struct DocumentSymbol { /// The kind of this symbol. pub kind: SymbolKind, /// Tags for this completion item. - /// + /// /// @since 3.15.0 #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, diff --git a/src/lib.rs b/src/lib.rs index 63fc5b0..633fc60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -280,8 +280,8 @@ impl Location { pub struct LocationLink { /// Span of the origin of this link. /// - /// Used as the underlined span for mouse interaction. Defaults to the word range at - /// the mouse position. + /// Used as the underlined span for mouse interaction. Defaults to the word range at + /// the mouse position. #[serde(skip_serializing_if = "Option::is_none")] pub origin_selection_range: Option, @@ -380,7 +380,7 @@ pub struct Diagnostic { #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, - /// A data entry field that is preserved between a `textDocument/publishDiagnostics` + /// A data entry field that is preserved between a `textDocument/publishDiagnostics` /// notification and `textDocument/codeAction` request. /// /// @since 3.16.0 @@ -1362,13 +1362,13 @@ pub struct PublishDiagnosticsClientCapabilities { /// Whether the client interprets the version property of the /// `textDocument/publishDiagnostics` notification's parameter. /// - /// 3.15.0 + /// @since 3.15.0 #[serde(skip_serializing_if = "Option::is_none")] pub version_support: Option, /// Client supports a codeDescription property /// - /// 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub code_description_support: Option, @@ -1376,7 +1376,7 @@ pub struct PublishDiagnosticsClientCapabilities { /// preserved between a `textDocument/publishDiagnostics` and /// `textDocument/codeAction` request. /// - /// 3.16.0 + /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] pub data_support: Option, } @@ -2641,6 +2641,7 @@ pub enum MarkupKind { /// If the format is `markdown` the content should follow the [GitHub Flavored Markdown Specification](https://github.github.com/gfm/). /// /// Here is an example how such a string can be constructed using JavaScript / TypeScript: +/// /// ```ignore /// let markdown: MarkupContent = { /// kind: MarkupKind::Markdown, @@ -2655,7 +2656,7 @@ pub enum MarkupKind { /// }; /// ``` /// -/// Please Note* that clients might sanitize the return markdown. A client could decide to +/// Please *Note* that clients might sanitize the return markdown. A client could decide to /// remove HTML from the markdown to avoid script execution. #[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)] pub struct MarkupContent { diff --git a/src/lsif.rs b/src/lsif.rs index de34c94..be6df6e 100644 --- a/src/lsif.rs +++ b/src/lsif.rs @@ -42,7 +42,7 @@ pub struct ToolInfo { pub version: Option, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)] pub enum Encoding { /// Currently only 'utf-16' is supported due to the limitations in LSP. #[serde(rename = "utf-16")] diff --git a/src/signature_help.rs b/src/signature_help.rs index 9abc960..2466d10 100644 --- a/src/signature_help.rs +++ b/src/signature_help.rs @@ -17,7 +17,7 @@ pub struct SignatureInformationSettings { pub parameter_information: Option, /// The client support the `activeParameter` property on `SignatureInformation` - /// literal. + /// literal. /// /// @since 3.16.0 #[serde(skip_serializing_if = "Option::is_none")] @@ -65,7 +65,7 @@ pub struct SignatureHelpOptions { #[serde(skip_serializing_if = "Option::is_none")] pub trigger_characters: Option>, - /// List of characters that re-trigger signature help. + /// List of characters that re-trigger signature help. /// These trigger characters are only active when signature help is already showing. All trigger characters /// are also counted as re-trigger characters. #[serde(skip_serializing_if = "Option::is_none")] @@ -90,7 +90,7 @@ lsp_enum! { impl SignatureHelpTriggerKind { /// Signature help was invoked manually by the user or by a command. pub const INVOKED: SignatureHelpTriggerKind = SignatureHelpTriggerKind(1); - /// Signature help was triggered by a trigger character. + /// Signature help was triggered by a trigger character. pub const TRIGGER_CHARACTER: SignatureHelpTriggerKind = SignatureHelpTriggerKind(2); /// Signature help was triggered by the cursor moving or by the document content changing. pub const CONTENT_CHANGE: SignatureHelpTriggerKind = SignatureHelpTriggerKind(3); @@ -115,7 +115,7 @@ pub struct SignatureHelpParams { #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct SignatureHelpContext { - /// Action that caused signature help to be triggered. + /// Action that caused signature help to be triggered. pub trigger_kind: SignatureHelpTriggerKind, /// Character that caused signature help to be triggered. diff --git a/src/window.rs b/src/window.rs index f583ded..ac45e60 100644 --- a/src/window.rs +++ b/src/window.rs @@ -147,17 +147,17 @@ pub struct ShowDocumentParams { #[serde(skip_serializing_if = "Option::is_none")] pub external: Option, - /// An optional property to indicate whether the editor - /// showing the document should take focus or not. - /// Clients might ignore this property if an external - /// program in started. + /// An optional property to indicate whether the editor + /// showing the document should take focus or not. + /// Clients might ignore this property if an external + /// program in started. #[serde(skip_serializing_if = "Option::is_none")] pub take_focus: Option, - /// An optional selection range if the document is a text - /// document. Clients might ignore the property if an - /// external program is started or the file is not a text - /// file. + /// An optional selection range if the document is a text + /// document. Clients might ignore the property if an + /// external program is started or the file is not a text + /// file. #[serde(skip_serializing_if = "Option::is_none")] pub selection: Option, }