@@ -20,69 +20,103 @@ pub const VERSION_CHECK_VERSION: u32 = 1;
2020pub const ENCODE_CLOSE_SPAN_VERSION : u32 = 2 ;
2121pub const HAS_GLOBAL_SPANS : u32 = 3 ;
2222pub const RUST_ANALYZER_SPAN_SUPPORT : u32 = 4 ;
23- /// Whether literals encode their kind as an additional u32 field and idents their rawness as a u32 field
23+ /// Whether literals encode their kind as an additional u32 field and idents their rawness as a u32 field.
2424pub const EXTENDED_LEAF_DATA : u32 = 5 ;
2525
26+ /// Current API version of the proc-macro protocol.
2627pub const CURRENT_API_VERSION : u32 = EXTENDED_LEAF_DATA ;
2728
29+ /// Represents requests sent from the client to the proc-macro-srv.
2830#[ derive( Debug , Serialize , Deserialize ) ]
2931pub enum Request {
32+ /// Retrieves a list of macros from a given dynamic library.
3033 /// Since [`NO_VERSION_CHECK_VERSION`]
3134 ListMacros { dylib_path : Utf8PathBuf } ,
35+
36+ /// Expands a procedural macro.
3237 /// Since [`NO_VERSION_CHECK_VERSION`]
3338 ExpandMacro ( Box < ExpandMacro > ) ,
39+
40+ /// Performs an API version check between the client and the server.
3441 /// Since [`VERSION_CHECK_VERSION`]
3542 ApiVersionCheck { } ,
43+
44+ /// Sets server-specific configurations.
3645 /// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
3746 SetConfig ( ServerConfig ) ,
3847}
3948
49+ /// Defines the mode used for handling span data.
4050#[ derive( Copy , Clone , Default , Debug , Serialize , Deserialize ) ]
4151pub enum SpanMode {
52+ /// Default mode, where spans are identified by an ID.
4253 #[ default]
4354 Id ,
55+
56+ /// Rust Analyzer-specific span handling mode.
4457 RustAnalyzer ,
4558}
4659
60+ /// Represents responses sent from the proc-macro-srv to the client.
4761#[ derive( Debug , Serialize , Deserialize ) ]
4862pub enum Response {
63+ /// Returns a list of available macros in a dynamic library.
4964 /// Since [`NO_VERSION_CHECK_VERSION`]
5065 ListMacros ( Result < Vec < ( String , ProcMacroKind ) > , String > ) ,
66+
67+ /// Returns result of a macro expansion.
5168 /// Since [`NO_VERSION_CHECK_VERSION`]
5269 ExpandMacro ( Result < FlatTree , PanicMessage > ) ,
70+
71+ /// Returns the API version supported by the server.
5372 /// Since [`NO_VERSION_CHECK_VERSION`]
5473 ApiVersionCheck ( u32 ) ,
74+
75+ /// Confirms the application of a configuration update.
5576 /// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
5677 SetConfig ( ServerConfig ) ,
78+
79+ /// Returns the result of a macro expansion, including extended span data.
5780 /// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
5881 ExpandMacroExtended ( Result < ExpandMacroExtended , PanicMessage > ) ,
5982}
6083
84+ /// Configuration settings for the proc-macro-srv.
6185#[ derive( Debug , Serialize , Deserialize , Default ) ]
6286#[ serde( default ) ]
6387pub struct ServerConfig {
88+ /// Defines how span data should be handled.
6489 pub span_mode : SpanMode ,
6590}
6691
92+ /// Represents an extended macro expansion response, including span data mappings.
6793#[ derive( Debug , Serialize , Deserialize ) ]
6894pub struct ExpandMacroExtended {
95+ /// The expanded syntax tree.
6996 pub tree : FlatTree ,
97+ /// Additional span data mappings.
7098 pub span_data_table : Vec < u32 > ,
7199}
72100
101+ /// Represents an error message when a macro expansion results in a panic.
73102#[ derive( Debug , Serialize , Deserialize ) ]
74103pub struct PanicMessage ( pub String ) ;
75104
105+ /// Represents a macro expansion request sent from the client.
76106#[ derive( Debug , Serialize , Deserialize ) ]
77107pub struct ExpandMacro {
108+ /// The path to the dynamic library containing the macro.
78109 pub lib : Utf8PathBuf ,
79110 /// Environment variables to set during macro expansion.
80111 pub env : Vec < ( String , String ) > ,
112+ /// The current working directory for the macro expansion.
81113 pub current_dir : Option < String > ,
114+ /// Macro expansion data, including the macro body, name and attributes.
82115 #[ serde( flatten) ]
83116 pub data : ExpandMacroData ,
84117}
85118
119+ /// Represents the input data required for expanding a macro.
86120#[ derive( Debug , Serialize , Deserialize ) ]
87121pub struct ExpandMacroData {
88122 /// Argument of macro call.
@@ -103,18 +137,24 @@ pub struct ExpandMacroData {
103137 #[ serde( skip_serializing_if = "ExpnGlobals::skip_serializing_if" ) ]
104138 #[ serde( default ) ]
105139 pub has_global_spans : ExpnGlobals ,
140+ /// Table of additional span data.
106141 #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
107142 #[ serde( default ) ]
108143 pub span_data_table : Vec < u32 > ,
109144}
110145
146+ /// Represents global expansion settings, including span resolution.
111147#[ derive( Copy , Clone , Default , Debug , Serialize , Deserialize ) ]
112148pub struct ExpnGlobals {
149+ /// Determines whether to serialize the expansion settings.
113150 #[ serde( skip_serializing) ]
114151 #[ serde( default ) ]
115152 pub serialize : bool ,
153+ /// Defines the `def_site` span location.
116154 pub def_site : usize ,
155+ /// Defines the `call_site` span location.
117156 pub call_site : usize ,
157+ /// Defines the `mixed_site` span location.
118158 pub mixed_site : usize ,
119159}
120160
@@ -150,9 +190,11 @@ pub trait Message: serde::Serialize + DeserializeOwned {
150190impl Message for Request { }
151191impl Message for Response { }
152192
193+ /// Type alias for a function that reads protocol messages from a buffered input stream.
153194#[ allow( type_alias_bounds) ]
154195type ProtocolRead < R : BufRead > =
155196 for <' i , ' buf > fn ( inp : & ' i mut R , buf : & ' buf mut String ) -> io:: Result < Option < & ' buf String > > ;
197+ /// Type alias for a function that writes protocol messages to an output stream.
156198#[ allow( type_alias_bounds) ]
157199type ProtocolWrite < W : Write > = for <' o , ' msg > fn ( out : & ' o mut W , msg : & ' msg str ) -> io:: Result < ( ) > ;
158200
0 commit comments