Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement signatureHelp and implementation #98

Merged
merged 4 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use futures::future;
use jsonrpc_core::{BoxFuture, Result};
use lsp_types::request::GotoImplementationResponse;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
use serde_json::Value;
use tower_lsp::lsp_types::request::GotoDefinitionResponse;
use tower_lsp::lsp_types::*;
Expand All @@ -18,6 +19,8 @@ impl LanguageServer for Backend {
type DefinitionFuture = BoxFuture<Option<GotoDefinitionResponse>>;
type TypeDefinitionFuture = BoxFuture<Option<GotoDefinitionResponse>>;
type HighlightFuture = BoxFuture<Option<Vec<DocumentHighlight>>>;
type SignatureHelpFuture = BoxFuture<Option<SignatureHelp>>;
type GotoImplementationFuture = BoxFuture<Option<GotoImplementationResponse>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved

fn initialize(&self, _: &Printer, _: InitializeParams) -> Result<InitializeResult> {
Ok(InitializeResult {
Expand Down Expand Up @@ -125,6 +128,14 @@ impl LanguageServer for Backend {
fn document_highlight(&self, _: TextDocumentPositionParams) -> Self::HighlightFuture {
Box::new(future::ok(None))
}

fn signature_help(&self, _: TextDocumentPositionParams) -> Self::SignatureHelpFuture {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
Box::new(future::ok(None))
}

fn goto_implementation(&self, _: TextDocumentPositionParams) -> Self::GotoImplementationFuture {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
Box::new(future::ok(None))
}
}

fn main() {
Expand Down
18 changes: 18 additions & 0 deletions src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ pub trait LanguageServerCore {

#[rpc(name = "textDocument/documentHighlight", raw_params)]
fn document_highlight(&self, params: Params) -> BoxFuture<Option<Vec<DocumentHighlight>>>;

#[rpc(name = "textDocument/signatureHelp", raw_params)]
fn signature_help(&self, params: Params) -> BoxFuture<Option<SignatureHelp>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved

#[rpc(name = "textDocument/implementation", raw_params)]
fn goto_implementation(&self, params: Params) -> BoxFuture<Option<GotoImplementationResponse>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
}

/// Wraps the language server backend and provides a `Printer` for sending notifications.
Expand Down Expand Up @@ -270,6 +276,18 @@ impl<T: LanguageServer> LanguageServerCore for Delegate<T> {
Box::new(self.server.document_highlight(p))
})
}

fn signature_help(&self, params: Params) -> BoxFuture<Option<SignatureHelp>> {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
self.delegate_request::<SignatureHelpRequest, _>(params, |p| {
Box::new(self.server.signature_help(p))
})
}

fn goto_implementation(&self, params: Params) -> BoxFuture<Option<GotoImplementationResponse>> {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
self.delegate_request::<GotoImplementation, _>(params, |p| {
Box::new(self.server.goto_implementation(p))
})
}
}

/// Error response returned for every request received before the server is initialized.
Expand Down
70 changes: 62 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! # use futures::future;
//! # use jsonrpc_core::{BoxFuture, Result};
//! # use serde_json::Value;
//! # use tower_lsp::lsp_types::request::GotoDefinitionResponse;
//! # use tower_lsp::lsp_types::request::{GotoDefinitionResponse, GotoImplementationResponse};
//! # use tower_lsp::lsp_types::*;
//! # use tower_lsp::{LanguageServer, LspService, Printer, Server};
//! #
Expand All @@ -25,6 +25,9 @@
//! type DefinitionFuture = BoxFuture<Option<GotoDefinitionResponse>>;
//! type TypeDefinitionFuture = BoxFuture<Option<GotoDefinitionResponse>>;
//! type HighlightFuture = BoxFuture<Option<Vec<DocumentHighlight>>>;
//! type SignatureHelpFuture = BoxFuture<Option<SignatureHelp>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
//! type GotoImplementationFuture = BoxFuture<Option<GotoImplementationResponse>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
//!
//!
//! fn initialize(&self, _: &Printer, _: InitializeParams) -> Result<InitializeResult> {
//! Ok(InitializeResult::default())
Expand Down Expand Up @@ -69,6 +72,14 @@
//! fn document_highlight(&self, _: TextDocumentPositionParams) -> Self::HighlightFuture {
//! Box::new(future::ok(None))
//! }
//!
//! fn signature_help(&self,params: TextDocumentPositionParams) -> Self::SignatureHelpFuture {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
//! Box::new(future::ok(None))
//! }
//!
//! fn goto_implementation(&self,params: TextDocumentPositionParams) -> Self::GotoImplementationFuture {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
//! Box::new(future::ok(None))
//! }
//! }
//!
//! fn main() {
Expand Down Expand Up @@ -98,7 +109,7 @@ pub use self::stdio::Server;

use futures::Future;
use jsonrpc_core::{Error, Result};
use lsp_types::request::GotoDefinitionResponse;
use lsp_types::request::{GotoDefinitionResponse, GotoImplementationResponse};
use lsp_types::*;
use serde_json::Value;

Expand Down Expand Up @@ -133,6 +144,11 @@ pub trait LanguageServer: Send + Sync + 'static {
type TypeDefinitionFuture: Future<Item = Option<GotoDefinitionResponse>, Error = Error> + Send;
/// Response returned when a document highlight action is requested.
type HighlightFuture: Future<Item = Option<Vec<DocumentHighlight>>, Error = Error> + Send;
/// Response returned when a signature help action is requested.
type SignatureHelpFuture: Future<Item = Option<SignatureHelp>, Error = Error> + Send;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
/// Response returned when a goto implementation action is requested.
type GotoImplementationFuture: Future<Item = Option<GotoImplementationResponse>, Error = Error>
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
+ Send;

/// The [`initialize`] request is the first request sent from the client to the server.
///
Expand Down Expand Up @@ -290,7 +306,7 @@ pub trait LanguageServer: Send + Sync + 'static {
/// field to `true` in the [`initialize`] method:
///
/// ```text
/// InitializeParams::capabilities::text_document::definition::link_support
/// InitializeParams::capabilities::text_document::declaration::link_support
/// ```
///
/// [`textDocument/declaration`]: https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_declaration
Expand Down Expand Up @@ -322,7 +338,7 @@ pub trait LanguageServer: Send + Sync + 'static {
/// field to `true` in the [`initialize`] method:
///
/// ```text
/// InitializeParams::capabilities::text_document::definition::link_support
/// InitializeParams::capabilities::text_document::type_definition::link_support
/// ```
///
/// [`textDocument/typeDefinition`]: https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_typeDefinition
Expand All @@ -344,6 +360,31 @@ pub trait LanguageServer: Send + Sync + 'static {
///
/// [`textDocument/documentHighlight`]: https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_documentHighlight
fn document_highlight(&self, params: TextDocumentPositionParams) -> Self::HighlightFuture;

/// The [`textDocument/signatureHelp`] request is sent from the client to the server to request
/// signature information at a given cursor position.
///
/// [`textDocument/signatureHelp`]: https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_signatureHelp
fn signature_help(&self, params: TextDocumentPositionParams) -> Self::SignatureHelpFuture;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved

/// The [`textDocument/implementation`] request is sent from the client to the server to resolve
/// the implementation location of a symbol at a given text document position.
///
/// The result type [`GotoImplementationResponse::Link`] got introduced with version 3.14.0 and
/// requires client-side support. It can be returned if the client set the following
/// field to `true` in the [`initialize`] method:
///
/// ```text
/// InitializeParams::capabilities::text_document::implementation::link_support
/// ```
///
/// [`textDocument/implementation`]: https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_implementation
/// [`GotoImplementationResponse::Link`]: https://docs.rs/lsp-types/0.63.1/lsp_types/request/enum.GotoDefinitionResponse.html
/// [`initialize`]: #tymethod.initialize
fn goto_implementation(
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
&self,
params: TextDocumentPositionParams,
) -> Self::GotoImplementationFuture;
}

impl<S: ?Sized + LanguageServer> LanguageServer for Box<S> {
Expand All @@ -356,6 +397,8 @@ impl<S: ?Sized + LanguageServer> LanguageServer for Box<S> {
type DefinitionFuture = S::DefinitionFuture;
type TypeDefinitionFuture = S::TypeDefinitionFuture;
type HighlightFuture = S::HighlightFuture;
type SignatureHelpFuture = S::SignatureHelpFuture;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
type GotoImplementationFuture = S::GotoImplementationFuture;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved

fn initialize(&self, printer: &Printer, params: InitializeParams) -> Result<InitializeResult> {
(**self).initialize(printer, params)
Expand Down Expand Up @@ -389,10 +432,6 @@ impl<S: ?Sized + LanguageServer> LanguageServer for Box<S> {
(**self).execute_command(p, params)
}

fn completion(&self, params: CompletionParams) -> Self::CompletionFuture {
(**self).completion(params)
}

fn did_open(&self, printer: &Printer, params: DidOpenTextDocumentParams) {
(**self).did_open(printer, params);
}
Expand All @@ -409,6 +448,10 @@ impl<S: ?Sized + LanguageServer> LanguageServer for Box<S> {
(**self).did_close(printer, params);
}

fn completion(&self, params: CompletionParams) -> Self::CompletionFuture {
(**self).completion(params)
}

fn hover(&self, params: TextDocumentPositionParams) -> Self::HoverFuture {
(**self).hover(params)
}
Expand All @@ -431,4 +474,15 @@ impl<S: ?Sized + LanguageServer> LanguageServer for Box<S> {
fn document_highlight(&self, params: TextDocumentPositionParams) -> Self::HighlightFuture {
(**self).document_highlight(params)
}

fn signature_help(&self, params: TextDocumentPositionParams) -> Self::SignatureHelpFuture {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
(**self).signature_help(params)
}

fn goto_implementation(
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
&self,
params: TextDocumentPositionParams,
) -> Self::GotoImplementationFuture {
(**self).goto_implementation(params)
}
}
15 changes: 14 additions & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Service<Incoming> for LspService {
#[cfg(test)]
mod tests {
use jsonrpc_core::{BoxFuture, Result};
use lsp_types::request::GotoDefinitionResponse;
use lsp_types::request::{GotoDefinitionResponse, GotoImplementationResponse};
use lsp_types::*;
use serde_json::Value;

Expand All @@ -192,6 +192,8 @@ mod tests {
type DefinitionFuture = BoxFuture<Option<GotoDefinitionResponse>>;
type TypeDefinitionFuture = BoxFuture<Option<GotoDefinitionResponse>>;
type HighlightFuture = BoxFuture<Option<Vec<DocumentHighlight>>>;
type SignatureHelpFuture = BoxFuture<Option<SignatureHelp>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
type GotoImplementationFuture = BoxFuture<Option<GotoImplementationResponse>>;
icsaszar marked this conversation as resolved.
Show resolved Hide resolved

fn initialize(&self, _: &Printer, _: InitializeParams) -> Result<InitializeResult> {
Ok(InitializeResult::default())
Expand Down Expand Up @@ -235,6 +237,17 @@ mod tests {
fn document_highlight(&self, _: TextDocumentPositionParams) -> Self::HighlightFuture {
Box::new(future::ok(None))
}

fn signature_help(&self, _: TextDocumentPositionParams) -> Self::SignatureHelpFuture {
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
Box::new(future::ok(None))
}

fn goto_implementation(
icsaszar marked this conversation as resolved.
Show resolved Hide resolved
&self,
_: TextDocumentPositionParams,
) -> Self::GotoImplementationFuture {
Box::new(future::ok(None))
}
}

#[test]
Expand Down