【问题标题】:Visual Studio Code intellisence doesn't show parameters for wrapperVisual Studio Code 智能感知不显示包装器的参数
【发布时间】:2019-12-20 21:28:20
【问题描述】:

例如我有简单的功能:

def foo(a):
    '''
    Some function.
    a : int
    '''
    print(a+10)

它按我的预期工作 - 当我将鼠标放在该功能上时,我可以看到有用的帮助:

但如果我使用包装器,有关函数参数的有用信息就会丢失:

def simple_decorator(f):
    def inner(*args, **kwargs):
        '''
        Simple decorator
        '''
        res = f(*args, **kwargs)
        print('Wrapped')
        return res
    return inner

@simple_decorator
def foo(a):
    '''
    Some function.
    a : int
    '''
    print(a+10)

但是!我可以使用 Ctrl + 鼠标悬停功能查看信息:

这种方式仍然无法帮助显示函数的参数 - 当我添加括号时,我再次只看到*args, **kwargs。 我也试过from functools import wraps 也不行。

是否可以让智能正常工作,显示包装函数的参数?或者可能总是同时显示它们,就像在 Ctrl+Mouse 上一样?

附:我在 GitHub 上发现了很多已关闭的问题,但仍然无法弄清楚如何解决它。例如: https://github.com/davidhalter/jedi/issues/906

【问题讨论】:

  • 我无法使用 VSC 1.37 和最新的 ms-python 扩展进行复制。也不适用于 Python 2.7 或 Python 3.6。无论有没有装饰器,我都会得到相同的提示。
  • @rioV8 我使用 VS Code 1.37.0 和 Python 扩展 2019.8.30787。并尝试了一切。我也试过禁用绝地。还是同样的问题。请出示您的代码好吗?
  • 他们一定是最近更新了,因为我使用的是 ms-python 2019.8.29288
  • @rioV8 我试过 29288 但仍然有同样的错误。你能显示你的代码吗?你用@wraps吗?
  • 我只是用装饰器复制/粘贴你的源代码

标签: python python-3.x visual-studio-code wrapper vscode-settings


【解决方案1】:

使用 Microsoft 语言服务器 0.3.59.0(测试版)对我来说效果很好:

【讨论】:

  • 感谢您的回复。您能否澄清一下:什么是 Microsoft 语言服务器以及如何使用它来修复我的 VSCode(如果可能的话:))
【解决方案2】:

试试ctrl + space^ + space

我可以解决问题

【讨论】:

    猜你喜欢
    • 2021-03-03
    • 2021-01-07
    • 2018-03-13
    • 2016-04-12
    • 2018-02-24
    • 1970-01-01
    • 2016-02-27
    • 2021-02-23
    相关资源
    最近更新 更多