-
Notifications
You must be signed in to change notification settings - Fork 46
Add Python import tracking to code graph #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
fafd066
7f95131
b795e65
f1b3757
ad639f9
4343b59
fb68cfe
b035a86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |||||||||||||
|
|
||||||||||||||
| import tomllib | ||||||||||||||
| from ...entities import * | ||||||||||||||
| from ...entities.entity import Entity | ||||||||||||||
| from ...entities.file import File | ||||||||||||||
| from typing import Optional | ||||||||||||||
| from ..analyzer import AbstractAnalyzer | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -96,9 +98,11 @@ def resolve_type(self, files: dict[Path, File], lsp: SyncLanguageServer, file_pa | |||||||||||||
| if node.type == 'attribute': | ||||||||||||||
| node = node.child_by_field_name('attribute') | ||||||||||||||
| for file, resolved_node in self.resolve(files, lsp, file_path, path, node): | ||||||||||||||
| type_dec = self.find_parent(resolved_node, ['class_definition']) | ||||||||||||||
| if type_dec in file.entities: | ||||||||||||||
| res.append(file.entities[type_dec]) | ||||||||||||||
| decl = resolved_node | ||||||||||||||
| if decl.type not in ['class_definition', 'function_definition']: | ||||||||||||||
| decl = self.find_parent(resolved_node, ['class_definition', 'function_definition']) | ||||||||||||||
| if decl in file.entities: | ||||||||||||||
|
Comment on lines
+102
to
+104
|
||||||||||||||
| if decl.type not in ['class_definition', 'function_definition']: | |
| decl = self.find_parent(resolved_node, ['class_definition', 'function_definition']) | |
| if decl in file.entities: | |
| if decl.type != 'class_definition': | |
| decl = self.find_parent(resolved_node, ['class_definition']) | |
| if decl and decl.type == 'class_definition' and decl in file.entities: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered this, but I believe the current approach is acceptable here. The purpose of this PR is to track imports, and resolve_type() expanding to include function_definition is what enables _resolve_import_name() to resolve function imports via a single call path before falling back to resolve_method().
The risk of resolve_type() returning Function entities for base_class/parameters/return_type resolution is low in practice — the LSP resolves annotations to their actual definition, and a type annotation like x: some_function would be unusual Python. That said, splitting resolve_type into type-only and definition-generic variants is a valid improvement but better suited for a dedicated refactor PR to avoid scope creep here.
Also added explicit Entity/File imports to the Python analyzer in 1b1ef5c to match the Java analyzer pattern and resolve F405 ruff warnings.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||
| #include <stdio.h> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify stdio APIs are not used in this file before removing the include.
rg -n '^\s*#include\s*<stdio\.h>' test-project/a.c
rg -nP '\b(FILE|printf|fprintf|snprintf|puts|putchar|fopen|fclose)\b' test-project/a.cRepository: FalkorDB/code-graph Length of output: 83 Remove the unused Line 1 contains Suggested change-#include <stdio.h>
`#include` "src/ff.h"📝 Committable suggestion
Suggested change
🧰 Tools🪛 Clang (14.0.6)[error] 1-1: 'stdio.h' file not found (clang-diagnostic-error) 🤖 Prompt for AI Agents |
||||||
| #include "src/ff.h" | ||||||
|
|
||||||
|
|
||||||
| /* Create an empty intset. */ | ||||||
| intset* intsetNew(void) { | ||||||
| intset *is = zmalloc(sizeof(intset)); | ||||||
| is->encoding = intrev32ifbe(INTSET_ENC_INT16); | ||||||
| is->length = 0; | ||||||
| return is; | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package test_project; | ||
|
|
||
| public class c { | ||
|
|
||
| private int a; | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Hello, World!"); | ||
| } | ||
|
|
||
| public static void print() { | ||
| System.out.println("Hello, World!"); | ||
| } | ||
|
|
||
| public int getA() { | ||
| return a; | ||
| } | ||
|
|
||
| public void setA(int a) { | ||
| this.a = a; | ||
| } | ||
|
|
||
| public void inc() { | ||
| setA(getA() + 1); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| """Module A with a class definition.""" | ||
|
|
||
| class ClassA: | ||
| """A simple class in module A.""" | ||
|
|
||
| def method_a(self): | ||
| """A method in ClassA.""" | ||
| return "Method A" | ||
|
|
||
| def function_a(): | ||
| """A function in module A.""" | ||
| return "Function A" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| """Module B that imports from module A.""" | ||
|
|
||
| from module_a import ClassA, function_a | ||
|
|
||
| class ClassB(ClassA): | ||
| """A class that extends ClassA.""" | ||
|
|
||
| def method_b(self): | ||
| """A method in ClassB.""" | ||
| result = function_a() | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return f"Method B: {result}" | ||
Uh oh!
There was an error while loading. Please reload this page.