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

标签 python visual-studio-code pycharm

我想要像 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/

相关文章:

python - 如何在 Flask-restful 中返回错误消息?

python - Blender - 移动网格,使最小 Z 点位于 Z = 0 平面上

python - module.__init__() takes at most 2 arguments 错误在Python

python - 我如何告诉 python 启动用户默认终端?

python - 我无法在 Visual Studio Code : "There is no document formatter for ' python'-files installed. 上格式化 Python 文件”

c++ - 如何使用 Visual Studio Code 从 Visual Studio 2019 构建、调试和运行现有 C++ 解决方案 (.sln)?

visual-studio-code - Visual Studio Code SQL 结果停靠在底部

python - 为什么 pycharm 对类或函数之外的 None 给出 "expected type"警告?

Python 如何在没有 linter(PyCharm 检查) Unresolved 引用的情况下迭代 StrEnum

configuration - 为什么 PyCharm 总是将 "contents root"添加到我的 PYTHONPATH,以及什么 PYTHONPATH?