fix custom method error
This commit is contained in:
parent
3074eb2c09
commit
2adaed1cfc
@ -1,8 +1,12 @@
|
|||||||
|
use std::future;
|
||||||
|
use std::sync::Arc;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use tower_lsp::jsonrpc::Result;
|
use tower_lsp::jsonrpc::Result;
|
||||||
use tower_lsp::lsp_types::*;
|
use tower_lsp::lsp_types::*;
|
||||||
|
|
||||||
|
use crate::server::Backend;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct CustomRequestParams {
|
pub struct CustomRequestParams {
|
||||||
// 定义你需要的参数
|
// 定义你需要的参数
|
||||||
@ -14,8 +18,18 @@ pub struct CustomResponse {
|
|||||||
result: serde_json::Value
|
result: serde_json::Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct CustomRequest;
|
||||||
|
|
||||||
pub async fn customRequest() -> Result<i32> {
|
impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (), Result<i32>> for CustomRequest {
|
||||||
|
type Future = future::Ready<Result<i32>>;
|
||||||
|
|
||||||
|
fn invoke(&self, _server: &'a Arc<Backend>, _params: ()) -> Self::Future {
|
||||||
|
future::ready(customRequest())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn customRequest() -> Result<i32> {
|
||||||
// let command = params[0].clone();
|
// let command = params[0].clone();
|
||||||
// let message = String::from("receive command: ") + &command;
|
// let message = String::from("receive command: ") + &command;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
use custom_request::customRequest;
|
use custom_request::CustomRequest;
|
||||||
use log::info;
|
use log::info;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
@ -36,7 +36,7 @@ async fn main() {
|
|||||||
// let (service, socket) = LspService::new(|client| Arc::new(Backend::new(client, log_handle)));
|
// let (service, socket) = LspService::new(|client| Arc::new(Backend::new(client, log_handle)));
|
||||||
|
|
||||||
let (service, socket) = LspService::build(|client| Arc::new(Backend::new(client, log_handle)))
|
let (service, socket) = LspService::build(|client| Arc::new(Backend::new(client, log_handle)))
|
||||||
.custom_method("custom/request", customRequest)
|
.custom_method("custom/request", CustomRequest)
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
Server::new(stdin, stdout, socket)
|
Server::new(stdin, stdout, socket)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user