You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
textDocument/documentSymbol returns empty result for non-existing files #301
textDocument/documentSymbol returns an empty result for non-existing files even though Jedi does provide symbol information. The culprit us the following code:
# Python 2 on Windows has no .samefile, but then these are
# strings for sure
docismodule=document.path==d.module_path
This can reproduced by creating a new file in Spyder: No symbol information is available in the Symbols Switcher and Outline plugin as long as the file is not saved¹. Code folding and linting does work.
¹ Note: Saving the new file is not sufficient to fix the issue in Spyder <= 5.4.0 due an another unrelated bug. See spyder/spyder-ide#20047.
I am not quite sure, but I think that docismodule should be determined via pathlib.Path(document.path) == d.module_path¹ – that is, check the file paths for equivalence. os.path.samefile()² actually accesses the filesystem to check if the two paths point to the same file (think of hard links on UNIX). I don’t think that’s intended here.
I can make a PR if the proposed fix is deemed correct.
os.path.samefile()² actually accesses the filesystem to check if the two paths point to the same file (think of hard links on UNIX). I don’t think that’s intended here.
Right, then I agree with your proposed solution. Please submit a PR for it.
Activity
ccordoba12 commentedon Nov 20, 2022
Hey @rear1019, thanks for reporting. What do you propose to fix the issue? Removing the try/except you referenced?
rear1019 commentedon Nov 21, 2022
I am not quite sure, but I think that
docismoduleshould be determined viapathlib.Path(document.path) == d.module_path¹ – that is, check the file paths for equivalence.os.path.samefile()² actually accesses the filesystem to check if the two paths point to the same file (think of hard links on UNIX). I don’t think that’s intended here.I can make a PR if the proposed fix is deemed correct.
¹ Or a variant thereof, depending on the required Python/Jedi compatibility.
² https://docs.python.org/3.10/library/os.path.html#os.path.samefile
ccordoba12 commentedon Nov 21, 2022
Right, then I agree with your proposed solution. Please submit a PR for it.
Add test for symbols of a non-existing (unsaved) file
Fix symbols for non-existing (unsaved) files
Fix symbols for non-existing (unsaved) files