Skip to content

Commit

Permalink
add context.to_ids method
Browse files Browse the repository at this point in the history
  • Loading branch information
granawkins committed May 27, 2024
1 parent 7293397 commit 0a7ef1f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages=["ragdaemon"]

[project]
name = "ragdaemon"
version = "0.7.2"
version = "0.7.3"
description = "Generate and render a call graph for a Python project."
readme = "README.md"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion ragdaemon/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.2"
__version__ = "0.7.3"
23 changes: 23 additions & 0 deletions ragdaemon/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,26 @@ def to_refs(self) -> list[str]:
segments.append(current_segment)
refs[path] = ",".join(segments)
return [f"{path}:{ref}" for path, ref in refs.items()]

def to_ids(self) -> list[str]:
"""Return a list of ids for everything in current context.
NOTE: Returns chunks if available by default. So if a full file is added,
this will return all of the chunks ids, not the file id.
"""
ids = set()
targets = []
refs = self.to_refs()
for ref in refs:
path, lines = parse_path_ref(ref)
targets.append((path, lines))
for node, data in self.graph.nodes(data=True):
for path, lines in targets:
if node.startswith(path.as_posix()):
_, node_lines = parse_path_ref(data["ref"])
if lines is None and node_lines is None:
ids.add(node)
elif lines is not None and node_lines is not None:
if node_lines.intersection(lines):
ids.add(node)
return list(ids)

0 comments on commit 0a7ef1f

Please sign in to comment.