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

Method create_node

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

Source from the content-addressed store, hash-verified

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