0

我们有一个 pybind11 模块,并希望使用 Jedi 为其类和功能完成代码。我们的方法是设置__doc__函数的文档字符串,以便 Jedi 可以使用它们来完成。当我们调用时,completions()我们得到一个空列表。Jedi 没有打印错误,也不是通过 set_debug_function。

我们在传递给 Jedi 的字符串中设置模块的路径。模块的导入也包含在此字符串中。

我们需要做什么才能让 Jedi 自动完成自定义 C++ 库类和函数?这通常可以使用__doc__吗?如果可以,格式应该是什么样的?

更新:感谢戴夫的评论,我们能够进一步分析问题。下面是一个例子:

import bitbuffer
bb = bitbuffer.BitBuffer(100)
bitbuffer. # completion works for the module
bitBuffer.BitBuffer. # completion works for the class
bb. # completion does not work for the instance of the class

以下set_debug_function()是 Jedi 0.14.0 完成的输出bb.

speed: init 17.217941999435425
speed: parsed 17.218032836914062
dbg: Start: completions

  dbg: eval_node <Name: bb@5,0>@(5, 0) in <ModuleContext: @1-5 is_stub=False>
  dbg: finder.filter_name 'bb' in (<ModuleContext: @1-5 is_stub=False>): [<TreeNameDefinition: string_name=bb start_pos=(3, 0)>]@(5, 0)
   dbg: eval_expr_stmt <ExprStmt: bb = bitbuffer.BitBuffer(100)@3,0> (<Name: bb@3,0>)
    dbg: eval_node PythonNode(atom_expr, [<Name: bitbuffer@3,5>, PythonNode(trailer, [<Operator: .>, <Name: BitBuffer@3,15>]), PythonNode(trailer, [<Operator: (>, <Number: 100>, <Operator: )>])])@(3, 5) in <ModuleContext: @1-5 is_stub=False>
     dbg: eval_node <Name: bitbuffer@3,5>@(3, 5) in <ModuleContext: @1-5 is_stub=False>
     dbg: finder.filter_name 'bitbuffer' in (<ModuleContext: @1-5 is_stub=False>): [<TreeNameDefinition: string_name=bitbuffer start_pos=(1, 7)>]@(3, 0)
     speed: import (<Name: bitbuffer@1,7>,) <ModuleContext: @1-5 is_stub=False> 0.0019109249114990234

     dbg: global search_module 'bitbuffer': <CompiledObject: <module 'bitbuffer' from '/home/software/build-Debug/install/myApp/python/lib/python3.6/site-packages/bitbuffer.so'>>
     dbg: after import: S{<CompiledObject: <module 'bitbuffer' from '/home/software/build-Debug/install/myApp/python/lib/python3.6/site-packages/bitbuffer.so'>>}
     dbg: finder._names_to_types: [<TreeNameDefinition: string_name=bitbuffer start_pos=(1, 7)>] -> S{<CompiledObject: <module 'bitbuffer' from '/home/software/build-Debug/install/myApp/python/lib/python3.6/site-packages/bitbuffer.so'>>}
    dbg: eval_trailer: PythonNode(trailer, [<Operator: .>, <Name: BitBuffer@3,15>]) in S{<CompiledObject: <module 'bitbuffer' from '/home/software/build-Debug/install/myApp/python/lib/python3.6/site-packages/bitbuffer.so'>>}
    dbg: finder.filter_name 'BitBuffer' in (<CompiledObject: <module 'bitbuffer' from '/home/software/build-Debug/install/myApp/python/lib/python3.6/site-packages/bitbuffer.so'>>): [<CompiledName: (<CompiledContextName: string_name=bitbuffer>).BitBuffer>]@None
    dbg: finder._names_to_types: [<CompiledName: (<CompiledContextName: string_name=bitbuffer>).BitBuffer>] -> S{<CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>}
    dbg: eval_trailer: PythonNode(trailer, [<Operator: (>, <Number: 100>, <Operator: )>]) in S{<CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>}
    dbg: global search_module 'builtins': <CompiledObject: <module 'builtins' (built-in)>>

    dbg: execute: <CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>> <TreeArguments: <Number: 100>>
    dbg: execute result: S{<CompiledInstance of <CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>(<TreeArguments: <Number: 100>>)>} in <CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>
   dbg: eval_expr_stmt result S{<CompiledInstance of <CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>(<TreeArguments: <Number: 100>>)>}
  dbg: finder._names_to_types: [<TreeNameDefinition: string_name=bb start_pos=(3, 0)>] -> S{<CompiledInstance of <CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>(<TreeArguments: <Number: 100>>)>}
 dbg: trailer completion contexts: S{<CompiledInstance of <CompiledObject: <pybind11_builtins.pybind11_type object at 0x55be2f8f7278>>(<TreeArguments: <Number: 100>>)>}

 dbg: Start: convert contexts
 dbg: End: convert contexts
dbg: End: completions

为什么绝地不返回对象实例的完成bbdir(bb)在 shell 中工作并生成以下输出:

['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'capacity', 'clear', 'copy', 'data', 'desc', 'fill', 'from_int', 'marks', 'name', 'offset', 'pack', 'shadow', 'size', 'unpack']

更新 #2 提示: 绝地解释器能够完成我们的对象:

script = jedi.Interpreter("bb.", [locals()])
script.completions() # this works

我们得出结论,对象本身没有问题。

更新#3:

对象的自动完成适用于 jedi 0.11.1,但不适用于 0.14.0。我们假设在以后的版本中出现了问题。

4

0 回答 0