1use std::{path::Path, sync::Arc};
2
3use async_trait::async_trait;
4use gpui::{AppContext, AsyncAppContext, Model};
5use language::Buffer;
6use lsp::{LanguageServer, LanguageServerId};
7use rpc::proto::{self, PeerId};
8use serde::{Deserialize, Serialize};
9
10use crate::{lsp_command::LspCommand, Project};
11
12pub enum LspExpandMacro {}
13
14impl lsp::request::Request for LspExpandMacro {
15 type Params = ExpandMacroParams;
16 type Result = Option<ExpandedMacro>;
17 const METHOD: &'static str = "rust-analyzer/expandMacro";
18}
19
20#[derive(Deserialize, Serialize, Debug)]
21#[serde(rename_all = "camelCase")]
22pub struct ExpandMacroParams {
23 pub text_document: lsp::TextDocumentIdentifier,
24 pub position: lsp::Position,
25}
26
27#[derive(Default, Deserialize, Serialize, Debug)]
28#[serde(rename_all = "camelCase")]
29pub struct ExpandedMacro {
30 pub name: String,
31 pub expansion: String,
32}
33
34pub struct ExpandMacro {}
35
36// TODO kb
37#[async_trait(?Send)]
38impl LspCommand for ExpandMacro {
39 type Response = ExpandedMacro;
40 type LspRequest = LspExpandMacro;
41 type ProtoRequest = proto::LspExtExpandMacro;
42
43 fn to_lsp(
44 &self,
45 path: &Path,
46 buffer: &Buffer,
47 language_server: &Arc<LanguageServer>,
48 cx: &AppContext,
49 ) -> ExpandMacroParams {
50 todo!()
51 }
52
53 async fn response_from_lsp(
54 self,
55 message: Option<ExpandedMacro>,
56 project: Model<Project>,
57 buffer: Model<Buffer>,
58 server_id: LanguageServerId,
59 cx: AsyncAppContext,
60 ) -> anyhow::Result<ExpandedMacro> {
61 anyhow::bail!("TODO kb")
62 }
63
64 fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::LspExtExpandMacro {
65 todo!()
66 }
67
68 async fn from_proto(
69 message: Self::ProtoRequest,
70 project: Model<Project>,
71 buffer: Model<Buffer>,
72 cx: AsyncAppContext,
73 ) -> anyhow::Result<Self> {
74 todo!()
75 }
76
77 fn response_to_proto(
78 response: ExpandedMacro,
79 project: &mut Project,
80 peer_id: PeerId,
81 buffer_version: &clock::Global,
82 cx: &mut AppContext,
83 ) -> proto::LspExtExpandMacroResponse {
84 todo!()
85 }
86
87 async fn response_from_proto(
88 self,
89 message: proto::LspExtExpandMacroResponse,
90 project: Model<Project>,
91 buffer: Model<Buffer>,
92 cx: AsyncAppContext,
93 ) -> anyhow::Result<ExpandedMacro> {
94 todo!()
95 }
96
97 fn buffer_id_from_proto(message: &proto::LspExtExpandMacro) -> u64 {
98 message.buffer_id
99 }
100}