@@ -47,30 +47,27 @@ impl flags::Scip {
47
47
48
48
let si = StaticIndex :: compute ( & analysis) ;
49
49
50
- let mut index = scip_types:: Index {
51
- metadata : Some ( scip_types:: Metadata {
52
- version : scip_types:: ProtocolVersion :: UnspecifiedProtocolVersion . into ( ) ,
53
- tool_info : Some ( scip_types:: ToolInfo {
54
- name : "rust-analyzer" . to_owned ( ) ,
55
- version : "0.1" . to_owned ( ) ,
56
- arguments : vec ! [ ] ,
57
- ..Default :: default ( )
58
- } )
59
- . into ( ) ,
60
- project_root : format ! (
61
- "file://{}" ,
62
- path. normalize( )
63
- . as_os_str( )
64
- . to_str( )
65
- . ok_or( anyhow:: anyhow!( "Unable to normalize project_root path" ) ) ?
66
- . to_string( )
67
- ) ,
68
- text_document_encoding : scip_types:: TextEncoding :: UTF8 . into ( ) ,
69
- ..Default :: default ( )
50
+ let metadata = scip_types:: Metadata {
51
+ version : scip_types:: ProtocolVersion :: UnspecifiedProtocolVersion . into ( ) ,
52
+ tool_info : Some ( scip_types:: ToolInfo {
53
+ name : "rust-analyzer" . to_owned ( ) ,
54
+ version : "0.1" . to_owned ( ) ,
55
+ arguments : vec ! [ ] ,
56
+ special_fields : Default :: default ( ) ,
70
57
} )
71
58
. into ( ) ,
72
- ..Default :: default ( )
59
+ project_root : format ! (
60
+ "file://{}" ,
61
+ path. normalize( )
62
+ . as_os_str( )
63
+ . to_str( )
64
+ . ok_or( anyhow:: anyhow!( "Unable to normalize project_root path" ) ) ?
65
+ . to_string( )
66
+ ) ,
67
+ text_document_encoding : scip_types:: TextEncoding :: UTF8 . into ( ) ,
68
+ special_fields : Default :: default ( ) ,
73
69
} ;
70
+ let mut documents = Vec :: new ( ) ;
74
71
75
72
let mut symbols_emitted: HashSet < TokenId > = HashSet :: default ( ) ;
76
73
let mut tokens_to_symbol: HashMap < TokenId , String > = HashMap :: new ( ) ;
@@ -95,53 +92,77 @@ impl flags::Scip {
95
92
endings : LineEndings :: Unix ,
96
93
} ;
97
94
98
- let mut doc = scip_types:: Document {
99
- relative_path,
100
- language : "rust" . to_string ( ) ,
101
- ..Default :: default ( )
102
- } ;
95
+ let mut occurrences = Vec :: new ( ) ;
96
+ let mut symbols = Vec :: new ( ) ;
103
97
104
- tokens. into_iter ( ) . for_each ( |( range , id) | {
98
+ tokens. into_iter ( ) . for_each ( |( text_range , id) | {
105
99
let token = si. tokens . get ( id) . unwrap ( ) ;
106
100
107
- let mut occurrence = scip_types:: Occurrence :: default ( ) ;
108
- occurrence. range = text_range_to_scip_range ( & line_index, range) ;
109
- occurrence. symbol = tokens_to_symbol
101
+ let range = text_range_to_scip_range ( & line_index, text_range) ;
102
+ let symbol = tokens_to_symbol
110
103
. entry ( id)
111
104
. or_insert_with ( || {
112
105
let symbol = token_to_symbol ( & token) . unwrap_or_else ( & mut new_local_symbol) ;
113
106
scip:: symbol:: format_symbol ( symbol)
114
107
} )
115
108
. clone ( ) ;
116
109
110
+ let mut symbol_roles = Default :: default ( ) ;
111
+
117
112
if let Some ( def) = token. definition {
118
- if def. range == range {
119
- occurrence . symbol_roles |= scip_types:: SymbolRole :: Definition as i32 ;
113
+ if def. range == text_range {
114
+ symbol_roles |= scip_types:: SymbolRole :: Definition as i32 ;
120
115
}
121
116
122
117
if symbols_emitted. insert ( id) {
123
- let mut symbol_info = scip_types:: SymbolInformation :: default ( ) ;
124
- symbol_info. symbol = occurrence. symbol . clone ( ) ;
125
- if let Some ( hover) = & token. hover {
126
- if !hover. markup . as_str ( ) . is_empty ( ) {
127
- symbol_info. documentation = vec ! [ hover. markup. as_str( ) . to_string( ) ] ;
128
- }
129
- }
130
-
131
- doc. symbols . push ( symbol_info)
118
+ let documentation = token
119
+ . hover
120
+ . as_ref ( )
121
+ . map ( |hover| hover. markup . as_str ( ) )
122
+ . filter ( |it| !it. is_empty ( ) )
123
+ . map ( |it| vec ! [ it. to_owned( ) ] ) ;
124
+ let symbol_info = scip_types:: SymbolInformation {
125
+ symbol : symbol. clone ( ) ,
126
+ documentation : documentation. unwrap_or_default ( ) ,
127
+ relationships : Vec :: new ( ) ,
128
+ special_fields : Default :: default ( ) ,
129
+ } ;
130
+
131
+ symbols. push ( symbol_info)
132
132
}
133
133
}
134
134
135
- doc. occurrences . push ( occurrence) ;
135
+ occurrences. push ( scip_types:: Occurrence {
136
+ range,
137
+ symbol,
138
+ symbol_roles,
139
+ override_documentation : Vec :: new ( ) ,
140
+ syntax_kind : Default :: default ( ) ,
141
+ diagnostics : Vec :: new ( ) ,
142
+ special_fields : Default :: default ( ) ,
143
+ } ) ;
136
144
} ) ;
137
145
138
- if doc . occurrences . is_empty ( ) {
146
+ if occurrences. is_empty ( ) {
139
147
continue ;
140
148
}
141
149
142
- index. documents . push ( doc) ;
150
+ documents. push ( scip_types:: Document {
151
+ relative_path,
152
+ language : "rust" . to_string ( ) ,
153
+ occurrences,
154
+ symbols,
155
+ special_fields : Default :: default ( ) ,
156
+ } ) ;
143
157
}
144
158
159
+ let index = scip_types:: Index {
160
+ metadata : Some ( metadata) . into ( ) ,
161
+ documents,
162
+ external_symbols : Vec :: new ( ) ,
163
+ special_fields : Default :: default ( ) ,
164
+ } ;
165
+
145
166
scip:: write_message_to_file ( "index.scip" , index)
146
167
. map_err ( |err| anyhow:: anyhow!( "Failed to write scip to file: {}" , err) ) ?;
147
168
@@ -181,7 +202,7 @@ fn new_descriptor_str(
181
202
name : name. to_string ( ) ,
182
203
disambiguator : "" . to_string ( ) ,
183
204
suffix : suffix. into ( ) ,
184
- .. Default :: default ( )
205
+ special_fields : Default :: default ( ) ,
185
206
}
186
207
}
187
208
@@ -232,11 +253,11 @@ fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
232
253
manager : "cargo" . to_string ( ) ,
233
254
name : package_name,
234
255
version : version. unwrap_or_else ( || "." . to_string ( ) ) ,
235
- .. Default :: default ( )
256
+ special_fields : Default :: default ( ) ,
236
257
} )
237
258
. into ( ) ,
238
259
descriptors,
239
- .. Default :: default ( )
260
+ special_fields : Default :: default ( ) ,
240
261
} )
241
262
}
242
263
0 commit comments