Skip to content
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

[BugReport]解析python代码,函数调用关系不完整 #12

Open
feng99 opened this issue Jan 13, 2025 · 8 comments
Open

[BugReport]解析python代码,函数调用关系不完整 #12

feng99 opened this issue Jan 13, 2025 · 8 comments

Comments

@feng99
Copy link

feng99 commented Jan 13, 2025

python版本3.6
插件版本1.22.2025.01.11_00.25
系统版本 windows10专业版
pycharm版本 2021.3.3 (Professional Edition)

源码为 test1调用了test2和test3
生成后,缺少了test2

区别 test3为self调用
test2为其他模块(目录) ,在当前.py文件的顶部有引用
from xxx import preset_api

image
image

@LinWanCen
Copy link
Owner

你是直接打开文件的话只会展示当前文件的调用关系,对着方法右键才会显示其他文件的。

@feng99
Copy link
Author

feng99 commented Jan 13, 2025

你是直接打开文件的话只会展示当前文件的调用关系,对着方法右键才会显示其他文件的。

你好, 我的使用方式正确吗? 如果不正确, 正确的是什么样的 求个截图示意下

image

@LinWanCen
Copy link
Owner

可否安装 PsiViewer 插件,点击引用处看下是不是 PyReferenceExpression,然后进入方法,看看是不是 PyFunction,调用关系查找的原理很简单,就是查找方法内的 PyReferenceExpression 然后 resolve 到 PyFunction 然后继续查找。

https://plugins.jetbrains.com/plugin/227-psiviewer

override fun callList(func: PyFunction, call: Boolean): List<PyFunction> {
return Call.find(func, call, PyReferenceExpression::class.java)
}

inline fun <reified F : PsiElement, R : PsiElement> find(func: F, call: Boolean, vararg refClass: Class<out R>) =
if (call) findRefs(PsiTreeUtil.findChildrenOfAnyType(func, *refClass)).filterIsInstance<F>()
// I don't know why cannot find usage for KotlinParser.callList in this project
else ReferencesSearch.search(func, GlobalSearchScope.projectScope(func.project)).findAll()
.mapNotNull { PsiTreeUtil.getParentOfType(it.element, F::class.java) }.distinct()

@feng99
Copy link
Author

feng99 commented Jan 13, 2025

可否安装 PsiViewer 插件,点击引用处看下是不是 PyReferenceExpression,然后进入方法,看看是不是 PyFunction,调用关系查找的原理很简单,就是查找方法内的 PyReferenceExpression 然后 resolve 到 PyFunction 然后继续查找。

https://plugins.jetbrains.com/plugin/227-psiviewer

override fun callList(func: PyFunction, call: Boolean): List<PyFunction> {
return Call.find(func, call, PyReferenceExpression::class.java)
}

inline fun <reified F : PsiElement, R : PsiElement> find(func: F, call: Boolean, vararg refClass: Class<out R>) =
if (call) findRefs(PsiTreeUtil.findChildrenOfAnyType(func, *refClass)).filterIsInstance<F>()
// I don't know why cannot find usage for KotlinParser.callList in this project
else ReferencesSearch.search(func, GlobalSearchScope.projectScope(func.project)).findAll()
.mapNotNull { PsiTreeUtil.getParentOfType(it.element, F::class.java) }.distinct()

安装了PsiViewer插件,

操作1:
在函数test1()鼠标右键,操作如截图所示
image
得到这些内容
image

操作2:
image

操作3:
image

操作4:
进入,def test2(self, device_id, collection_id): 鼠标右键点击
image
得到数据如图
image
image

@feng99
Copy link
Author

feng99 commented Jan 16, 2025

下午好, 期待您解决这个问题

@LinWanCen
Copy link
Owner

可否弄个demo给我调试下,我自己的demo没问题

Image

@feng99
Copy link
Author

feng99 commented Jan 21, 2025

可否弄个demo给我调试下,我自己的demo没问题

Image

收到, 这个项目的代码非常多 我需要一些时间 摘取一个可复现问题的案例 预计会在今天完成

@feng99
Copy link
Author

feng99 commented Jan 21, 2025

可否弄个demo给我调试下,我自己的demo没问题

Image

https://gitee.com/phpgogo/draw-graph_issues_12
复现此问题的样例代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants