Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/schemas/draft/relation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ This is a high-value query for:
| `source` | `ChainNode` | The resolved source symbol. |
| `target` | `ChainNode` | The resolved target symbol. |
| `chains` | `ChainNode[][]` | All paths found. Each path is a sequence of nodes. |
| `max_depth` | `number` | The maximum depth used for the search. |

The maximum depth used for the search is available as `request.max_depth`, since the response includes the original `RelationRequest`.

### ChainNode

Expand Down
19 changes: 11 additions & 8 deletions src/lsap/capability/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ async def _find_paths(
current_item, path, depth = queue.popleft()
current_key = self._item_key(current_item)

# Check if we've reached the target
if current_key == target_key:
found_chains.append(path)
continue

# Skip if we've exceeded max depth
if depth >= max_depth:
continue
Expand All @@ -117,11 +122,6 @@ async def _find_paths(
continue
visited.add(current_key)

# Check if we've reached the target
if current_key == target_key:
found_chains.append(path)
continue

# Get outgoing calls from current item
outgoing_calls = (
await call_hierarchy._request_call_hierarchy_outgoing_calls(
Expand All @@ -135,9 +135,12 @@ async def _find_paths(
# Add each outgoing call to the queue
for call in outgoing_calls:
next_item = call.to
next_node = self._to_chain_node(next_item)
next_path = path + [next_node]
queue.append((next_item, next_path, depth + 1))
next_key = self._item_key(next_item)
# Skip if already visited to prevent redundant queue entries
if next_key not in visited:
next_node = self._to_chain_node(next_item)
next_path = path + [next_node]
queue.append((next_item, next_path, depth + 1))

return found_chains

Expand Down
Loading