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
Specifc relative import statement causing issues with VSC highlighting and 'jumping' functionality. #1655
Comments
This looks indeed like a bug, will do some further digging. However, I doubt that this will help you. VSCode is already a few versions behind the current Jedi version, so it might take you quite a while until you actually get this fixed. |
Not sure that's quite right -- vscode-python is using 0.17.2. Agree it's a little bit laggy due to the release cycles not being quite in sync though. As noted on the original issue though it is still using an older API so that may have an impact, depending on exactly what the issue is. |
Oh, did I not notice the upgrade? I thought they were still on 0.15.2. Where did you find this information? |
Oh, just checked and looks like you did the work: microsoft/vscode-python#11252 Thanks! :) |
@PeterJCLaw Feel free to tackle this issue. I'm working on my understanding of Rust :). If I ever get to work on this ticket, I will just self-assign. |
hi @NootNootEliot, I've just had a look at this and I'm struggling to reproduce it. I've extracted the demo source you've provided and am opening the files in the order as described, however for me the information regarding I'm launching the editor by There are a couple of differences with my setup than yours though:
Could you try this with the latest version of the extension? Alternatively, are there any other steps which are needed or settings you have locally which affect the |
Hi @PeterJCLaw Thank you for taking a look. I first tested this on Windows. I However, I then opened a Virtual Machine (Ubuntu 20.04) and With regards to settings I might have affecting the |
Ok, this is looking like it's a platform thing. To me this suggests there's something about this directory structure which is creating this, rather than the ordering of the files being opened, which hopefully will make this easier to chase down. |
@PeterJCLaw - Cool! I think it is to do with the directory structure as well, rather than the ordering of files. Cheers! |
I'm currently working using a cut-down which has It seems that the presence (or lack) of the Running This suggests to me that this is an interaction with the VSCode extension, possibly around the determination of the (Jedi) project directory (which is a distinct concept than the VSCode project directory). I'm out of time for tonight, but may have time to pick this up an evening during the week. |
Okay cool, thank you! To clarify, does 'VSCode extension' refer to the VSCode Python extension? |
@PeterJCLaw Strange, I thought I was able to reproduce this on Ubuntu. I will recheck. |
Ok, so pinning down exactly what combination of things doesn't work here is a bit difficult as it seems to vary by platform. I'm not sure quite why that is, however I'm pretty sure that this is an issue with the VSCode Python extension rather than Jedi itself. This is because the issue seems to stem from the way that the extension's |
Mostly for myself/posterity: Here's my repro with separate files for each of the variants, with inline comments about what works on Windows (Win 7): jedi-issue-1655.zip The difference I get on Ubuntu is that the |
Hrm, this is true when doing completions in files within the root of the project, but not true for files in the |
I just remembered that I think there are different ways to generate import paths in case of completions vs. goto. But I'm not 100% sure anymore. I'm pretty sure that completions are more forgiving and give you more, where goto is more precise (and better respects the sys path). |
Ok, so I think I've found the source of the I think I've also found cases where this is hit if the user has their code the other side of a windows mount point, which was causing me issues for a while, but I can reproduce this without that. Essentially when Jedi is working out the paths for the import in The lowercasing happens somewhere in the JS part of the VSCode extension -- the drive letters are already in lowercase when they reach the Python Certainly if I reply a case-respecting request to the extension's I suspect that Jedi could fix this by using |
Just tested this specifically in that function and this does indeed fix the issue for me. |
…orts This fixes an issue which showed up on Windows in 0.17.x where the VSCode Python extension passes paths which have their drive letter normalised to lower case. Since paths are (mostly) case insensitivd on Windows, that shouldn't matter. However Jedi's handling was `==` on `str`s, meaning that completions based on relative imports on windows didn't work. On master this same issue had started appearing due to the partial migration to use `Path` instead of `str` (which will avoid such issues entirely once complete), as `Path` instances were being compared to `str` instances without first converting. We fix both by clarifying which is used here and then doing the proper conversions.
…orts This fixes an issue which showed up on Windows in 0.17.x where the VSCode Python extension passes paths which have their drive letter normalised to lower case. Since paths are (mostly) case insensitive on Windows, that shouldn't matter. However Jedi's handling was `==` on `str`s, meaning that completions based on relative imports on windows didn't work. On master this same issue had started appearing due to the partial migration to use `Path` instead of `str` (which will avoid such issues entirely once complete), as `Path` instances were being compared to `str` instances without first converting. We fix both by clarifying which is used here and then doing the proper conversions.
…tive imports This fixes an issue which showed up on Windows in 0.17.x where the VSCode Python extension passes paths which have their drive letter normalised to lower case. Since paths are (mostly) case insensitive on Windows, that shouldn't matter. However Jedi's handling was `==` on `str`s, meaning that completions based on relative imports on windows didn't work. On master this same issue had started appearing due to the partial migration to use `Path` instead of `str` (which will avoid such issues entirely once complete), as `Path` instances were being compared to `str` instances without first converting. We fix both by clarifying which is used here and then doing the proper conversions.
…tive imports This fixes an issue which showed up on Windows in 0.17.x where the VSCode Python extension passes paths which have their drive letter normalised to lower case. Since paths are (mostly) case insensitive on Windows, that shouldn't matter. However Jedi's handling was `==` on `str`s, meaning that completions based on relative imports on windows didn't work. On master this same issue had started appearing due to the partial migration to use `Path` instead of `str` (which will avoid such issues entirely once complete), as `Path` instances were being compared to `str` instances without first converting. We fix both by clarifying which is used here and then doing the proper conversions.
…tive imports This fixes an issue which showed up on Windows in 0.17.x where the VSCode Python extension passes paths which have their drive letter normalised to lower case. Since paths are (mostly) case insensitive on Windows, that shouldn't matter. However Jedi's handling was `==` on `str`s, meaning that completions based on relative imports on windows didn't work. On master this same issue had started appearing due to the partial migration to use `Path` instead of `str` (which will avoid such issues entirely once complete), as `Path` instances were being compared to `str` instances without first converting. We fix both by clarifying which is used here and then doing the proper conversions.
This issue should be fixed. At least my tests should make it a lot better. I'll keep #1662 open, but I guess this issue can be closed. |
Hi! This is an issue that I've forwarded over from microsoft/vscode-python#13198, following advice. For the full discussion so far, please check the issue above.
Environment data
python.languageServer
setting: JediSteps to reproduce:
Example Directory:
VSC_behaviour.zip
Expected behaviour
I will describe the highlighting as 'blue-highlighting', as that's what's shown in my screenshots due to my theme, but presumably, there will be different colours for others.
1.1. Navigate to
run.py
. Assuming default keybindings, hover your mouse over thefile1
part ofimport file1
. It should highlight and underline in blue, shown below, and you should be able to left-click and 'jump' tofile1
.1.2. Type
file1.
insiderun.py
, as if you were calling a function fromfile1
. You should be auto-suggested thedo_nothing()
function, the behaviour of which I believe comes from the Python extension.Now navigate to
file2.py
. Notice thefrom . import file3
. Hovering your mouse over file3 should result in highlighting/underlining/jumping (but it doesn't - see Actual Behaviour). Moreover, writingfile3.
infile2.py
should suggest thedo_nothing()
function.Replacing
from . import file3
infile2.py
with an alternative syntax should also have blue-highlighting/underlining/jumping/function suggestions. For instance,from .file3 import *
should have this behaviour, as well asimport file3
, although the latter throws an editor error, but still has that highlighting/underlining and 'jumping'.Actual behaviour
Steps 1.1 and 1.2 show the expected behaviour (see images above). There is the expected blue-highlighting/underlining/jumping/function suggestions.
However, Step 2 does not show the expected behaviour. There is no blue-highlighting/underlining/jumping/function suggestions.
Perhaps this behaviour is due to my syntax, but my project appears to run fine with this step 2 syntax. This seems frustrating to me, as this syntax seems to be 'legal'. Furthermore, if I manually write
file3.do_nothing()
, the function can run perfectly normally at execution, provided the function is ultimately called fromrun.py
, the Python file that's ran for the project. You can see an example of this expected behaviour here. You should see the text 'I'm working!' on terminal.VSC_Behaviour_run.zip
One possible theory I have is that the highlighting/etc. is being missed out due to the nature of the relative import. However, the highlighting/etc. work for another relative imports method, as shown in Step 3 below. Hence, I think that this specific relative import syntax could be causing conflicts with the Python extension for some reason, but I'm not sure why this might be occurring.
As mentioned above, the alternative import syntaxes in Step 3 do show the expected behaviour. There is highlighting/etc.
Furthermore, within
__init__.py
specifically, I found Step 2 to indeed meet the expected behaviour. Writing:from . import file3
showed the blue-highlighting/underlining/jumping/function suggestions. This makes me confused. Now this syntax apparently does show support, but only within that__init__.py
file, not withinfile2.py
, for instance.However, as I mentioned above, the relative import that's missing that highlighting/etc. still runs in the project with expected output, with the relative imports working, as can be seen in VSC_Behaviour_run.zip above.
I was recommended to post the issue here, just to let
jedi
, but apparently it could be due to the Python extension's use of the Jedi API. The original issue is here: microsoft/vscode-python#13198Thank you!
The text was updated successfully, but these errors were encountered: