Visitar URL original
Unable to use intellisense and code navigation · Issue #12353 · microsoft/vscode-python · GitHub
The Wayback Machine - https://web.archive.org/web/20240601125120/https://github.com/microsoft/vscode-python/issues/12353
Skip to content
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

Unable to use intellisense and code navigation #12353

Closed
sourabh2902 opened this issue Jun 15, 2020 · 18 comments
Closed

Unable to use intellisense and code navigation #12353

sourabh2902 opened this issue Jun 15, 2020 · 18 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@sourabh2902
Copy link

sourabh2902 commented Jun 15, 2020 •

Hi
I am working on the project which has a huge code base involving many many python source code files. I am using python extension and vscode for the first time and I am running into the following issue.

I have a python file located in path : a/b/c/d/e/legacy/file_reader.py
This is imported in the second python file using the following method :

import os
import sys
sys.path.append("a/b/c/d/e/legacy")
import file_reader_legacy

In this usage, I observe that the IntelliSense and code navigation work normally
However, in our project we define many environment variables which point to paths that can be used in python to import. For example :

import os
import sys
sys.path.append(os.environ['PATH_TO_FILE_READER'] + "/legacy") ==> PATH_TO_FILE_READER is an environment variable which points to a/b/c/d/e/
import file_reader_legacy

In this usage, I observe that the IntelliSense and code navigation don't work at all. That is when I select Go to definition option, the extension is not able to navigate to the definition of the method
Using absolute paths in our project is not suitable since our codebase has to support many variations and hence we try our best to abstract this as much as possible.

Please note I have created a file called: python_env.env in my ./vscode directory. This file has the definition of environment variables inside it.
for example,
.vscode/python_env.env
PATH_TO_FILE_READER=${PATH_TO_FILE_READER}

I have also defined the following in .vscode/settings.json and .vscode/vscode_workspace.code_workspace files
"python.envFile": "${workspaceFolder}/python_env.env"

Can I kindly get some help in this matter?

Environment data

  • VS Code version: 1.45.1
  • Extension version (available under the Extensions sidebar): 2020.5.80290
  • OS and version: Linux 3.0.101-108.108-default
  • Python version (& distribution if applicable, e.g. Anaconda): 3.5.4 64 bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): set to default setting
  • Value of the python.languageServer setting: set to the default setting

Expected behaviour

Please see the description above

Actual behaviour

Please see the description above

Steps to reproduce:

Please see the description above

@sourabh2902 sourabh2902 added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jun 15, 2020
@Yonglin5170
Copy link

I got similar problem. The intellisense stops working on my linux server, but it works on my local pc.
The python extension version is 2020.5.86806.

@PrateekArya
Copy link

I have the similar issue. I think its a bug in this version 2020.5.86806. Intellisense autocomplete is very slow and not working properly. In some cases it is not even suggesting the variable I used in the previous line. See the attached screenshot.

image

It works completely fine if I disable the python extension!!

@PrateekArya
Copy link

Got it! The bug is in Jedi (this extension's custom intellisense engine but we can work without it :D). Just disable that in the settings (untick as shown in attached screenshot) and everything works fine. ;)

image

@Yonglin5170
Copy link

Got it! The bug is in Jedi (this extension's custom intellisense engine but we can work without it :D). Just disable that in the settings (untick as shown in attached screenshot) and everything works fine. ;)

image

Yes it works for me! Thank u so much!

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jun 15, 2020
@sourabh2902
Copy link
Author

Unfortunately, this workaround doesn't work for me. Our project code base is IP protected and hence from Linux remote machines(where MS VS CODE is installed )access to internet is not allowed.
Due to this when I disable the JEDI option in the python extension I get the following popup and error message :

Popup
image

Error message
image

@PrateekArya
Copy link

Unfortunately, this workaround doesn't work for me. Our project code base is IP protected and hence from Linux remote machines(where MS VS CODE is installed )access to internet is not allowed.
Due to this when I disable the JEDI option in the python extension I get the following popup and error message :

Popup
image

Error message
image

You can ask them here how u can download and install the offline version for python-language-server here: https://github.com/Microsoft/python-language-server

@sourabh2902
Copy link
Author

@karrtikr
I saw this ticket has been assigned to you, instead of going through all this workaround, can't we just fix the extension?

@ghost ghost removed the triage label Jun 17, 2020
@karrtikr karrtikr reopened this Jun 17, 2020
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jun 17, 2020
@karrtikr
Copy link

.vscode/python_env.env
PATH_TO_FILE_READER=${PATH_TO_FILE_READER}

@sourabh2902 That syntax is used to references variables defined in the file. Try this to reference system environment variables.

PATH_TO_FILE_READER=${env:PATH_TO_FILE_READER}

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jun 17, 2020
@karrtikr
Copy link

In order to make sure the environment variables are correctly set, you can create a python file with following contents and then debug it, and print the environment variables.

import os
print(os.getenv('PATH_TO_FILE_READER'))

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Jun 17, 2020
@sourabh2902
Copy link
Author

@karrtikr Thanks for the reply! let me try this and update you

@sourabh2902
Copy link
Author

sourabh2902 commented Jun 17, 2020 •

@karrtikr
I tried the steps it didnt work the code navigation is still not able to go to the definition of the function
For example :
We can see the value of environment variable in the terminal :
image

the contents of the .env file are :
image

In my python code I append the path to sys like the following :
image

The tool still is not able to find the definition
image

I tried to run my python script I see the environment variable value correctly and script output being generated correctly as well. If I replace the code from 3rd picture to absolute path then the code navigation and IntelliSense work as expected. But as I mentioned that is not desirable in large projects.

@karrtikr
Copy link

I see.

We can see the value of environment variable in the terminal :

That's actually different. Can you please try printing the environment variable by debugging the python file instead?

From your screenshot, I would need you to print os.environ['UL_MODEL'] +'/shared/func2rif

@sourabh2902
Copy link
Author

@karrtikr Yes , as I mentioned that the script runs normally and produces the right outputs. So it was also decoding the os.environ part correctly.

@Yonglin5170
Copy link

Unfortunately, the issue happened again both on my pc and linux server. The python extention version is 2020.6.89148

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Jun 20, 2020
@karrtikr
Copy link

@plus5170 Please open up a new issue, and I will transfer it up to language server.

@sourabh2902 I will get back to you when I get the chance

@Yonglin5170
Copy link

@plus5170 Please open up a new issue, and I will transfer it up to language server.

@sourabh2902 I will get back to you when I get the chance

Oh I just find it works after the command "Analyzing in background..." completed. It is OK to wait for a while. Thanks for your reply!

@karrtikr
Copy link

@sourabh2902 Note Jedi doesn't pick changes from sys.path. You'll have to set PYTHONPATH environment variable to the relative path of the directory (to workspace) where modules are imported from. See this for more details.

If it still doesn't work our for you, please give me small reproducible example with file directory structure, file contents, .env file.
My understanding of the problem is this,

  • If you don't use the environment variable, things work fine for you.
  • If you use the environment variable, and set it correctly (you checked by printing the values of variable), things still do not work for you.

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Jun 22, 2020
@sourabh2902
Copy link
Author

thanks for the help ! now it is working

@ghost ghost removed the triage label Jun 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants