pybind11 モジュールがあり、そのクラスと関数の Jedi によるコード補完が必要です。私たちのアプローチは、関数の docstring を設定して__doc__
、Jedi がそれらを使用して完了できるようにすることでした。呼び出すcompletions()
と、空のリストが取得されます。Jedi は、set_debug_function 経由でも、エラーを出力しません。
モジュールへのパスを、Jedi に渡される文字列に設定します。モジュールのインポートもこの文字列に含まれます。
Jedi がカスタム C++ ライブラリのクラスと関数をオートコンプリートするにはどうすればよいでしょうか? これは一般的に使用して機能しますか__doc__
?もしそうなら、フォーマットはどのようになりますか?
更新: Dave のコメントのおかげで、問題をさらに分析することができました。次に例を示します。
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
Jedi がオブジェクト インスタンスの完了を返さないのはなぜbb
ですか? dir(bb)
シェルで動作し、次の出力を生成します。
['__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 では機能しません。それ以降のバージョンでは何かが壊れていると想定しています。