MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / create_node

Method create_node

codegraph-kernel/src/rustlang.rs:260–355  ·  view source on GitHub ↗
(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra)

Source from the content-addressed store, hash-verified

258 }
259
260 fn create_node(&mut self, kind: &'static str, name: &str, node: Node<'t>, extra: Extra) -> Option<u32> {
261 if name.is_empty() {
262 return None;
263 }
264 let start_line = self.line_of(node);
265 let column = self.col_of(node);
266 let id = self.node_id_allocator.generate(self.file_path, kind, name, start_line, column);
267 let end_line = node.end_position().row as u32 + 1;
268
269 let qualified = extra.qualified_name.unwrap_or_else(|| {
270 let mut parts: Vec<&str> = Vec::new();
271 for s in &self.stack {
272 if s.kind != "file" {
273 parts.push(&s.name);
274 }
275 }
276 let mut qn = parts.join("::");
277 if !qn.is_empty() {
278 qn.push_str("::");
279 }
280 qn.push_str(name);
281 qn
282 });
283
284 let mut flags = BoolFlags::default();
285 if let Some(v) = extra.is_exported {
286 flags.set(FLAG_IS_EXPORTED, v);
287 }
288 if let Some(v) = extra.is_async {
289 flags.set(FLAG_IS_ASYNC, v);
290 }
291 let name_ref = self.arena.put(name);
292 let qn_ref = self.arena.put(&qualified);
293 let id_ref = self.arena.put(&id);
294 let doc_ref = opt_str(&mut self.arena, extra.docstring.as_deref());
295 let sig_ref = opt_str(&mut self.arena, extra.signature.as_deref());
296 let decorators_ref = opt_str(&mut self.arena, extra.decorators.as_deref());
297 let ret_ref = opt_str(&mut self.arena, extra.return_type.as_deref());
298 let row = self.tables.push_node(&NodeRow {
299 kind: node_kind_index(kind).unwrap(),
300 visibility: extra.visibility.unwrap_or(0),
301 flags,
302 start_line,
303 end_line,
304 start_column: self.col_of(node),
305 end_column: self.end_col_of(node),
306 name: name_ref,
307 qualified_name: qn_ref,
308 id: id_ref,
309 docstring: doc_ref,
310 signature: sig_ref,
311 decorators: decorators_ref,
312 type_parameters: NONE_STR,
313 return_type: ret_ref,
314 extra_json: NONE_STR,
315 });
316 self.nodes_meta.push(NodeMeta { kind, name: name.to_string() });
317 self.node_ids.push(id);

Callers 7

extract_fn_or_methodMethod · 0.45
extract_interfaceMethod · 0.45
extract_aggregateMethod · 0.45
extract_enumMethod · 0.45
extract_type_aliasMethod · 0.45
extract_variableMethod · 0.45
extract_importMethod · 0.45

Calls 15

node_kind_indexFunction · 0.85
edge_kind_indexFunction · 0.85
utf16_lenFunction · 0.85
pushMethod · 0.80
push_nodeMethod · 0.80
push_edgeMethod · 0.80
mapMethod · 0.80
opt_strFunction · 0.70
putMethod · 0.65
unwrapMethod · 0.60
line_ofMethod · 0.45
col_ofMethod · 0.45

Tested by

no test coverage detected