Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code completion / Intellisense not working #145

Open
RobertoRoos opened this issue Jul 1, 2024 · 4 comments
Open

Code completion / Intellisense not working #145

RobertoRoos opened this issue Jul 1, 2024 · 4 comments

Comments

@RobertoRoos
Copy link
Contributor

RobertoRoos commented Jul 1, 2024

I couldn't find a reference to this yet: it seems code completion / intellisense / etc. isn't working at all for pysoem:
image

This is in PyCharm, but the same happens in VS Code.

I imagine this is a consequence of Cython?
Maybe we could add some .pyi files for code analysis. Ideally generated from the Cython source files.

@RobertoRoos
Copy link
Contributor Author

I'm a little surprised code suggestions are also not working form a console, because __dir__ looks to be implemented correctly:
image

@RobertoRoos
Copy link
Contributor Author

One option could be create a .pyi file in the module, alongside the .pyx file. This will describe the interface to any IDE:

# file: pysoem/pysoem.pyi

class Master: ...

def find_adapters(): ...

But this would require every single object to be repeated, which isn't very DRY.
The .pyi file would be leading for documentation too, so all docs info should be moved from the source file into the interface file.

I've teste MyPy's stubgen, but it doesn't detect the contents of the pysoem package directly.

@RobertoRoos RobertoRoos changed the title Code completion / Intelisense not working for Code completion / Intellisense not working for Jul 1, 2024
@RobertoRoos RobertoRoos changed the title Code completion / Intellisense not working for Code completion / Intellisense not working Jul 25, 2024
@Michaelicious
Copy link

Michaelicious commented Aug 13, 2024

had the same issue, so i asked chatgpt to read the docs and create pyi file, so far it works.

# .\venv\Lib\site-packages\pysoem\pysoem.pyi

from typing import List, Optional, Union

class Master:
    slaves: List["CdefSlave"]
    sdo_read_timeout: int
    sdo_write_timeout: int
    
    def close(self) -> None: ...
    def config_dc(self) -> bool: ...
    def config_init(self, usetable: bool = False) -> int: ...
    def config_map(self) -> int: ...
    def config_overlap_map(self) -> int: ...
    
    @property
    def dc_time(self) -> int: ...
    
    @property
    def expected_wkc(self) -> int: ...
    
    def open(self, ifname: str, ifname_red: Optional[str] = None) -> None: ...
    def read_state(self) -> int: ...
    def receive_processdata(self, timeout: int = 2000) -> int: ...
    def send_overlap_processdata(self) -> int: ...
    def send_processdata(self) -> int: ...
    
    @property
    def state(self) -> int: ...
    
    def state_check(self, expected_state: int, timeout: int = 50000) -> int: ...
    def write_state(self) -> int: ...

class CdefSlave:
    config_func: Optional[callable]
    name: str
    id: int
    man: int
    rev: int
    
    def dc_sync(self, act: bool, sync0_cycle_time: int, sync0_shift_time: int = 0, sync1_cycle_time: Optional[int] = None) -> None: ...
    def eeprom_read(self, word_address: int, timeout: int = 20000) -> bytes: ...
    def eeprom_write(self, word_address: int, data: bytes, timeout: int = 20000) -> None: ...
    def foe_read(self, filename: str, password: int, size: int, timeout: int = 200000) -> bytes: ...
    def foe_write(self, filename: str, password: int, data: bytes, timeout: int = 200000) -> None: ...
    def mbx_receive(self) -> int: ...
    def reconfig(self, timeout: int = 500) -> int: ...
    def recover(self, timeout: int = 500) -> int: ...
    def sdo_read(self, index: int, subindex: int, size: int = 0, ca: bool = False) -> bytes: ...
    def sdo_write(self, index: int, subindex: int, data: bytes, ca: bool = False) -> None: ...

# Additional helper functions
def find_adapters() -> List["Adapter"]: ...
def al_status_code_to_string(code: int) -> str: ...

class Adapter:
    name: str
    desc: str

@RobertoRoos
Copy link
Contributor Author

With v1.1.8 this is already improved. Without the asterisk import any IDE should give code completion to functions etc.
However, docs information is not processed and is not incorporated by the IDE.

I gave a .pyi file a try, based on the sample from @Michaelicious . I moved some doc blocks from the .pyx into the .pyi too and after installing the result is good in the IDE: code completion works in full like you'd expect from a native Python package.

However, now the docs generation through Sphinx doesn't work... Apparently Sphinx cannot work with .pyi files (yet).

I'd suggest we leave this as it is. Listing of content alone is a bit improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants