From 0a7ef1fa392c6c9e690cbea54c707f828c037ee4 Mon Sep 17 00:00:00 2001 From: granawkins Date: Mon, 27 May 2024 11:55:05 +0700 Subject: [PATCH] add context.to_ids method --- pyproject.toml | 2 +- ragdaemon/__init__.py | 2 +- ragdaemon/context.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a950023..e7ab936 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/ragdaemon/__init__.py b/ragdaemon/__init__.py index bc8c296..4910b9e 100644 --- a/ragdaemon/__init__.py +++ b/ragdaemon/__init__.py @@ -1 +1 @@ -__version__ = "0.7.2" +__version__ = "0.7.3" diff --git a/ragdaemon/context.py b/ragdaemon/context.py index 3b99ea2..c1e4d02 100644 --- a/ragdaemon/context.py +++ b/ragdaemon/context.py @@ -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)