#![allow(non_upper_case_globals)]
#![forbid(unsafe_code)]
#[macro_use]
extern crate bitflags;
use serde::{Deserialize, Serialize};
use serde_json;
use serde_repr::{Deserialize_repr, Serialize_repr};
pub use url::Url;
use std::collections::HashMap;
#[cfg(feature = "proposed")]
use base64;
use serde::de;
use serde::de::Error as Error_;
use serde_json::Value;
#[cfg(feature = "proposed")]
use serde::ser::SerializeSeq;
#[cfg(feature = "proposed")]
use std::{borrow::Cow, convert::TryFrom};
pub mod notification;
pub mod request;
#[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum NumberOrString {
Number(u64),
String(String),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct CancelParams {
pub id: NumberOrString,
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize)]
pub struct Position {
pub line: u64,
pub character: u64,
}
impl Position {
pub fn new(line: u64, character: u64) -> Position {
Position { line, character }
}
}
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize)]
pub struct Range {
pub start: Position,
pub end: Position,
}
impl Range {
pub fn new(start: Position, end: Position) -> Range {
Range { start, end }
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct Location {
pub uri: Url,
pub range: Range,
}
impl Location {
pub fn new(uri: Url, range: Range) -> Location {
Location { uri, range }
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LocationLink {
#[serde(skip_serializing_if = "Option::is_none")]
pub origin_selection_range: Option<Range>,
pub target_uri: Url,
pub target_range: Range,
pub target_selection_range: Range,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Diagnostic {
pub range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub severity: Option<DiagnosticSeverity>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<NumberOrString>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub related_information: Option<Vec<DiagnosticRelatedInformation>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<DiagnosticTag>>,
}
impl Diagnostic {
pub fn new(
range: Range,
severity: Option<DiagnosticSeverity>,
code: Option<NumberOrString>,
source: Option<String>,
message: String,
related_information: Option<Vec<DiagnosticRelatedInformation>>,
tags: Option<Vec<DiagnosticTag>>,
) -> Diagnostic {
Diagnostic {
range,
severity,
code,
source,
message,
related_information,
tags,
}
}
pub fn new_simple(range: Range, message: String) -> Diagnostic {
Self::new(range, None, None, None, message, None, None)
}
pub fn new_with_code_number(
range: Range,
severity: DiagnosticSeverity,
code_number: u64,
source: Option<String>,
message: String,
) -> Diagnostic {
let code = Some(NumberOrString::Number(code_number));
Self::new(range, Some(severity), code, source, message, None, None)
}
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum DiagnosticSeverity {
Error = 1,
Warning = 2,
Information = 3,
Hint = 4,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct DiagnosticRelatedInformation {
pub location: Location,
pub message: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum DiagnosticTag {
Unnecessary = 1,
Deprecated = 2,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct Command {
pub title: String,
pub command: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub arguments: Option<Vec<Value>>,
}
impl Command {
pub fn new(title: String, command: String, arguments: Option<Vec<Value>>) -> Command {
Command {
title,
command,
arguments,
}
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextEdit {
pub range: Range,
pub new_text: String,
}
impl TextEdit {
pub fn new(range: Range, new_text: String) -> TextEdit {
TextEdit { range, new_text }
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentEdit {
pub text_document: VersionedTextDocumentIdentifier,
pub edits: Vec<TextEdit>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct InsertReplaceEdit {
pub new_text: String,
pub insert: Range,
pub replace: Range,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum CompletionTextEdit {
Edit(TextEdit),
#[cfg(feature = "proposed")]
InsertAndReplace(InsertReplaceEdit),
}
impl From<TextEdit> for CompletionTextEdit {
fn from(edit: TextEdit) -> Self {
CompletionTextEdit::Edit(edit)
}
}
#[cfg(feature = "proposed")]
impl From<InsertReplaceEdit> for CompletionTextEdit {
fn from(edit: InsertReplaceEdit) -> Self {
CompletionTextEdit::InsertAndReplace(edit)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateFileOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub overwrite: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore_if_exists: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateFile {
pub uri: Url,
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<CreateFileOptions>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RenameFileOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub overwrite: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore_if_exists: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RenameFile {
pub old_uri: Url,
pub new_uri: Url,
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<RenameFileOptions>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteFileOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub recursive: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ignore_if_not_exists: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteFile {
pub uri: Url,
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<DeleteFileOptions>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceEdit {
#[serde(with = "url_map")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub changes: Option<HashMap<Url, Vec<TextEdit>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_changes: Option<DocumentChanges>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum DocumentChanges {
Edits(Vec<TextDocumentEdit>),
Operations(Vec<DocumentChangeOperation>),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged, rename_all = "lowercase")]
pub enum DocumentChangeOperation {
Op(ResourceOp),
Edit(TextDocumentEdit),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum ResourceOp {
Create(CreateFile),
Rename(RenameFile),
Delete(DeleteFile),
}
#[derive(Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfigurationParams {
pub items: Vec<ConfigurationItem>,
}
#[derive(Debug, Default, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfigurationItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub scope_uri: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub section: Option<String>,
}
mod url_map {
use super::*;
use std::fmt;
pub fn deserialize<'de, D>(
deserializer: D,
) -> Result<Option<HashMap<Url, Vec<TextEdit>>>, D::Error>
where
D: serde::Deserializer<'de>,
{
struct UrlMapVisitor;
impl<'de> de::Visitor<'de> for UrlMapVisitor {
type Value = HashMap<Url, Vec<TextEdit>>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("map")
}
fn visit_map<M>(self, mut visitor: M) -> Result<Self::Value, M::Error>
where
M: de::MapAccess<'de>,
{
let mut values = HashMap::with_capacity(visitor.size_hint().unwrap_or(0));
while let Some((key, value)) = visitor.next_entry::<Url, _>()? {
values.insert(key, value);
}
Ok(values)
}
}
struct OptionUrlMapVisitor;
impl<'de> de::Visitor<'de> for OptionUrlMapVisitor {
type Value = Option<HashMap<Url, Vec<TextEdit>>>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("option")
}
#[inline]
fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(None)
}
#[inline]
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(None)
}
#[inline]
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_map(UrlMapVisitor).map(Some)
}
}
deserializer.deserialize_option(OptionUrlMapVisitor)
}
pub fn serialize<S>(
changes: &Option<HashMap<Url, Vec<TextEdit>>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeMap;
match *changes {
Some(ref changes) => {
let mut map = serializer.serialize_map(Some(changes.len()))?;
for (k, v) in changes {
map.serialize_entry(k.as_str(), v)?;
}
map.end()
}
None => serializer.serialize_none(),
}
}
}
impl WorkspaceEdit {
pub fn new(changes: HashMap<Url, Vec<TextEdit>>) -> WorkspaceEdit {
WorkspaceEdit {
changes: Some(changes),
document_changes: None,
}
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct TextDocumentIdentifier {
pub uri: Url,
}
impl TextDocumentIdentifier {
pub fn new(uri: Url) -> TextDocumentIdentifier {
TextDocumentIdentifier { uri }
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentItem {
pub uri: Url,
pub language_id: String,
pub version: i64,
pub text: String,
}
impl TextDocumentItem {
pub fn new(uri: Url, language_id: String, version: i64, text: String) -> TextDocumentItem {
TextDocumentItem {
uri,
language_id,
version,
text,
}
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct VersionedTextDocumentIdentifier {
pub uri: Url,
pub version: Option<i64>,
}
impl VersionedTextDocumentIdentifier {
pub fn new(uri: Url, version: i64) -> VersionedTextDocumentIdentifier {
VersionedTextDocumentIdentifier {
uri,
version: Some(version),
}
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentPositionParams {
pub text_document: TextDocumentIdentifier,
pub position: Position,
}
impl TextDocumentPositionParams {
pub fn new(
text_document: TextDocumentIdentifier,
position: Position,
) -> TextDocumentPositionParams {
TextDocumentPositionParams {
text_document,
position,
}
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct DocumentFilter {
#[serde(skip_serializing_if = "Option::is_none")]
pub language: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub scheme: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pattern: Option<String>,
}
pub type DocumentSelector = Vec<DocumentFilter>;
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InitializeParams {
pub process_id: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[deprecated(note = "Use `root_uri` instead when possible")]
pub root_path: Option<String>,
#[serde(default)]
pub root_uri: Option<Url>,
#[serde(skip_serializing_if = "Option::is_none")]
pub initialization_options: Option<Value>,
pub capabilities: ClientCapabilities,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub trace: Option<TraceOption>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_folders: Option<Vec<WorkspaceFolder>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub client_info: Option<ClientInfo>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct ClientInfo {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Debug, PartialEq, Clone, Copy, Deserialize, Serialize)]
pub struct InitializedParams {}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)]
pub enum TraceOption {
#[serde(rename = "off")]
Off,
#[serde(rename = "messages")]
Messages,
#[serde(rename = "verbose")]
Verbose,
}
impl Default for TraceOption {
fn default() -> TraceOption {
TraceOption::Off
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct GenericRegistrationOptions {
#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,
#[serde(flatten)]
pub options: GenericOptions,
#[serde(flatten)]
pub static_registration_options: StaticRegistrationOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct GenericOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct GenericParams {
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GenericCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GotoCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
pub link_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceEditCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub document_changes: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub resource_operations: Option<Vec<ResourceOperationKind>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_handling: Option<FailureHandlingKind>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_folders: Option<WorkspaceFolderCapability>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceFolderCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub supported: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub change_notifications: Option<WorkspaceFolderCapabilityChangeNotifications>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum WorkspaceFolderCapabilityChangeNotifications {
Bool(bool),
Id(String),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceFolder {
pub uri: Url,
pub name: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DidChangeWorkspaceFoldersParams {
pub event: WorkspaceFoldersChangeEvent,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceFoldersChangeEvent {
pub added: Vec<WorkspaceFolder>,
pub removed: Vec<WorkspaceFolder>,
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)]
#[serde(rename_all = "lowercase")]
pub enum ResourceOperationKind {
Create,
Rename,
Delete,
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Copy, Clone)]
#[serde(rename_all = "camelCase")]
pub enum FailureHandlingKind {
Abort,
Transactional,
TextOnlyTransactional,
Undo,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SymbolKindCapability {
pub value_set: Option<Vec<SymbolKind>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SymbolCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub symbol_kind: Option<SymbolKindCapability>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub apply_edit: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_edit: Option<WorkspaceEditCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub did_change_configuration: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub did_change_watched_files: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub symbol: Option<SymbolCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub execute_command: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_folders: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub configuration: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SynchronizationCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub will_save: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub will_save_wait_until: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub did_save: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionItemCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub snippet_support: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub commit_characters_support: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub documentation_format: Option<Vec<MarkupKind>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated_support: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub preselect_support: Option<bool>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "TagSupport::deserialize_compat"
)]
pub tag_support: Option<TagSupport<CompletionItemTag>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg(feature = "proposed")]
pub insert_replace_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum CompletionItemTag {
Deprecated = 1,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionItemKindCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub value_set: Option<Vec<CompletionItemKind>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HoverCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_format: Option<Vec<MarkupKind>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completion_item: Option<CompletionItemCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completion_item_kind: Option<CompletionItemKindCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignatureInformationSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub documentation_format: Option<Vec<MarkupKind>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameter_information: Option<ParameterInformationSettings>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ParameterInformationSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub label_offset_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignatureHelpCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature_information: Option<SignatureInformationSettings>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PublishDiagnosticsCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub related_information: Option<bool>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "TagSupport::deserialize_compat"
)]
pub tag_support: Option<TagSupport<DiagnosticTag>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TagSupport<T> {
pub value_set: Vec<T>,
}
impl<T> TagSupport<T> {
fn deserialize_compat<'de, S>(serializer: S) -> Result<Option<TagSupport<T>>, S::Error>
where
S: serde::Deserializer<'de>,
T: serde::Deserialize<'de>,
{
Ok(
match Option::<Value>::deserialize(serializer).map_err(serde::de::Error::custom)? {
Some(Value::Bool(false)) => None,
Some(Value::Bool(true)) => Some(TagSupport { value_set: vec![] }),
Some(other) => {
Some(TagSupport::<T>::deserialize(other).map_err(serde::de::Error::custom)?)
}
None => None,
},
)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub synchronization: Option<SynchronizationCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completion: Option<CompletionCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hover: Option<HoverCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature_help: Option<SignatureHelpCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub references: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_highlight: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_symbol: Option<DocumentSymbolCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub formatting: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub range_formatting: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub on_type_formatting: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub declaration: Option<GotoCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub definition: Option<GotoCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub type_definition: Option<GotoCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub implementation: Option<GotoCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code_action: Option<CodeActionCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code_lens: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_link: Option<DocumentLinkCapabilities>,
#[serde(skip_serializing_if = "Option::is_none")]
pub color_provider: Option<GenericCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rename: Option<RenameCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub publish_diagnostics: Option<PublishDiagnosticsCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub folding_range: Option<FoldingRangeCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg(feature = "proposed")]
pub semantic_highlighting_capabilities: Option<SemanticHighlightingClientCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg(feature = "proposed")]
pub semantic_tokens: Option<SemanticTokensClientCapabilities>,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WindowClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub work_done_progress: Option<bool>,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace: Option<WorkspaceClientCapabilities>,
#[serde(skip_serializing_if = "Option::is_none")]
pub text_document: Option<TextDocumentClientCapabilities>,
#[serde(skip_serializing_if = "Option::is_none")]
pub window: Option<WindowClientCapabilities>,
#[serde(skip_serializing_if = "Option::is_none")]
pub experimental: Option<Value>,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InitializeResult {
pub capabilities: ServerCapabilities,
#[serde(skip_serializing_if = "Option::is_none")]
pub server_info: Option<ServerInfo>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct ServerInfo {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct InitializeError {
pub retry: bool,
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum TextDocumentSyncKind {
None = 0,
Full = 1,
Incremental = 2,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub resolve_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_characters: Option<Vec<String>>,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignatureHelpOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_characters: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub retrigger_characters: Option<Vec<String>>,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct SignatureHelpRegistrationOptions {
#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum SignatureHelpTriggerKind {
Invoked = 1,
TriggerCharacter = 2,
ContentChange = 3,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignatureHelpParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<SignatureHelpContext>,
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignatureHelpContext {
pub trigger_kind: SignatureHelpTriggerKind,
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_character: Option<String>,
pub is_retrigger: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub active_signature_help: Option<SignatureHelp>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLensOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub resolve_provider: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentOnTypeFormattingOptions {
pub first_trigger_character: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub more_trigger_character: Option<Vec<String>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct ExecuteCommandOptions {
pub commands: Vec<String>,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SaveOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub include_text: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentSyncOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub open_close: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub change: Option<TextDocumentSyncKind>,
#[serde(skip_serializing_if = "Option::is_none")]
pub will_save: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub will_save_wait_until: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub save: Option<SaveOptions>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum TextDocumentSyncCapability {
Kind(TextDocumentSyncKind),
Options(TextDocumentSyncOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum ImplementationProviderCapability {
Simple(bool),
Options(StaticTextDocumentRegistrationOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum TypeDefinitionProviderCapability {
Simple(bool),
Options(StaticTextDocumentRegistrationOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum ColorProviderCapability {
Simple(bool),
ColorProvider(ColorProviderOptions),
Options(StaticTextDocumentColorProviderOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum CodeActionProviderCapability {
Simple(bool),
Options(CodeActionOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeActionCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code_action_literal_support: Option<CodeActionLiteralSupport>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_preferred_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeActionLiteralSupport {
pub code_action_kind: CodeActionKindLiteralSupport,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeActionKindLiteralSupport {
pub value_set: Vec<String>,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ServerCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub text_document_sync: Option<TextDocumentSyncCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub selection_range_provider: Option<SelectionRangeProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hover_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completion_provider: Option<CompletionOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature_help_provider: Option<SignatureHelpOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub definition_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub type_definition_provider: Option<TypeDefinitionProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub implementation_provider: Option<ImplementationProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub references_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_highlight_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_symbol_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_symbol_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code_action_provider: Option<CodeActionProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code_lens_provider: Option<CodeLensOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_formatting_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_range_formatting_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_on_type_formatting_provider: Option<DocumentOnTypeFormattingOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rename_provider: Option<RenameProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_link_provider: Option<DocumentLinkOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub color_provider: Option<ColorProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub folding_range_provider: Option<FoldingRangeProviderCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub declaration_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub execute_command_provider: Option<ExecuteCommandOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace: Option<WorkspaceCapability>,
#[cfg(feature = "proposed")]
#[serde(skip_serializing_if = "Option::is_none")]
pub semantic_highlighting: Option<SemanticHighlightingServerCapability>,
#[cfg(feature = "proposed")]
#[serde(skip_serializing_if = "Option::is_none")]
pub call_hierarchy_provider: Option<CallHierarchyServerCapability>,
#[cfg(feature = "proposed")]
#[serde(skip_serializing_if = "Option::is_none")]
pub semantic_tokens_provider: Option<SemanticTokensServerCapabilities>,
#[serde(skip_serializing_if = "Option::is_none")]
pub experimental: Option<Value>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentLinkCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tooltip_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ShowMessageParams {
#[serde(rename = "type")]
pub typ: MessageType,
pub message: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum MessageType {
Error = 1,
Warning = 2,
Info = 3,
Log = 4,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ShowMessageRequestParams {
#[serde(rename = "type")]
pub typ: MessageType,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub actions: Option<Vec<MessageActionItem>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct MessageActionItem {
pub title: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct LogMessageParams {
#[serde(rename = "type")]
pub typ: MessageType,
pub message: String,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Registration {
pub id: String,
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub register_options: Option<Value>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct RegistrationParams {
pub registrations: Vec<Registration>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentRegistrationOptions {
pub document_selector: Option<DocumentSelector>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StaticRegistrationOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StaticTextDocumentRegistrationOptions {
pub document_selector: Option<DocumentSelector>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ColorProviderOptions {}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StaticTextDocumentColorProviderOptions {
pub document_selector: Option<DocumentSelector>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct Unregistration {
pub id: String,
pub method: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct UnregistrationParams {
pub unregisterations: Vec<Unregistration>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct DidChangeConfigurationParams {
pub settings: Value,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DidOpenTextDocumentParams {
pub text_document: TextDocumentItem,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DidChangeTextDocumentParams {
pub text_document: VersionedTextDocumentIdentifier,
pub content_changes: Vec<TextDocumentContentChangeEvent>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentContentChangeEvent {
#[serde(skip_serializing_if = "Option::is_none")]
pub range: Option<Range>,
#[serde(skip_serializing_if = "Option::is_none")]
pub range_length: Option<u64>,
pub text: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TextDocumentChangeRegistrationOptions {
pub document_selector: Option<DocumentSelector>,
pub sync_kind: i32,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WillSaveTextDocumentParams {
pub text_document: TextDocumentIdentifier,
pub reason: TextDocumentSaveReason,
}
#[derive(Copy, Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum TextDocumentSaveReason {
Manual = 1,
AfterDelay = 2,
FocusOut = 3,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DidCloseTextDocumentParams {
pub text_document: TextDocumentIdentifier,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DidSaveTextDocumentParams {
pub text_document: TextDocumentIdentifier,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct DidChangeWatchedFilesParams {
pub changes: Vec<FileEvent>,
}
#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum FileChangeType {
Created = 1,
Changed = 2,
Deleted = 3,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct FileEvent {
pub uri: Url,
#[serde(rename = "type")]
pub typ: FileChangeType,
}
impl FileEvent {
pub fn new(uri: Url, typ: FileChangeType) -> FileEvent {
FileEvent { uri, typ }
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)]
pub struct DidChangeWatchedFilesRegistrationOptions {
pub watchers: Vec<FileSystemWatcher>,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FileSystemWatcher {
pub glob_pattern: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<WatchKind>,
}
bitflags! {
pub struct WatchKind: u8 {
const Create = 1;
const Change = 2;
const Delete = 4;
}
}
impl<'de> serde::Deserialize<'de> for WatchKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let i = u8::deserialize(deserializer)?;
WatchKind::from_bits(i).ok_or_else(|| {
D::Error::invalid_value(de::Unexpected::Unsigned(u64::from(i)), &"Unknown flag")
})
}
}
impl serde::Serialize for WatchKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_u8(self.bits())
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct PublishDiagnosticsParams {
pub uri: Url,
pub diagnostics: Vec<Diagnostic>,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<i64>,
}
impl PublishDiagnosticsParams {
pub fn new(
uri: Url,
diagnostics: Vec<Diagnostic>,
version: Option<i64>,
) -> PublishDiagnosticsParams {
PublishDiagnosticsParams {
uri,
diagnostics,
version,
}
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct CompletionRegistrationOptions {
#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,
#[serde(flatten)]
pub completion_options: CompletionOptions,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CompletionResponse {
Array(Vec<CompletionItem>),
List(CompletionList),
}
impl From<Vec<CompletionItem>> for CompletionResponse {
fn from(items: Vec<CompletionItem>) -> Self {
CompletionResponse::Array(items)
}
}
impl From<CompletionList> for CompletionResponse {
fn from(list: CompletionList) -> Self {
CompletionResponse::List(list)
}
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionParams {
#[serde(flatten)]
pub text_document_position: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<CompletionContext>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionContext {
pub trigger_kind: CompletionTriggerKind,
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_character: Option<String>,
}
#[derive(Debug, PartialEq, Clone, Copy, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum CompletionTriggerKind {
Invoked = 1,
TriggerCharacter = 2,
TriggerForIncompleteCompletions = 3,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CompletionList {
pub is_incomplete: bool,
pub items: Vec<CompletionItem>,
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub enum Documentation {
String(String),
MarkupContent(MarkupContent),
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CompletionItem {
pub label: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<CompletionItemKind>,
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub documentation: Option<Documentation>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub preselect: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sort_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub filter_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub insert_text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub insert_text_format: Option<InsertTextFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub text_edit: Option<CompletionTextEdit>,
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_text_edits: Option<Vec<TextEdit>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command: Option<Command>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<CompletionItemTag>>,
}
impl CompletionItem {
pub fn new_simple(label: String, detail: String) -> CompletionItem {
CompletionItem {
label,
detail: Some(detail),
..Self::default()
}
}
}
#[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_repr, Deserialize_repr)]
#[repr(u8)]
pub enum InsertTextFormat {
PlainText = 1,
Snippet = 2,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HoverParams {
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct Hover {
pub contents: HoverContents,
#[serde(skip_serializing_if = "Option::is_none")]
pub range: Option<Range>,
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum HoverContents {
Scalar(MarkedString),
Array(Vec<MarkedString>),
Markup(MarkupContent),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum MarkedString {
String(String),
LanguageString(LanguageString),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct LanguageString {
pub language: String,
pub value: String,
}
impl MarkedString {
pub fn from_markdown(markdown: String) -> MarkedString {
MarkedString::String(markdown)
}
pub fn from_language_code(language: String, code_block: String) -> MarkedString {
MarkedString::LanguageString(LanguageString {
language,
value: code_block,
})
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignatureHelp {
pub signatures: Vec<SignatureInformation>,
#[serde(skip_serializing_if = "Option::is_none")]
pub active_signature: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub active_parameter: Option<i64>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct SignatureInformation {
pub label: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub documentation: Option<Documentation>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<Vec<ParameterInformation>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ParameterInformation {
pub label: ParameterLabel,
#[serde(skip_serializing_if = "Option::is_none")]
pub documentation: Option<Documentation>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum ParameterLabel {
Simple(String),
LabelOffsets([u64; 2]),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GotoDefinitionParams {
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GotoDefinitionResponse {
Scalar(Location),
Array(Vec<Location>),
Link(Vec<LocationLink>),
}
impl From<Location> for GotoDefinitionResponse {
fn from(location: Location) -> Self {
GotoDefinitionResponse::Scalar(location)
}
}
impl From<Vec<Location>> for GotoDefinitionResponse {
fn from(locations: Vec<Location>) -> Self {
GotoDefinitionResponse::Array(locations)
}
}
impl From<Vec<LocationLink>> for GotoDefinitionResponse {
fn from(locations: Vec<LocationLink>) -> Self {
GotoDefinitionResponse::Link(locations)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ReferenceParams {
#[serde(flatten)]
pub text_document_position: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
pub context: ReferenceContext,
}
#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ReferenceContext {
pub include_declaration: bool,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentHighlightParams {
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct DocumentHighlight {
pub range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<DocumentHighlightKind>,
}
#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
pub enum DocumentHighlightKind {
Text = 1,
Read = 2,
Write = 3,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentSymbolCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub symbol_kind: Option<SymbolKindCapability>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hierarchical_document_symbol_support: Option<bool>,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DocumentSymbolResponse {
Flat(Vec<SymbolInformation>),
Nested(Vec<DocumentSymbol>),
}
impl From<Vec<SymbolInformation>> for DocumentSymbolResponse {
fn from(info: Vec<SymbolInformation>) -> Self {
DocumentSymbolResponse::Flat(info)
}
}
impl From<Vec<DocumentSymbol>> for DocumentSymbolResponse {
fn from(symbols: Vec<DocumentSymbol>) -> Self {
DocumentSymbolResponse::Nested(symbols)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentSymbolParams {
pub text_document: TextDocumentIdentifier,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentSymbol {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<String>,
pub kind: SymbolKind,
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<bool>,
pub range: Range,
pub selection_range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub children: Option<Vec<DocumentSymbol>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SymbolInformation {
pub name: String,
pub kind: SymbolKind,
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecated: Option<bool>,
pub location: Location,
#[serde(skip_serializing_if = "Option::is_none")]
pub container_name: Option<String>,
}
#[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,
Unknown = 255,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct WorkspaceSymbolParams {
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
pub query: String,
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct ExecuteCommandParams {
pub command: String,
#[serde(default)]
pub arguments: Vec<Value>,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ExecuteCommandRegistrationOptions {
pub commands: Vec<String>,
#[serde(flatten)]
pub execute_command_options: ExecuteCommandOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ApplyWorkspaceEditParams {
pub edit: WorkspaceEdit,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct ApplyWorkspaceEditResponse {
pub applied: bool,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeActionParams {
pub text_document: TextDocumentIdentifier,
pub range: Range,
pub context: CodeActionContext,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
pub type CodeActionResponse = Vec<CodeActionOrCommand>;
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(untagged)]
pub enum CodeActionOrCommand {
Command(Command),
CodeAction(CodeAction),
}
impl From<Command> for CodeActionOrCommand {
fn from(comand: Command) -> Self {
CodeActionOrCommand::Command(comand)
}
}
impl From<CodeAction> for CodeActionOrCommand {
fn from(action: CodeAction) -> Self {
CodeActionOrCommand::CodeAction(action)
}
}
pub mod code_action_kind {
pub const EMPTY: &str = "";
pub const QUICKFIX: &str = "quickfix";
pub const REFACTOR: &str = "refactor";
pub const REFACTOR_EXTRACT: &str = "refactor.extract";
pub const REFACTOR_INLINE: &str = "refactor.inline";
pub const REFACTOR_REWRITE: &str = "refactor.rewrite";
pub const SOURCE: &str = "source";
pub const SOURCE_ORGANIZE_IMPORTS: &str = "source.organizeImports";
}
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct CodeAction {
pub title: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub diagnostics: Option<Vec<Diagnostic>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub edit: Option<WorkspaceEdit>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command: Option<Command>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_preferred: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct CodeActionContext {
pub diagnostics: Vec<Diagnostic>,
#[serde(skip_serializing_if = "Option::is_none")]
pub only: Option<Vec<String>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeActionOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub code_action_kinds: Option<Vec<String>>,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLensParams {
pub text_document: TextDocumentIdentifier,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct CodeLens {
pub range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub command: Option<Command>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Value>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentLinkParams {
pub text_document: TextDocumentIdentifier,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct DocumentLink {
pub range: Range,
pub target: Url,
#[serde(skip_serializing_if = "Option::is_none")]
pub tooltip: Option<String>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentFormattingParams {
pub text_document: TextDocumentIdentifier,
pub options: FormattingOptions,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FormattingOptions {
pub tab_size: u64,
pub insert_spaces: bool,
#[serde(flatten)]
pub properties: HashMap<String, FormattingProperty>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trim_trailing_whitespace: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub insert_final_newline: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trim_final_newlines: Option<bool>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum FormattingProperty {
Bool(bool),
Number(f64),
String(String),
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentRangeFormattingParams {
pub text_document: TextDocumentIdentifier,
pub range: Range,
pub options: FormattingOptions,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentOnTypeFormattingParams {
#[serde(flatten)]
pub text_document_position: TextDocumentPositionParams,
pub ch: String,
pub options: FormattingOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentOnTypeFormattingRegistrationOptions {
pub document_selector: Option<DocumentSelector>,
pub first_trigger_character: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub more_trigger_character: Option<Vec<String>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RenameParams {
#[serde(flatten)]
pub text_document_position: TextDocumentPositionParams,
pub new_name: String,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum RenameProviderCapability {
Simple(bool),
Options(RenameOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RenameOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub prepare_provider: Option<bool>,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RenameCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prepare_support: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum PrepareRenameResponse {
Range(Range),
RangeWithPlaceholder { range: Range, placeholder: String },
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentLinkOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub resolve_provider: Option<bool>,
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DocumentColorParams {
pub text_document: TextDocumentIdentifier,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ColorInformation {
pub range: Range,
pub color: Color,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Color {
pub red: f64,
pub green: f64,
pub blue: f64,
pub alpha: f64,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ColorPresentationParams {
pub text_document: TextDocumentIdentifier,
pub color: Color,
pub range: Range,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Default, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ColorPresentation {
pub label: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub text_edit: Option<TextEdit>,
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_text_edits: Option<Vec<TextEdit>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FoldingRangeParams {
pub text_document: TextDocumentIdentifier,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum FoldingRangeProviderCapability {
Simple(bool),
FoldingProvider(FoldingProviderOptions),
Options(StaticTextDocumentColorProviderOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct FoldingProviderOptions {}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FoldingRangeCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub range_limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_folding_only: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FoldingRange {
pub start_line: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub start_character: Option<u64>,
pub end_line: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub end_character: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<FoldingRangeKind>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct SelectionRangeOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct SelectionRangeRegistrationOptions {
#[serde(flatten)]
pub selection_range_options: SelectionRangeOptions,
#[serde(flatten)]
pub registration_options: StaticTextDocumentRegistrationOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum SelectionRangeProviderCapability {
Simple(bool),
Options(SelectionRangeOptions),
RegistrationOptions(SelectionRangeRegistrationOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SelectionRangeParams {
pub text_document: TextDocumentIdentifier,
pub positions: Vec<Position>,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SelectionRange {
pub range: Range,
#[serde(skip_serializing_if = "Option::is_none")]
pub parent: Option<Box<SelectionRange>>,
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum FoldingRangeKind {
Comment,
Imports,
Region,
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum MarkupKind {
PlainText,
Markdown,
}
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
pub struct MarkupContent {
pub kind: MarkupKind,
pub value: String,
}
pub type ProgressToken = NumberOrString;
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ProgressParams {
pub token: ProgressToken,
pub value: ProgressParamsValue,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub enum ProgressParamsValue {
WorkDone(WorkDoneProgress),
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressCreateParams {
pub token: ProgressToken,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressCancelParams {
pub token: ProgressToken,
}
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub work_done_progress: Option<bool>,
}
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub work_done_token: Option<ProgressToken>,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressBegin {
pub title: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub cancellable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub percentage: Option<f64>,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressReport {
#[serde(skip_serializing_if = "Option::is_none")]
pub cancellable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub percentage: Option<f64>,
}
#[derive(Debug, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressEnd {
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
}
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum WorkDoneProgress {
Begin(WorkDoneProgressBegin),
Report(WorkDoneProgressReport),
End(WorkDoneProgressEnd),
}
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PartialResultParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub partial_result_token: Option<ProgressToken>,
}
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticHighlightingClientCapability {
pub semantic_highlighting: bool,
}
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize, Clone)]
#[cfg(feature = "proposed")]
pub struct SemanticHighlightingServerCapability {
#[serde(skip_serializing_if = "Option::is_none")]
pub scopes: Option<Vec<Vec<String>>>,
}
#[derive(Debug, Eq, PartialEq, Clone)]
#[cfg(feature = "proposed")]
pub struct SemanticHighlightingToken {
pub character: u32,
pub length: u16,
pub scope: u16,
}
#[cfg(feature = "proposed")]
impl SemanticHighlightingToken {
fn deserialize_tokens<'de, D>(
deserializer: D,
) -> Result<Option<Vec<SemanticHighlightingToken>>, D::Error>
where
D: serde::Deserializer<'de>,
{
let opt_s = Option::<String>::deserialize(deserializer)?;
if let Some(s) = opt_s {
let bytes = base64::decode_config(s.as_str(), base64::STANDARD)
.map_err(|_| serde::de::Error::custom("Error parsing base64 string"))?;
let mut res = Vec::new();
for chunk in bytes.chunks_exact(8) {
res.push(SemanticHighlightingToken {
character: u32::from_be_bytes(<[u8; 4]>::try_from(&chunk[0..4]).unwrap()),
length: u16::from_be_bytes(<[u8; 2]>::try_from(&chunk[4..6]).unwrap()),
scope: u16::from_be_bytes(<[u8; 2]>::try_from(&chunk[6..8]).unwrap()),
});
}
Result::Ok(Some(res))
} else {
Result::Ok(None)
}
}
fn serialize_tokens<S>(
tokens: &Option<Vec<SemanticHighlightingToken>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
if let Some(tokens) = tokens {
let mut bytes = vec![];
for token in tokens {
bytes.extend_from_slice(&token.character.to_be_bytes());
bytes.extend_from_slice(&token.length.to_be_bytes());
bytes.extend_from_slice(&token.scope.to_be_bytes());
}
serializer.collect_str(&base64::display::Base64Display::with_config(
&bytes,
base64::STANDARD,
))
} else {
serializer.serialize_none()
}
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[cfg(feature = "proposed")]
pub struct SemanticHighlightingInformation {
pub line: i32,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "SemanticHighlightingToken::deserialize_tokens",
serialize_with = "SemanticHighlightingToken::serialize_tokens"
)]
pub tokens: Option<Vec<SemanticHighlightingToken>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticHighlightingParams {
pub text_document: VersionedTextDocumentIdentifier,
pub lines: Vec<SemanticHighlightingInformation>,
}
#[derive(Debug, Eq, PartialEq, Hash, PartialOrd, Clone, Deserialize, Serialize)]
#[cfg(feature = "proposed")]
pub struct SemanticTokenType(Cow<'static, str>);
#[cfg(feature = "proposed")]
impl SemanticTokenType {
pub const COMMENT: SemanticTokenType = SemanticTokenType::new("comment");
pub const KEYWORD: SemanticTokenType = SemanticTokenType::new("keyword");
pub const STRING: SemanticTokenType = SemanticTokenType::new("string");
pub const NUMBER: SemanticTokenType = SemanticTokenType::new("number");
pub const REGEXP: SemanticTokenType = SemanticTokenType::new("regexp");
pub const OPERATOR: SemanticTokenType = SemanticTokenType::new("operator");
pub const NAMESPACE: SemanticTokenType = SemanticTokenType::new("namespace");
pub const TYPE: SemanticTokenType = SemanticTokenType::new("type");
pub const STRUCT: SemanticTokenType = SemanticTokenType::new("struct");
pub const CLASS: SemanticTokenType = SemanticTokenType::new("class");
pub const INTERFACE: SemanticTokenType = SemanticTokenType::new("interface");
pub const ENUM: SemanticTokenType = SemanticTokenType::new("enum");
pub const TYPE_PARAMETER: SemanticTokenType = SemanticTokenType::new("typeParameter");
pub const FUNCTION: SemanticTokenType = SemanticTokenType::new("function");
pub const MEMBER: SemanticTokenType = SemanticTokenType::new("member");
pub const PROPERTY: SemanticTokenType = SemanticTokenType::new("property");
pub const MACRO: SemanticTokenType = SemanticTokenType::new("macro");
pub const VARIABLE: SemanticTokenType = SemanticTokenType::new("variable");
pub const PARAMETER: SemanticTokenType = SemanticTokenType::new("parameter");
pub const LABEL: SemanticTokenType = SemanticTokenType::new("label");
pub const fn new(tag: &'static str) -> Self {
SemanticTokenType(Cow::Borrowed(tag))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
#[cfg(feature = "proposed")]
impl From<String> for SemanticTokenType {
fn from(from: String) -> Self {
SemanticTokenType(Cow::from(from))
}
}
#[cfg(feature = "proposed")]
impl From<&'static str> for SemanticTokenType {
fn from(from: &'static str) -> Self {
SemanticTokenType::new(from)
}
}
#[derive(Debug, Eq, PartialEq, Hash, PartialOrd, Clone, Deserialize, Serialize)]
#[cfg(feature = "proposed")]
pub struct SemanticTokenModifier(Cow<'static, str>);
#[cfg(feature = "proposed")]
impl SemanticTokenModifier {
pub const DOCUMENTATION: SemanticTokenModifier = SemanticTokenModifier::new("documentation");
pub const DECLARATION: SemanticTokenModifier = SemanticTokenModifier::new("declaration");
pub const DEFINITION: SemanticTokenModifier = SemanticTokenModifier::new("definition");
pub const STATIC: SemanticTokenModifier = SemanticTokenModifier::new("static");
pub const ABSTRACT: SemanticTokenModifier = SemanticTokenModifier::new("abstract");
pub const DEPRECATED: SemanticTokenModifier = SemanticTokenModifier::new("deprecated");
pub const READONLY: SemanticTokenModifier = SemanticTokenModifier::new("readonly");
pub const fn new(tag: &'static str) -> Self {
SemanticTokenModifier(Cow::Borrowed(tag))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
#[cfg(feature = "proposed")]
impl From<String> for SemanticTokenModifier {
fn from(from: String) -> Self {
SemanticTokenModifier(Cow::from(from))
}
}
#[cfg(feature = "proposed")]
impl From<&'static str> for SemanticTokenModifier {
fn from(from: &'static str) -> Self {
SemanticTokenModifier::new(from)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensLegend {
pub token_types: Vec<SemanticTokenType>,
pub token_modifiers: Vec<SemanticTokenModifier>,
}
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default)]
#[cfg(feature = "proposed")]
pub struct SemanticToken {
pub delta_line: u32,
pub delta_start: u32,
pub length: u32,
pub token_type: u32,
pub token_modifiers_bitset: u32,
}
#[cfg(feature = "proposed")]
impl SemanticToken {
fn deserialize_tokens<'de, D>(deserializer: D) -> Result<Vec<SemanticToken>, D::Error>
where
D: serde::Deserializer<'de>,
{
let data = Vec::<u32>::deserialize(deserializer)?;
let chunks = data.chunks_exact(5);
if !chunks.remainder().is_empty() {
return Result::Err(serde::de::Error::custom("Length is not divisible by 5"));
}
Result::Ok(
chunks
.map(|chunk| SemanticToken {
delta_line: chunk[0],
delta_start: chunk[1],
length: chunk[2],
token_type: chunk[3],
token_modifiers_bitset: chunk[4],
})
.collect(),
)
}
fn serialize_tokens<S>(tokens: &[SemanticToken], serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut seq = serializer.serialize_seq(Some(tokens.len() * 5))?;
for token in tokens.iter() {
seq.serialize_element(&token.delta_line)?;
seq.serialize_element(&token.delta_start)?;
seq.serialize_element(&token.length)?;
seq.serialize_element(&token.token_type)?;
seq.serialize_element(&token.token_modifiers_bitset)?;
}
seq.end()
}
fn deserialize_tokens_opt<'de, D>(
deserializer: D,
) -> Result<Option<Vec<SemanticToken>>, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(transparent)]
struct Wrapper {
#[serde(deserialize_with = "SemanticToken::deserialize_tokens")]
tokens: Vec<SemanticToken>,
}
Ok(Option::<Wrapper>::deserialize(deserializer)?.map(|wrapper| wrapper.tokens))
}
fn serialize_tokens_opt<S>(
data: &Option<Vec<SemanticToken>>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
#[derive(Serialize)]
#[serde(transparent)]
struct Wrapper {
#[serde(serialize_with = "SemanticToken::serialize_tokens")]
tokens: Vec<SemanticToken>,
}
let opt = data.as_ref().map(|t| Wrapper { tokens: t.to_vec() });
opt.serialize(serializer)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokens {
#[serde(skip_serializing_if = "Option::is_none")]
pub result_id: Option<String>,
#[serde(
deserialize_with = "SemanticToken::deserialize_tokens",
serialize_with = "SemanticToken::serialize_tokens"
)]
pub data: Vec<SemanticToken>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensPartialResult {
#[serde(
deserialize_with = "SemanticToken::deserialize_tokens",
serialize_with = "SemanticToken::serialize_tokens"
)]
pub data: Vec<SemanticToken>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
#[cfg(feature = "proposed")]
pub enum SemanticTokensResult {
Tokens(SemanticTokens),
Partial(SemanticTokensPartialResult),
}
#[cfg(feature = "proposed")]
impl From<SemanticTokens> for SemanticTokensResult {
fn from(from: SemanticTokens) -> Self {
SemanticTokensResult::Tokens(from)
}
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensPartialResult> for SemanticTokensResult {
fn from(from: SemanticTokensPartialResult) -> Self {
SemanticTokensResult::Partial(from)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensEdit {
pub start: u32,
pub delete_count: u32,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "SemanticToken::deserialize_tokens_opt",
serialize_with = "SemanticToken::serialize_tokens_opt"
)]
pub data: Option<Vec<SemanticToken>>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
#[cfg(feature = "proposed")]
pub enum SemanticTokensEditResult {
Tokens(SemanticTokens),
TokensEdits(SemanticTokensEdit),
PartialTokens(SemanticTokensPartialResult),
PartialTokensEdit(SemanticTokensEditsPartialResult),
}
#[cfg(feature = "proposed")]
impl From<SemanticTokens> for SemanticTokensEditResult {
fn from(from: SemanticTokens) -> Self {
SemanticTokensEditResult::Tokens(from)
}
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensEdit> for SemanticTokensEditResult {
fn from(from: SemanticTokensEdit) -> Self {
SemanticTokensEditResult::TokensEdits(from)
}
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensPartialResult> for SemanticTokensEditResult {
fn from(from: SemanticTokensPartialResult) -> Self {
SemanticTokensEditResult::PartialTokens(from)
}
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensEditsPartialResult> for SemanticTokensEditResult {
fn from(from: SemanticTokensEditsPartialResult) -> Self {
SemanticTokensEditResult::PartialTokensEdit(from)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensEdits {
#[serde(skip_serializing_if = "Option::is_none")]
pub result_id: Option<String>,
pub edits: Vec<SemanticTokensEdit>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensEditsPartialResult {
pub edits: Vec<SemanticTokensEdit>,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
pub token_types: Vec<SemanticTokenType>,
pub token_modifiers: Vec<SemanticTokenModifier>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
#[cfg(feature = "proposed")]
pub enum SemanticTokensDocumentProvider {
Bool(bool),
Edits {
#[serde(skip_serializing_if = "Option::is_none")]
edits: Option<bool>,
},
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
pub legend: SemanticTokensLegend,
#[serde(skip_serializing_if = "Option::is_none")]
pub range_provider: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub document_provider: Option<SemanticTokensDocumentProvider>,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensRegistrationOptions {
#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,
#[serde(flatten)]
pub semantic_tokens_options: SemanticTokensOptions,
#[serde(flatten)]
pub static_registration_options: StaticRegistrationOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
#[cfg(feature = "proposed")]
pub enum SemanticTokensServerCapabilities {
SemanticTokensOptions(SemanticTokensOptions),
SemanticTokensRegistrationOptions(SemanticTokensRegistrationOptions),
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensOptions> for SemanticTokensServerCapabilities {
fn from(from: SemanticTokensOptions) -> Self {
SemanticTokensServerCapabilities::SemanticTokensOptions(from)
}
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensRegistrationOptions> for SemanticTokensServerCapabilities {
fn from(from: SemanticTokensRegistrationOptions) -> Self {
SemanticTokensServerCapabilities::SemanticTokensRegistrationOptions(from)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensParams {
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
pub text_document: TextDocumentIdentifier,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensEditsParams {
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
pub text_document: TextDocumentIdentifier,
pub previous_result_id: String,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct SemanticTokensRangeParams {
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
pub text_document: TextDocumentIdentifier,
pub range: Range,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
#[cfg(feature = "proposed")]
pub enum SemanticTokensRangeResult {
Tokens(SemanticTokens),
Partial(SemanticTokensPartialResult),
}
#[cfg(feature = "proposed")]
impl From<SemanticTokens> for SemanticTokensRangeResult {
fn from(tokens: SemanticTokens) -> Self {
SemanticTokensRangeResult::Tokens(tokens)
}
}
#[cfg(feature = "proposed")]
impl From<SemanticTokensPartialResult> for SemanticTokensRangeResult {
fn from(partial: SemanticTokensPartialResult) -> Self {
SemanticTokensRangeResult::Partial(partial)
}
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize_repr, Serialize_repr)]
#[repr(u8)]
#[cfg(feature = "proposed")]
pub enum SymbolTag {
Deprecated = 1,
}
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
#[cfg(feature = "proposed")]
pub enum CallHierarchyServerCapability {
Simple(bool),
Options(CallHierarchyOptions),
}
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyPrepareParams {
#[serde(flatten)]
pub text_document_position_params: TextDocumentPositionParams,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyItem {
pub name: String,
pub kind: SymbolKind,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<SymbolTag>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<String>,
pub uri: Url,
pub range: Range,
pub selection_range: Range,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyIncomingCallsParams {
pub item: CallHierarchyItem,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyIncomingCall {
pub from: CallHierarchyItem,
pub from_ranges: Vec<Range>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyOutgoingCallsParams {
pub item: CallHierarchyItem,
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
#[serde(flatten)]
pub partial_result_params: PartialResultParams,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
pub struct CallHierarchyOutgoingCall {
pub to: CallHierarchyItem,
pub from_ranges: Vec<Range>,
}
#[cfg(test)]
mod tests {
use super::*;
use serde::{Deserialize, Serialize};
fn test_serialization<SER>(ms: &SER, expected: &str)
where
SER: Serialize + for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug,
{
let json_str = serde_json::to_string(ms).unwrap();
assert_eq!(&json_str, expected);
let deserialized: SER = serde_json::from_str(&json_str).unwrap();
assert_eq!(&deserialized, ms);
}
fn test_deserialization<T>(json: &str, expected: &T)
where
T: for<'de> Deserialize<'de> + PartialEq + std::fmt::Debug,
{
let value = serde_json::from_str::<T>(json).unwrap();
assert_eq!(&value, expected);
}
#[test]
fn number_or_string() {
test_serialization(&NumberOrString::Number(123), r#"123"#);
test_serialization(&NumberOrString::String("abcd".into()), r#""abcd""#);
}
#[test]
fn marked_string() {
test_serialization(&MarkedString::from_markdown("xxx".into()), r#""xxx""#);
test_serialization(
&MarkedString::from_language_code("lang".into(), "code".into()),
r#"{"language":"lang","value":"code"}"#,
);
}
#[test]
fn language_string() {
test_serialization(
&LanguageString {
language: "LL".into(),
value: "VV".into(),
},
r#"{"language":"LL","value":"VV"}"#,
);
}
#[test]
fn workspace_edit() {
test_serialization(
&WorkspaceEdit {
changes: Some(vec![].into_iter().collect()),
document_changes: None,
},
r#"{"changes":{}}"#,
);
test_serialization(
&WorkspaceEdit {
changes: None,
document_changes: None,
},
r#"{}"#,
);
test_serialization(
&WorkspaceEdit {
changes: Some(
vec![(Url::parse("file://test").unwrap(), vec![])]
.into_iter()
.collect(),
),
document_changes: None,
},
r#"{"changes":{"file://test/":[]}}"#,
);
}
#[test]
fn formatting_options() {
test_serialization(
&FormattingOptions {
tab_size: 123,
insert_spaces: true,
properties: HashMap::new(),
trim_trailing_whitespace: None,
insert_final_newline: None,
trim_final_newlines: None,
},
r#"{"tabSize":123,"insertSpaces":true}"#,
);
test_serialization(
&FormattingOptions {
tab_size: 123,
insert_spaces: true,
properties: vec![("prop".to_string(), FormattingProperty::Number(1.0))]
.into_iter()
.collect(),
trim_trailing_whitespace: None,
insert_final_newline: None,
trim_final_newlines: None,
},
r#"{"tabSize":123,"insertSpaces":true,"prop":1.0}"#,
);
}
#[test]
fn root_uri_can_be_missing() {
serde_json::from_str::<InitializeParams>(r#"{ "capabilities": {} }"#).unwrap();
}
#[test]
fn test_watch_kind() {
test_serialization(&WatchKind::Create, "1");
test_serialization(&(WatchKind::Create | WatchKind::Change), "3");
test_serialization(
&(WatchKind::Create | WatchKind::Change | WatchKind::Delete),
"7",
);
}
#[test]
fn test_resource_operation_kind() {
test_serialization(
&vec![
ResourceOperationKind::Create,
ResourceOperationKind::Rename,
ResourceOperationKind::Delete,
],
r#"["create","rename","delete"]"#,
);
}
#[test]
fn test_code_action_response() {
test_serialization(
&vec![
CodeActionOrCommand::Command(Command {
title: "title".to_string(),
command: "command".to_string(),
arguments: None,
}),
CodeActionOrCommand::CodeAction(CodeAction {
title: "title".to_string(),
kind: Some(code_action_kind::QUICKFIX.to_owned()),
command: None,
diagnostics: None,
edit: None,
is_preferred: None,
}),
],
r#"[{"title":"title","command":"command"},{"title":"title","kind":"quickfix"}]"#,
)
}
#[cfg(feature = "proposed")]
#[test]
fn test_semantic_highlighting_information_serialization() {
test_serialization(
&SemanticHighlightingInformation {
line: 10,
tokens: Some(vec![
SemanticHighlightingToken {
character: 0x00000001,
length: 0x0002,
scope: 0x0003,
},
SemanticHighlightingToken {
character: 0x00112222,
length: 0x0FF0,
scope: 0x0202,
},
]),
},
r#"{"line":10,"tokens":"AAAAAQACAAMAESIiD/ACAg=="}"#,
);
test_serialization(
&SemanticHighlightingInformation {
line: 22,
tokens: None,
},
r#"{"line":22}"#,
);
}
#[test]
fn test_tag_support_deserialization() {
let mut empty = CompletionItemCapability::default();
empty.tag_support = None;
test_deserialization(r#"{}"#, &empty);
test_deserialization(r#"{"tagSupport": false}"#, &empty);
let mut t = CompletionItemCapability::default();
t.tag_support = Some(TagSupport { value_set: vec![] });
test_deserialization(r#"{"tagSupport": true}"#, &t);
let mut t = CompletionItemCapability::default();
t.tag_support = Some(TagSupport {
value_set: vec![CompletionItemTag::Deprecated],
});
test_deserialization(r#"{"tagSupport": {"valueSet": [1]}}"#, &t);
}
#[cfg(feature = "proposed")]
#[test]
fn test_semantic_tokens_support_serialization() {
test_serialization(
&SemanticTokens {
result_id: None,
data: vec![],
},
r#"{"data":[]}"#,
);
test_serialization(
&SemanticTokens {
result_id: None,
data: vec![SemanticToken {
delta_line: 2,
delta_start: 5,
length: 3,
token_type: 0,
token_modifiers_bitset: 3,
}],
},
r#"{"data":[2,5,3,0,3]}"#,
);
test_serialization(
&SemanticTokens {
result_id: None,
data: vec![
SemanticToken {
delta_line: 2,
delta_start: 5,
length: 3,
token_type: 0,
token_modifiers_bitset: 3,
},
SemanticToken {
delta_line: 0,
delta_start: 5,
length: 4,
token_type: 1,
token_modifiers_bitset: 0,
},
],
},
r#"{"data":[2,5,3,0,3,0,5,4,1,0]}"#,
);
}
#[cfg(feature = "proposed")]
#[test]
fn test_semantic_tokens_support_deserialization() {
test_deserialization(
r#"{"data":[]}"#,
&SemanticTokens {
result_id: None,
data: vec![],
},
);
test_deserialization(
r#"{"data":[2,5,3,0,3]}"#,
&SemanticTokens {
result_id: None,
data: vec![SemanticToken {
delta_line: 2,
delta_start: 5,
length: 3,
token_type: 0,
token_modifiers_bitset: 3,
}],
},
);
test_deserialization(
r#"{"data":[2,5,3,0,3,0,5,4,1,0]}"#,
&SemanticTokens {
result_id: None,
data: vec![
SemanticToken {
delta_line: 2,
delta_start: 5,
length: 3,
token_type: 0,
token_modifiers_bitset: 3,
},
SemanticToken {
delta_line: 0,
delta_start: 5,
length: 4,
token_type: 1,
token_modifiers_bitset: 0,
},
],
},
);
}
#[cfg(feature = "proposed")]
#[test]
#[should_panic]
fn test_semantic_tokens_support_deserialization_err() {
test_deserialization(
r#"{"data":[1]}"#,
&SemanticTokens {
result_id: None,
data: vec![],
},
);
}
#[cfg(feature = "proposed")]
#[test]
fn test_semantic_tokens_edit_support_deserialization() {
test_deserialization(
r#"{"start":0,"deleteCount":1,"data":[2,5,3,0,3,0,5,4,1,0]}"#,
&SemanticTokensEdit {
start: 0,
delete_count: 1,
data: Some(vec![
SemanticToken {
delta_line: 2,
delta_start: 5,
length: 3,
token_type: 0,
token_modifiers_bitset: 3,
},
SemanticToken {
delta_line: 0,
delta_start: 5,
length: 4,
token_type: 1,
token_modifiers_bitset: 0,
},
]),
},
);
test_deserialization(
r#"{"start":0,"deleteCount":1}"#,
&SemanticTokensEdit {
start: 0,
delete_count: 1,
data: None,
},
);
}
#[cfg(feature = "proposed")]
#[test]
fn test_semantic_tokens_edit_support_serialization() {
test_serialization(
&SemanticTokensEdit {
start: 0,
delete_count: 1,
data: Some(vec![
SemanticToken {
delta_line: 2,
delta_start: 5,
length: 3,
token_type: 0,
token_modifiers_bitset: 3,
},
SemanticToken {
delta_line: 0,
delta_start: 5,
length: 4,
token_type: 1,
token_modifiers_bitset: 0,
},
]),
},
r#"{"start":0,"deleteCount":1,"data":[2,5,3,0,3,0,5,4,1,0]}"#,
);
test_serialization(
&SemanticTokensEdit {
start: 0,
delete_count: 1,
data: None,
},
r#"{"start":0,"deleteCount":1}"#,
);
}
}