Skip to content

Commit

Permalink
Merge branch 'master' into use_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes authored Mar 25, 2024
2 parents e3d0ed2 + 3e6daee commit eec068c
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 33 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
<a name="v0.95.1"></a>
### v0.95.1 (2024-03-18)




<a name="v0.95.0"></a>
## v0.95.0 (2023-12-12)




<a name="v0.94.2"></a>
### v0.94.2 (2023-12-12)




<a name="v0.94.1"></a>
### v0.94.1 (2023-08-07)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lsp-types"
version = "0.94.1"
version = "0.95.1"
authors = ["Markus Westerlind <[email protected]>", "Bruno Medeiros <[email protected]>"]
edition = "2018"
description = "Types for interaction with a language server, using VSCode's Language Server Protocol"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Supports Language Server Protocol (LSP) version 3.16.0.
Proposed 3.17 features can be activated using the `proposed` feature flag.
- **NOTE** that these are unstable and may change between releases.

## Contributing

If you are making a change which adds, removes or modifies the LSP API it is highly appreciated if you link to the spec where this change is described. This gives context to whether the change should be an experimental addition and lets the reviewer double check the changes easily against the spec.

## Links

[Stable Protocol reference](https://github.com/microsoft/language-server-protocol/tree/gh-pages/_specifications/lsp/3.17/specification.md)
Expand Down
64 changes: 41 additions & 23 deletions src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,53 @@
//! There are other error codes that are defined in the
//! [JSON RPC specification](https://www.jsonrpc.org/specification#error_object).
// This is the start range of LSP reserved error codes.
// It doesn't denote a real error code.
//
// @since 3.16.0
/// Defined in the LSP specification but in the range reserved for JSON-RPC error codes,
/// namely the -32099 to -32000 "Reserved for implementation-defined server-errors." range.
/// The code has, nonetheless, been left in this range for backwards compatibility reasons.
pub const SERVER_NOT_INITIALIZED: i64 = -32002;

/// Defined in the LSP specification but in the range reserved for JSON-RPC error codes,
/// namely the -32099 to -32000 "Reserved for implementation-defined server-errors." range.
/// The code has, nonetheless, left in this range for backwards compatibility reasons.
pub const UNKNOWN_ERROR_CODE: i64 = -32001;

/// This is the start range of LSP reserved error codes.
/// It doesn't denote a real error code.
///
/// @since 3.16.0
pub const LSP_RESERVED_ERROR_RANGE_START: i64 = -32899;

// The server cancelled the request. This error code should
// only be used for requests that explicitly support being
// server cancellable.
//
// @since 3.17.0
/// A request failed but it was syntactically correct, e.g the
/// method name was known and the parameters were valid. The error
/// message should contain human readable information about why
/// the request failed.
///
/// @since 3.17.0
pub const REQUEST_FAILED: i64 = -32803;

/// The server cancelled the request. This error code should
/// only be used for requests that explicitly support being
/// server cancellable.
///
/// @since 3.17.0
pub const SERVER_CANCELLED: i64 = -32802;

// The server detected that the content of a document got
// modified outside normal conditions. A server should
// NOT send this error code if it detects a content change
// in it unprocessed messages. The result even computed
// on an older state might still be useful for the client.
//
// If a client decides that a result is not of any use anymore
// the client should cancel the request.
/// The server detected that the content of a document got
/// modified outside normal conditions. A server should
/// NOT send this error code if it detects a content change
/// in it unprocessed messages. The result even computed
/// on an older state might still be useful for the client.
///
/// If a client decides that a result is not of any use anymore
/// the client should cancel the request.
pub const CONTENT_MODIFIED: i64 = -32801;

// The client has canceled a request and a server as detected
// the cancel.
/// The client has canceled a request and a server as detected
/// the cancel.
pub const REQUEST_CANCELLED: i64 = -32800;

// This is the end range of LSP reserved error codes.
// It doesn't denote a real error code.
//
// @since 3.16.0
/// This is the end range of LSP reserved error codes.
/// It doesn't denote a real error code.
///
/// @since 3.16.0
pub const LSP_RESERVED_ERROR_RANGE_END: i64 = -32800;
162 changes: 162 additions & 0 deletions src/inline_completion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use crate::{
Command, InsertTextFormat, Range, StaticRegistrationOptions, TextDocumentPositionParams,
TextDocumentRegistrationOptions, WorkDoneProgressOptions, WorkDoneProgressParams,
};
use serde::{Deserialize, Serialize};

/// Client capabilities specific to inline completions.
///
/// @since 3.18.0
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineCompletionClientCapabilities {
/// Whether implementation supports dynamic registration for inline completion providers.
#[serde(skip_serializing_if = "Option::is_none")]
pub dynamic_registration: Option<bool>,
}

/// Inline completion options used during static registration.
///
/// @since 3.18.0
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct InlineCompletionOptions {
#[serde(flatten)]
pub work_done_progress_options: WorkDoneProgressOptions,
}

/// Inline completion options used during static or dynamic registration.
///
// @since 3.18.0
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
pub struct InlineCompletionRegistrationOptions {
#[serde(flatten)]
pub inline_completion_options: InlineCompletionOptions,

#[serde(flatten)]
pub text_document_registration_options: TextDocumentRegistrationOptions,

#[serde(flatten)]
pub static_registration_options: StaticRegistrationOptions,
}

/// A parameter literal used in inline completion requests.
///
/// @since 3.18.0
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineCompletionParams {
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,

#[serde(flatten)]
pub text_document_position: TextDocumentPositionParams,

/// Additional information about the context in which inline completions were requested.
pub context: InlineCompletionContext,
}

/// Describes how an [`InlineCompletionItemProvider`] was triggered.
///
/// @since 3.18.0
#[derive(Eq, PartialEq, Clone, Copy, Deserialize, Serialize)]
pub struct InlineCompletionTriggerKind(i32);
lsp_enum! {
impl InlineCompletionTriggerKind {
/// Completion was triggered explicitly by a user gesture.
/// Return multiple completion items to enable cycling through them.
pub const Invoked: InlineCompletionTriggerKind = InlineCompletionTriggerKind(1);

/// Completion was triggered automatically while editing.
/// It is sufficient to return a single completion item in this case.
pub const Automatic: InlineCompletionTriggerKind = InlineCompletionTriggerKind(2);
}
}

/// Describes the currently selected completion item.
///
/// @since 3.18.0
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
pub struct SelectedCompletionInfo {
/// The range that will be replaced if this completion item is accepted.
pub range: Range,
/// The text the range will be replaced with if this completion is
/// accepted.
pub text: String,
}

/// Provides information about the context in which an inline completion was
/// requested.
///
/// @since 3.18.0
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineCompletionContext {
/// Describes how the inline completion was triggered.
pub trigger_kind: InlineCompletionTriggerKind,
/// Provides information about the currently selected item in the
/// autocomplete widget if it is visible.
///
/// If set, provided inline completions must extend the text of the
/// selected item and use the same range, otherwise they are not shown as
/// preview.
/// As an example, if the document text is `console.` and the selected item
/// is `.log` replacing the `.` in the document, the inline completion must
/// also replace `.` and start with `.log`, for example `.log()`.
///
/// Inline completion providers are requested again whenever the selected
/// item changes.
#[serde(skip_serializing_if = "Option::is_none")]
pub selected_completion_info: Option<SelectedCompletionInfo>,
}

/// InlineCompletion response can be multiple completion items, or a list of completion items
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InlineCompletionResponse {
Array(Vec<InlineCompletionItem>),
List(InlineCompletionList),
}

/// Represents a collection of [`InlineCompletionItem`] to be presented in the editor.
///
/// @since 3.18.0
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct InlineCompletionList {
/// The inline completion items
pub items: Vec<InlineCompletionItem>,
}

/// An inline completion item represents a text snippet that is proposed inline
/// to complete text that is being typed.
///
/// @since 3.18.0
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InlineCompletionItem {
/// The text to replace the range with. Must be set.
/// Is used both for the preview and the accept operation.
pub insert_text: String,
/// A text that is used to decide if this inline completion should be
/// shown. When `falsy` the [`InlineCompletionItem::insertText`] is
/// used.
///
/// An inline completion is shown if the text to replace is a prefix of the
/// filter text.
#[serde(skip_serializing_if = "Option::is_none")]
pub filter_text: Option<String>,
/// The range to replace.
/// Must begin and end on the same line.
///
/// Prefer replacements over insertions to provide a better experience when
/// the user deletes typed text.
#[serde(skip_serializing_if = "Option::is_none")]
pub range: Option<Range>,
/// An optional command that is executed *after* inserting this
/// completion.
#[serde(skip_serializing_if = "Option::is_none")]
pub command: Option<Command>,
/// The format of the insert text. The format applies to the `insertText`.
/// If omitted defaults to `InsertTextFormat.PlainText`.
#[serde(skip_serializing_if = "Option::is_none")]
pub insert_text_format: Option<InsertTextFormat>,
}
33 changes: 28 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ pub use inlay_hint::*;
mod inline_value;
pub use inline_value::*;

#[cfg(feature = "proposed")]
mod inline_completion;
#[cfg(feature = "proposed")]
pub use inline_completion::*;

mod moniker;
pub use moniker::*;

Expand Down Expand Up @@ -226,7 +231,7 @@ pub type LSPArray = Vec<serde_json::Value>;

/// Position in a text document expressed as zero-based line and character offset.
/// A position is between two characters like an 'insert' cursor in a editor.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize)]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize, Hash)]
pub struct Position {
/// Line position in a document (zero-based).
pub line: u32,
Expand All @@ -246,7 +251,7 @@ impl Position {

/// A range in a text document expressed as (zero-based) start and end positions.
/// A range is comparable to a selection in an editor. Therefore the end position is exclusive.
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize)]
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default, Deserialize, Serialize, Hash)]
pub struct Range {
/// The range's start position.
pub start: Position,
Expand All @@ -261,7 +266,7 @@ impl Range {
}

/// Represents a location inside a resource, such as a line inside a text file.
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize, Hash)]
pub struct Location {
pub uri: Uri,
pub range: Range,
Expand Down Expand Up @@ -951,9 +956,8 @@ pub struct InitializeParams {
/// The rootUri of the workspace. Is null if no
/// folder is open. If both `rootPath` and `rootUri` are set
/// `rootUri` wins.
///
/// Deprecated in favour of `workspaceFolders`
#[serde(default)]
#[deprecated(note = "Use `workspace_folders` instead when possible")]
pub root_uri: Option<Uri>,

/// User provided initialization options.
Expand Down Expand Up @@ -989,6 +993,11 @@ pub struct InitializeParams {
/// @since 3.16.0
#[serde(skip_serializing_if = "Option::is_none")]
pub locale: Option<String>,

/// The LSP server may report about initialization progress to the client
/// by using the following work done token if it was passed by the client.
#[serde(flatten)]
pub work_done_progress_params: WorkDoneProgressParams,
}

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -1455,6 +1464,13 @@ pub struct TextDocumentClientCapabilities {
/// @since 3.17.0
#[serde(skip_serializing_if = "Option::is_none")]
pub diagnostic: Option<DiagnosticClientCapabilities>,

/// Capabilities specific to the `textDocument/inlineCompletion` request.
///
/// @since 3.18.0
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg(feature = "proposed")]
pub inline_completion: Option<InlineCompletionClientCapabilities>,
}

/// Where ClientCapabilities are currently empty:
Expand Down Expand Up @@ -1913,6 +1929,13 @@ pub struct ServerCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub diagnostic_provider: Option<DiagnosticServerCapabilities>,

/// The server provides inline completions.
///
/// @since 3.18.0
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg(feature = "proposed")]
pub inline_completion_provider: Option<OneOf<bool, InlineCompletionOptions>>,

/// Experimental server capabilities.
#[serde(skip_serializing_if = "Option::is_none")]
pub experimental: Option<Value>,
Expand Down
4 changes: 2 additions & 2 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
use serde::{de::DeserializeOwned, Serialize};

pub trait Notification {
type Params: DeserializeOwned + Serialize;
type Params: DeserializeOwned + Serialize + Send + Sync + 'static;
const METHOD: &'static str;
}

Expand Down Expand Up @@ -167,7 +167,7 @@ impl Notification for LogMessage {
pub enum TelemetryEvent {}

impl Notification for TelemetryEvent {
type Params = serde_json::Value;
type Params = OneOf<LSPObject, LSPArray>;
const METHOD: &'static str = "telemetry/event";
}

Expand Down
Loading

0 comments on commit eec068c

Please sign in to comment.