microsoft / python-language-server

Microsoft Language Server for Python
Apache License 2.0
914 stars 133 forks source link

Classes not loading python libraries #1081

Closed SheepDomination closed 5 years ago

SheepDomination commented 5 years ago

The Python Language Server is loading some specific python libraries; but when using Intellisense to access the libraries, there is no list of the classes which I can load ?

jakebailey commented 5 years ago

Can you be more specific? When the language server analyzes a file, it will first read all of the imports in the file, and analyzes those. Any imported library in a file, or any file in the dependency graph imports, will be analyzed and get IntelliSense.

If you're saying that you're importing a library, and that library's completion is missing some class declared in that library, then we'd like to know about that and reproduce it.

SheepDomination commented 5 years ago

I'm not getting any completion when attempting to work with the loaded classes. Typically if I were to type the name space, I would get prompt with the classes I want to load, although this is not occurring ?

jakebailey commented 5 years ago

If you have a code example, that'd be better to explain your issue. I'm not sure exactly what a "name space" in the context of python implies. If you import a module, then you can use it and get completion.

SheepDomination commented 5 years ago

That is what I'm having problems with getting a module to load, I was directed that it's due to the Python Language Server and that once it's loaded by the Python Language Server then ctrl+space (Intellisense) should show when my cursor is above the class then I will see suggestions ?

MikhailArkhipov commented 5 years ago

Screenshot please. It is unclear what do you mean in above in connection with ctrl+space.

SheepDomination commented 5 years ago

Correct me if I'm wrong but you load modules with "python.autoComplete.extraPaths" ? And when those modules are loaded; then using the keyboard short-cut ctrl+space to trigger intellisense when I have my cursor over a class which was loaded by means of python.autoComplete.extraPaths. I should then see suggestions.

MikhailArkhipov commented 5 years ago

No. Modules are loaded automatically when parser discovers import statement and resolves dependency according to the Python module discovery rules (ie search paths). It is the best to show your code and point at which location you invoke completion

SheepDomination commented 5 years ago

No. Modules are loaded automatically when parser discovers import statement and resolves dependency according to the Python module discovery rules (ie search paths). It is the best to show your code and point at which location you invoke completion

I don't follow exactly ?

MikhailArkhipov commented 5 years ago

https://docs.python.org/2/tutorial/modules.html#the-module-search-path

MikhailArkhipov commented 5 years ago

Closing this issue. If you have specific scenario, please provide step by step repro with screenshot.

SheepDomination commented 5 years ago

If I understand correctly; if the module is found within the PYTHONPATH environment variable then it will be loaded into code and therefore I should be able to load all the classes and functions from the module; all using the Python Language Server ?

jakebailey commented 5 years ago

It does not necessarily need to be in that variable. If you open code which imports a module (import foo), then that module will be analyzed and will be usable (foo.bar). You do not need to explicitly tell the language server what to "load"; it will find dependencies as needed and analyze them. extraPaths and PYTHONPATH can help the language server figure out where some modules live in more complicated setups.

SheepDomination commented 5 years ago

I placed the *.pyc file location into the environment variable in Windows for the variable PYTHONPATH. Restarted the computer and when typing the class followed by CTRL+SPACE I don't see suggestions corresponding to the class ?

MikhailArkhipov commented 5 years ago

See above. "Please provide step by step repro with code screenshot." It is unclear what is that you are doing or trying to achieve.

SheepDomination commented 5 years ago

I have a file with a pyc extension; assuming if the information I was given is correct, this pyc file contains a class with methods of the class. The goal is when typing the name of the class, whether in a variable or not; I should get a list of suggestions which correspond to the class.

For example, if the class has a method called sheep() then when typing the name space of the class, in this case ro then when typing ro followed by CTRL+SPACE I should get a list of classes to which I should see the sheep() method in the list of pre-loaded modules since the setting "python.autoComplete.preloadModules": loaded all the ro modules.

jakebailey commented 5 years ago

To be clear, pyc files are compiled python code which you would not write by hand. You can't put normal python code in a pyc file.

preloadModules does not exist; this option only ever applied to using Jedi in the VSC python extension and was never implemented in the language server; it is not needed here. It was only used in the extension as a performance hack.

If the pyc file is a library, and exists in some python path (not the file itself "in" the python path, but in "a" python path), then if you do import my_library, you can do my_library.sheep(). I.e., if you have C:\random\my_library.pyc, and do:

"python.autoComplete.extraPaths": ["C:\\random"]

Or add C:\random to a PYTHONPATH environment variable (which you should not be setting for the entire system, a .env file would likely be better), then when the language server reads the code import my_library, it will find my_library.pyc, scrape, and analyze it. Then, doing my_library. will show completion for the members we were able to find within that compiled module.

jakebailey commented 5 years ago

Just note that the above is a confusing setup; it wouldn't really be executable in the python code and has dubious value. Your configuration should be dependent on your project (which is the part you are still not providing).

SheepDomination commented 5 years ago

@jakebailey

Or add C:\random to a PYTHONPATH environment variable (which you should not be setting for the entire system, a .env file would likely be better), then when the language server reads the code import my_library, it will find my_library.pyc, scrape, and analyze it. Then, doing my_library. will show completion for the members we were able to find within that compiled module.

What do you mean setting a .env file would be better; and what type of .env file ?

jakebailey commented 5 years ago

https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file

SheepDomination commented 5 years ago

What is not occurring is, when selecting the method of the class, no brief documentation on the method is shown, as in what the method does ?

jakebailey commented 5 years ago

You're going to have to provide the a test project for us to work with.

SheepDomination commented 5 years ago

Is it possible that Jedi would work successfully loading the brief documentation but the python language server doesn't work in this sense ?

I did get the libraries to load 👍 but all that is missing is the documentation on the methods in the class.

SheepDomination commented 5 years ago

@jakebailey The python language server does not load up as seen in the screen shot as does Jedi.

What is Jedi doing which the python language server is not;is loading a description of the method as seen on the right of the image ?

description

jakebailey commented 5 years ago

The language server does that too. We are not aware of any issues showing that info. We cannot reproduce your issue if you do not provide the actual code that causes the issue.

This thread has moved past the original issue reported. When you have something we can test, we'd appreciate a new filed issue that we can handle, versus using an unrelated one.

SheepDomination commented 5 years ago

@jakebailey I have attached the file; if you can get what you see in the previous screen shot to load with the python language server, I would like to know how; as I can only get it loaded with Jedi with is being phased out ?

jakebailey commented 5 years ago

Thanks for the file, I can look at that now. I can see those docs in the file, so maybe our scraper isn't doing the right thing. I'll file a different issue for this, given the issue was not loading, but this is a doc problem.

Jedi is still not the default, you can continue to use it if it works better for you.

SheepDomination commented 5 years ago

@jakebailey The python language server is not loading the docs ? I can continue to use Jedi but it's slow compared to the python language server. What do you mean this is a doc problem; can it be resolved ?

SheepDomination commented 5 years ago

@jakebailey I recently updated to Code 1.35.0; any word on when this issue will be resolved ?

jakebailey commented 5 years ago

I opened #1165, which you can follow. Our releases are not related to VS Code's.

As far as I can tell, Houdini python files exist somewhere on the disk, which you may want to give via extraPaths or PYTHONPATH for us to read (instead of random pyc files, which we may not be able to load, I certainly wasn't able to import that pyc file you provided), but past that, I do not have any more information.

SheepDomination commented 5 years ago

I found an extra file which may help with the documentation, it is a *.pyd file would that help in resolving this issue; as I have included this file within the extraPaths and PYTHONPATH

jakebailey commented 5 years ago

Please, comment on the other issue. #1165

extraPaths and PYTHONPATH are lists of directories (ignoring the special case of zip files, which we don't support). Putting pyc/pyd files in them will not do anything, as they are not import roots.