@@ -20,69 +20,103 @@ pub const VERSION_CHECK_VERSION: u32 = 1;
20
20
pub const ENCODE_CLOSE_SPAN_VERSION : u32 = 2 ;
21
21
pub const HAS_GLOBAL_SPANS : u32 = 3 ;
22
22
pub 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.
24
24
pub const EXTENDED_LEAF_DATA : u32 = 5 ;
25
25
26
+ /// Current API version of the proc-macro protocol.
26
27
pub const CURRENT_API_VERSION : u32 = EXTENDED_LEAF_DATA ;
27
28
29
+ /// Represents requests sent from the client to the proc-macro-srv.
28
30
#[ derive( Debug , Serialize , Deserialize ) ]
29
31
pub enum Request {
32
+ /// Retrieves a list of macros from a given dynamic library.
30
33
/// Since [`NO_VERSION_CHECK_VERSION`]
31
34
ListMacros { dylib_path : Utf8PathBuf } ,
35
+
36
+ /// Expands a procedural macro.
32
37
/// Since [`NO_VERSION_CHECK_VERSION`]
33
38
ExpandMacro ( Box < ExpandMacro > ) ,
39
+
40
+ /// Performs an API version check between the client and the server.
34
41
/// Since [`VERSION_CHECK_VERSION`]
35
42
ApiVersionCheck { } ,
43
+
44
+ /// Sets server-specific configurations.
36
45
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
37
46
SetConfig ( ServerConfig ) ,
38
47
}
39
48
49
+ /// Defines the mode used for handling span data.
40
50
#[ derive( Copy , Clone , Default , Debug , Serialize , Deserialize ) ]
41
51
pub enum SpanMode {
52
+ /// Default mode, where spans are identified by an ID.
42
53
#[ default]
43
54
Id ,
55
+
56
+ /// Rust Analyzer-specific span handling mode.
44
57
RustAnalyzer ,
45
58
}
46
59
60
+ /// Represents responses sent from the proc-macro-srv to the client.
47
61
#[ derive( Debug , Serialize , Deserialize ) ]
48
62
pub enum Response {
63
+ /// Returns a list of available macros in a dynamic library.
49
64
/// Since [`NO_VERSION_CHECK_VERSION`]
50
65
ListMacros ( Result < Vec < ( String , ProcMacroKind ) > , String > ) ,
66
+
67
+ /// Returns result of a macro expansion.
51
68
/// Since [`NO_VERSION_CHECK_VERSION`]
52
69
ExpandMacro ( Result < FlatTree , PanicMessage > ) ,
70
+
71
+ /// Returns the API version supported by the server.
53
72
/// Since [`NO_VERSION_CHECK_VERSION`]
54
73
ApiVersionCheck ( u32 ) ,
74
+
75
+ /// Confirms the application of a configuration update.
55
76
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
56
77
SetConfig ( ServerConfig ) ,
78
+
79
+ /// Returns the result of a macro expansion, including extended span data.
57
80
/// Since [`RUST_ANALYZER_SPAN_SUPPORT`]
58
81
ExpandMacroExtended ( Result < ExpandMacroExtended , PanicMessage > ) ,
59
82
}
60
83
84
+ /// Configuration settings for the proc-macro-srv.
61
85
#[ derive( Debug , Serialize , Deserialize , Default ) ]
62
86
#[ serde( default ) ]
63
87
pub struct ServerConfig {
88
+ /// Defines how span data should be handled.
64
89
pub span_mode : SpanMode ,
65
90
}
66
91
92
+ /// Represents an extended macro expansion response, including span data mappings.
67
93
#[ derive( Debug , Serialize , Deserialize ) ]
68
94
pub struct ExpandMacroExtended {
95
+ /// The expanded syntax tree.
69
96
pub tree : FlatTree ,
97
+ /// Additional span data mappings.
70
98
pub span_data_table : Vec < u32 > ,
71
99
}
72
100
101
+ /// Represents an error message when a macro expansion results in a panic.
73
102
#[ derive( Debug , Serialize , Deserialize ) ]
74
103
pub struct PanicMessage ( pub String ) ;
75
104
105
+ /// Represents a macro expansion request sent from the client.
76
106
#[ derive( Debug , Serialize , Deserialize ) ]
77
107
pub struct ExpandMacro {
108
+ /// The path to the dynamic library containing the macro.
78
109
pub lib : Utf8PathBuf ,
79
110
/// Environment variables to set during macro expansion.
80
111
pub env : Vec < ( String , String ) > ,
112
+ /// The current working directory for the macro expansion.
81
113
pub current_dir : Option < String > ,
114
+ /// Macro expansion data, including the macro body, name and attributes.
82
115
#[ serde( flatten) ]
83
116
pub data : ExpandMacroData ,
84
117
}
85
118
119
+ /// Represents the input data required for expanding a macro.
86
120
#[ derive( Debug , Serialize , Deserialize ) ]
87
121
pub struct ExpandMacroData {
88
122
/// Argument of macro call.
@@ -103,18 +137,24 @@ pub struct ExpandMacroData {
103
137
#[ serde( skip_serializing_if = "ExpnGlobals::skip_serializing_if" ) ]
104
138
#[ serde( default ) ]
105
139
pub has_global_spans : ExpnGlobals ,
140
+ /// Table of additional span data.
106
141
#[ serde( skip_serializing_if = "Vec::is_empty" ) ]
107
142
#[ serde( default ) ]
108
143
pub span_data_table : Vec < u32 > ,
109
144
}
110
145
146
+ /// Represents global expansion settings, including span resolution.
111
147
#[ derive( Copy , Clone , Default , Debug , Serialize , Deserialize ) ]
112
148
pub struct ExpnGlobals {
149
+ /// Determines whether to serialize the expansion settings.
113
150
#[ serde( skip_serializing) ]
114
151
#[ serde( default ) ]
115
152
pub serialize : bool ,
153
+ /// Defines the `def_site` span location.
116
154
pub def_site : usize ,
155
+ /// Defines the `call_site` span location.
117
156
pub call_site : usize ,
157
+ /// Defines the `mixed_site` span location.
118
158
pub mixed_site : usize ,
119
159
}
120
160
@@ -150,9 +190,11 @@ pub trait Message: serde::Serialize + DeserializeOwned {
150
190
impl Message for Request { }
151
191
impl Message for Response { }
152
192
193
+ /// Type alias for a function that reads protocol messages from a buffered input stream.
153
194
#[ allow( type_alias_bounds) ]
154
195
type ProtocolRead < R : BufRead > =
155
196
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.
156
198
#[ allow( type_alias_bounds) ]
157
199
type ProtocolWrite < W : Write > = for <' o , ' msg > fn ( out : & ' o mut W , msg : & ' msg str ) -> io:: Result < ( ) > ;
158
200
0 commit comments