-
Notifications
You must be signed in to change notification settings - Fork 218
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 intellisense broken in few libraries #621
Comments
I have no idea how to fix it, I guess we need to debug how VSCode's IntelliSense (or Kite as an alternative) is inspecting the objects (a Here's what I tried:
...
cls = self.__class__
for attr, meth in self.__dict__["attributes"].items():
setattr(cls, attr, meth) # should be converted to unbound method (function) and at module level: setattr(PDF, "open_pdf", DocumentKeywords.open_pdf) and I feel even with a meta-class that dynamically picks the methods and adds them to the library class won't change something.
and as you can see, only Problem is that these dynamically added methods happen at instantiation time and black magic is done to the holder instance, which confuses the static introspection. While in normal scenarios, methods (and all attributes) are collected from the actual and base classes at importing (code reading) time and inferred from there. A class definition like: class PDF(DynamicCore, DocumentKeywords, FinderKeywords, ModelKeywords): will solve IntelliSense, but we'll be running into other kind of issues as the dynamic registration wasn't designed to work like this. ❌ I'm going to mark this as "won't fix" and @mikahanninen can even close the issue if there isn't any sane solution to this. (like augmenting our own vendorized DynamicCore with a mixin in such a way it will provide to VSCode the missing methods (keywords) from every final library class adopting this pattern) |
Closing this in favor to the upstream reported Issue: robotframework/PythonLibCore#95 We can partially overcome this limitation by creating *.pyi module stubs with mypy. |
Actually it is not black magic all, PythonLibCore fully follows Robot Framework Dynamic library API. It seems that rpaframework only implements the static library API, which is the most popular API, but is not the only API available in the Robot Framework (Please note that there is actually three different library API in RF). The difference between library API is easy. From user guide: From PythonLibCore (PLC) point of view closing this issue is not correct, because PLC will only support dynamic library API. Instead this issue should be reopened and underlying problem should be fixed in the rpaframework. |
Thank you for the thorough explanations and they all make sense! But just to be sure we are highlighting correctly the pain point here, Robot Framework syntax discovery and And the same happens with every library inheriting from @aaltat Just to be sure, is there a way where you can see in VSCode the keyword documentation (docstring) when writing a robot in Python code? (while using a library inheriting from the |
I do not use VSCOde, so I am not able to answer your question. Generally speaking capabilities depends on the plugin used by in the VSCode. When looking matter from the PLC and dynamic library API point of view, there is not limitations when or how often keywords and other data from library is discovered. Plugin can do discovery every second, if that is the implementation of the plugin. But discovery should be done in the VSCode plugin side, library/PLC/dynamic library API can not push changes to VSCode direction. The best solution from user point of view, would be automatic refresh for changes. Example plugin could discover files used by the library and detect changes on them. Example, I think, it is possible to use libdoc In short, all depends on the VSCode plugin implementation, PLC and dynamic library API support your needs. |
My memory served me well source is available at least according the json schema file: https://github.com/robotframework/robotframework/blob/master/doc/schema/libdoc.json#L35 |
@cmin764 I know it's been a while since this issue was closed but I wanted to apologize and thank you for the time you spent looking into this. I'm fairly new at Python development and for some reason I thought that if Intellisense didn't work, that meant the code had syntax errors and wouldn't work. If I had known that the code would work even without Intellisense highlighting it, I wouldn't have submitted this as an issue at all. Thank you again for explaining what's going on behind the scenes, it's much appreciated |
Libraries that are based on
robotlibcore.DynamicCore
do not provide class methods when accessed in the Python mode, in VSCode for example.Verified with
rpaframework==16.1.0
affected libraries (at least):
RPA.Desktop
RPA.PDF
RPA.Windows
Original report by Andres Douglass in the Dev Slack - link
Information in the Robot Framework user guide
The text was updated successfully, but these errors were encountered: