This project has moved. For the latest updates, please go here.

Intellisense works only in Interactive

Mar 2, 2014 at 2:07 AM
I read in some previous discussions that IntelliSense is dumber than REPL, because it is static, i.e. it has to have a scraped .py file. I am not sure if I understood this well, but it does work like this.
My problem starts with the qgis module.
After I set up all the directories in PYTHONPATH and in PATH I managed to make REPL see qgis module. After I import it I have access to core, networkanalysis, etc, but not to utils(which has a file), unless I import qgis.utils.
In code editor I even have code competion for import statement, so if I write import and space, I get qgis option, and if I put a dot after qgis, I also get a utils option, but I don't have code-completion for core, gui, networkanalysis, and this is, if I understood corectly, because they don't have .py files.
Basically, half of code-completion is in code-editor and the other half(the good half) is in REPL.
Will these two ever be united?
Mar 10, 2014 at 4:29 PM
They can be united already, but only by making the REPL worse. You probably don't want to do this. :)

We won't ever be making the completions in the editor equivalent to what's in the REPL (though we will try and get close) because they work in a fundamentally different way:
  • the REPL executes all the code that you ask it about
  • the editor never executes any code
What this means is that if you type the following into both the editor and the REPL:
class DeleteC:
    def right_now(self):
        import shutil
        return 123

delete_c = DeleteC()
delete_c.right_now.    # just typed a dot to see completions - I haven't pressed Enter yet
Both of them will show you completions for integer, because that's what the property returns. However, if you do this in the REPL, you will also delete your entire C: drive, whereas in the editor this won't happen. This code could be anywhere in any library that you've installed (or another user on the same machine has installed).

While this is a malicious example, there are plenty of non-malicious ones that can still cause issues if we execute arbitrary code. There are also state concerns, so the completions you see in the REPL depend on the state right now while the editor tries to show you all the possible states ever. Here's an example to demonstrate that:
if random() > 0.5:
    a = 123
    a = 'abc'
The editor will tell you that a could be an integer or a string, while the REPL knows exactly which one it is because it has actually picked the random number and executed one of the two statements.

We do allow some code execution for the editor to look into .pyd files, which is probably what qgis is using for the completions that you don't see. In most cases, we can successfully load these, but sometimes people write buggy modules that only load under certain conditions. If this happens, we won't have any information about it. You'll be able to see if this is the issue if you look through the Tools|Python Tools|Diagnostic Info logs (copy it into Notepad and search for the module name). Over time we are trying to improve this, but it is at the point where we are following the rules (as they exist - there aren't many), and trying to also handle modules that don't as we find them.

In short, the two contexts are fundamentally different, and so they behave differently. We sacrifice some information in the editor to avoid arbitrary code execution but take all code into account, while the REPL is actually executing the code you type in and showing you the immediate state. We won't ever be changing how the editor works to match how the REPL works, though we are always trying to improve both of them.