Closed xobs closed 3 years ago
The reason it isn't working is because code navigation doesn't use PYTHONPATH
as specified in your .env
file.
You can work around this by setting your "python.autoComplete.extraPaths"
as necessary, e.g.:
"python.autoComplete.extraPaths": [
"${workspaceFolder}\\deps\\litex"
]
will let you navigate from to Platform
from from litex.boards.platforms.icestick import Platform
.
Related: microsoft/vscode-python#2312
Will the contents of .env
be used at some point?
@xobs not sure yet. We need to discuss it on the team and think through the ramifications of that decision.
@brettcannon, I was under the impression the value for PYTHONPATH was being used by the language server. I remember having a chat about this with @mikhail. It either got missed out it accidentally dropped off at done point in time
@DonJayamanne I think you meant to ask @MikhailArkhipov 😉
But my question is whether we are always sourcing a .env
file to calculate PYTHONPATH
for things like the language server?
But my question is whether we are always sourcing a .env file to calculate PYTHONPATH for things like the language server?
No we aren't, I checked this yesterday.
We need to use the IEnvironmentVariablesService (or similar name, can't remember) to get these resolved variables and pass into the language server.
It should be noted that you need both python.autoComplete.extraPaths
and the .env
file for both the Python Language Server and pylint
to work. If you only specify one, you'll get some strange behavior.
The reason it isn't working is because code navigation doesn't use
PYTHONPATH
as specified in your.env
file.You can work around this by setting your
"python.autoComplete.extraPaths"
as necessary, e.g.:"python.autoComplete.extraPaths": [ "${workspaceFolder}\\deps\\litex" ]
will let you navigate from to
Platform
fromfrom litex.boards.platforms.icestick import Platform
.
Where are you supposed to add those lines?
EDIT: Answer : settings.json that you can access through Ctrl + shift + P > Preferences: Open Settings (JSON)
@DonJayamanne Is this a temporary solution, or is this the approach VS Code will stick with?
As I can see, this is really not a convenient way: .env file nicely pack all environment variables into one place and therefore duplicating this items in settings.json (or any other file than .env) just makes a whole lot of maintenance problems. Also, system environment variables are discovered inside .env files, while VS Code is quite messy where and what environment substitution is possible, for example even main .code-workspace file doesn't support basic env stuff...
I am switching back to Jedi, since IntelliCode doesn't work in our environment.
@schperplata we're hoping to plumb .env
support throughout the extension at some point.
We can check if this is fixed when https://github.com/microsoft/vscode-python/issues/11995 lands
This should be fixed as part of the #275
@judej This does not appear to be fixed as part of #275
Please file a new issue for your case; this issue definitely was closed as we could navigate and resolve imports as we would had they been populated in extraPaths.
Environment data
Actual behavior
Control-clicking on a symbol does nothing, pressing F12 says "No definition found", mousing-over shows the function definition.
Expected behavior
If a definition is available, such as by mousing-over a symbol, then control-clicking on the symbol should go to the definition.
Steps to reproduce:
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
)