SD2E / opil

The Open Protocol Interface Language (OPIL) is intended as a standard language for protocol interfaces
5 stars 1 forks source link

OPIL code completion not working in VS Code #96

Open bjkeller opened 3 years ago

bjkeller commented 3 years ago

Because the OPIL classes are generated, OPIL does not work with python code completion

The following are screen caps of VS Code with completions for sbol3. and opil.

Screen Shot 2021-01-25 at 11 27 41 AM Screen Shot 2021-01-25 at 11 28 06 AM

In both cases, VS Code is showing (mostly) members of the respective packages, but for OPIL only the factory and other members that are in the opil code base are shown. Since the OPIL classes are generated they are not shown.

These screen captures are from https://github.com/aquariumbio/aquarium-opil in a VS Code dev container where I have installed opil. The resulting environment allows me to use code completion for pySBOL3, but not OPIL.

This particular configuration is somewhat convoluted, but to replicate it should be sufficient to create a virtual environment, pip install opil, start VS Code with Python extension (or some other editor able to use the virtual environment for code completion), and then edit a script with opil and sbol3 imported to see something similar.

jakebeal commented 3 years ago

@bjkeller I changed the title to be more descriptive, because when I first saw it, I thought you meant you didn't want to have code completion in OPIL.

bjkeller commented 3 years ago

Well, technically, it is working. It is just not reflective of the ontology classes

bbartley commented 3 years ago

Hi @bjkeller do you have any ideas what is required for code completion to work? In the Python interpreter, the generated classes all appear in the opil namespace:

>>> import opil
RDFLib Version: 5.0.0
>>> dir(opil)
['BooleanParameter', 'BooleanValue', 'CombinatorialDerivation', 'Component', 'Document', 'EnumeratedParameter', 'EnumeratedValue', 'ExperimentalRequest', 'Identified', 'IntegerParameter', 'IntegerValue', 'MeasureParameter', 'MeasureValue', 'Measurement', 'MeasurementType', 'Media', 'OPILFactory', 'Parameter', 'ParameterValue', 'ProtocolInterface', 'Query', 'SampleSet', 'ShaclValidator', 'Strain', 'StrateosOpilGenerator', 'StringParameter', 'StringValue', 'TimeInterval', 'TopLevel', 'URIParameter', 'URIValue', 'ValidationReport', 'VariableFeature', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'class_uri', 'generate_opil_from_strateos', 'help', 'inf', 'log', 'opil_factory', 'os', 'posixpath', 'rdflib', 'sbol', 'set_namespace', 'shacl_validator']
bjkeller commented 3 years ago

I'll look. I'm guessing that VS Code is somehow doing static analysis on the code b/c the Pylance extension is based on a static type checker

Can you see these in a different editor?

bbartley commented 3 years ago

@tramyn confirmed it doesn't work in PyCharm IDE either

bjkeller commented 3 years ago

The solution may be to add a .pyi file. See https://mypy.readthedocs.io/en/stable/stubs.html.

https://mypy.readthedocs.io/en/stable/stubgen.html

jakebeal commented 3 years ago

It looks like for PyCharm, at least, one can patch around this by generating a stub file (https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003388099-Add-dynamic-created-classes-to-autocomplete-for-pycharm-2018, https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000665110-auto-completion-for-dynamic-module-attributes-in-python).