gpt4 book ai didi

python - VS 代码 : How to find all references of a variable in python?

转载 作者:太空狗 更新时间:2023-10-30 00:18:21 26 4
gpt4 key购买 nike

我想要像 Find Usages 这样的 VS Code 功能在 Pycharm 中,它可以找到一个变量的所有读写。以一个简单的文件为例:

class Foo:
def __init__(self, bar):
self.bar = bar

def do_something(self):
bar1 = "hhhhh"
if bar1 == self.bar:
print("do something")

在 Pycharm 中使用 self.bar 的“Find Usages”:

Find Usages screenshot

我试过“查找所有引用文献”,但它不起作用:

Find all references screenshot

因为它没有找到 if bar1 == self.bar:

更新:我要的不是只搜索出现次数,因为它只匹配关键字,其中包括具有相同名称的其他变量以及评论中出现的次数。

更新:原来是 Microsoft python 语言服务器中的一个已知问题:github.com/microsoft/python-language-server/issues/1174

最佳答案

问题发生在我将 python 扩展 jediEnabled 选项的用户设置为 false 时:

"python.jediEnabled": false,

所以切换回默认值:

// Enables Jedi as IntelliSense engine instead of Microsoft Python Analysis Engine.
"python.jediEnabled": true,

并且“查找所有引用”在示例中有效!

可能是 Microsoft Python 分析引擎中的错误。

关于python - VS 代码 : How to find all references of a variable in python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com