Draft an expand macro recusively command
This commit is contained in:
parent
db8e58b888
commit
e3fc810b3d
13 changed files with 216 additions and 11 deletions
|
@ -33,7 +33,7 @@ pub fn lsp_formatting_options(tab_size: u32) -> lsp::FormattingOptions {
|
|||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
pub(crate) trait LspCommand: 'static + Sized + Send {
|
||||
pub trait LspCommand: 'static + Sized + Send {
|
||||
type Response: 'static + Default + Send;
|
||||
type LspRequest: 'static + Send + lsp::request::Request;
|
||||
type ProtoRequest: 'static + Send + proto::RequestMessage;
|
||||
|
|
100
crates/project2/src/lsp_ext_command.rs
Normal file
100
crates/project2/src/lsp_ext_command.rs
Normal file
|
@ -0,0 +1,100 @@
|
|||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use gpui::{AppContext, AsyncAppContext, Model};
|
||||
use language::Buffer;
|
||||
use lsp::{LanguageServer, LanguageServerId};
|
||||
use rpc::proto::{self, PeerId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{lsp_command::LspCommand, Project};
|
||||
|
||||
pub enum LspExpandMacro {}
|
||||
|
||||
impl lsp::request::Request for LspExpandMacro {
|
||||
type Params = ExpandMacroParams;
|
||||
type Result = Option<ExpandedMacro>;
|
||||
const METHOD: &'static str = "rust-analyzer/expandMacro";
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExpandMacroParams {
|
||||
pub text_document: lsp::TextDocumentIdentifier,
|
||||
pub position: lsp::Position,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExpandedMacro {
|
||||
pub name: String,
|
||||
pub expansion: String,
|
||||
}
|
||||
|
||||
pub struct ExpandMacro {}
|
||||
|
||||
// TODO kb
|
||||
#[async_trait(?Send)]
|
||||
impl LspCommand for ExpandMacro {
|
||||
type Response = ExpandedMacro;
|
||||
type LspRequest = LspExpandMacro;
|
||||
type ProtoRequest = proto::LspExtExpandMacro;
|
||||
|
||||
fn to_lsp(
|
||||
&self,
|
||||
path: &Path,
|
||||
buffer: &Buffer,
|
||||
language_server: &Arc<LanguageServer>,
|
||||
cx: &AppContext,
|
||||
) -> ExpandMacroParams {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn response_from_lsp(
|
||||
self,
|
||||
message: Option<ExpandedMacro>,
|
||||
project: Model<Project>,
|
||||
buffer: Model<Buffer>,
|
||||
server_id: LanguageServerId,
|
||||
cx: AsyncAppContext,
|
||||
) -> anyhow::Result<ExpandedMacro> {
|
||||
anyhow::bail!("TODO kb")
|
||||
}
|
||||
|
||||
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::LspExtExpandMacro {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn from_proto(
|
||||
message: Self::ProtoRequest,
|
||||
project: Model<Project>,
|
||||
buffer: Model<Buffer>,
|
||||
cx: AsyncAppContext,
|
||||
) -> anyhow::Result<Self> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn response_to_proto(
|
||||
response: ExpandedMacro,
|
||||
project: &mut Project,
|
||||
peer_id: PeerId,
|
||||
buffer_version: &clock::Global,
|
||||
cx: &mut AppContext,
|
||||
) -> proto::LspExtExpandMacroResponse {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn response_from_proto(
|
||||
self,
|
||||
message: proto::LspExtExpandMacroResponse,
|
||||
project: Model<Project>,
|
||||
buffer: Model<Buffer>,
|
||||
cx: AsyncAppContext,
|
||||
) -> anyhow::Result<ExpandedMacro> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn buffer_id_from_proto(message: &proto::LspExtExpandMacro) -> u64 {
|
||||
message.buffer_id
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
mod ignore;
|
||||
mod lsp_command;
|
||||
pub mod lsp_command;
|
||||
pub mod lsp_ext_command;
|
||||
mod prettier_support;
|
||||
pub mod project_settings;
|
||||
pub mod search;
|
||||
|
@ -172,7 +173,7 @@ struct DelayedDebounced {
|
|||
cancel_channel: Option<oneshot::Sender<()>>,
|
||||
}
|
||||
|
||||
enum LanguageServerToQuery {
|
||||
pub enum LanguageServerToQuery {
|
||||
Primary,
|
||||
Other(LanguageServerId),
|
||||
}
|
||||
|
@ -623,6 +624,7 @@ impl Project {
|
|||
client.add_model_request_handler(Self::handle_open_buffer_by_path);
|
||||
client.add_model_request_handler(Self::handle_save_buffer);
|
||||
client.add_model_message_handler(Self::handle_update_diff_base);
|
||||
client.add_model_request_handler(Self::handle_lsp_command::<lsp_ext_command::ExpandMacro>);
|
||||
}
|
||||
|
||||
pub fn local(
|
||||
|
@ -5933,7 +5935,7 @@ impl Project {
|
|||
.await;
|
||||
}
|
||||
|
||||
fn request_lsp<R: LspCommand>(
|
||||
pub fn request_lsp<R: LspCommand>(
|
||||
&self,
|
||||
buffer_handle: Model<Buffer>,
|
||||
server: LanguageServerToQuery,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue