mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 246 forks source link

vscode intellisense (code autocomplete) #1179

Closed toaster-robotics closed 5 months ago

toaster-robotics commented 6 months ago

Summary

Many functions/properties are not available for autocomplete on vscode.

System configuration

vscode/pylance

Description

Many functions/properties are not available for autocomplete on vscode. For example, the function mitsuba.util.write_bitmap does not autocomplete and has no type hints. This is the same problem that pybullet has (issue link). They resolved it by generating a stub file and having that in their working directory. I attempted to generate a stub file using mypy (stub-gen) however it fails because the mitsuba variant has to be declared. I'm guess the retargetable aspect of mitsuba is the reason why some of the autocomplete doesn't work. It would be great to have this ability for the entire library. It helps a lot with coding. Otherwise there's a lot of looking up old code or searching the documents.

Below shows write_bitmap in white text, unlike render which is in yellow. This indicates an unknown function. Screenshot from 2024-05-21 22-40-24 Screenshot from 2024-05-21 22-49-26

Steps to reproduce

type out mitsuba.util.write_bitmap and try and get a type hint

toaster-robotics commented 6 months ago

I did some further digging and it seems there already is a stub file containing write_bitmap. It's under stubs/scalar_rgb_util.pyi. So maybe vscode doesn't know to look there when I retarget mitsuba to scalar_rgb?

merlinND commented 6 months ago

Hello @toaster-robotics,

I believe that the generated stubs will be much more complete in the next major version, with the transition to nanobind.

njroussel commented 5 months ago

From my experience, at the first formatting/syntax issue in any stub .pyi file the IDE's auto-completion system (ex: pyright) will halt. Well let's just fix the stub?! The issue is that we hand crafted a script to build these stub files because of the thousands of types and classes that Mitsuba contains. We've ran into many, many, many cases were we would produce some illegal syntax, I'm not surprised that some still exist. In short, although every symbol is declared in the stubs files, some are not picked up because of some error earlier in the parsing.

We are transitioning to nanobinds's stub generation tool which will be much more robust.