Skip to content

textDocument/documentSymbol returns empty result for non-existing files #301

Closed

Description

@rear1019

textDocument/documentSymbol returns an empty result for non-existing files even though Jedi does provide symbol information. The culprit us the following code:

try:
docismodule = os.path.samefile(document.path, d.module_path)
except (TypeError, FileNotFoundError):
# 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.

EDIT: Formatting

Activity

  1. added this to the v1.7.0 milestone on Nov 20, 2022
  2. ccordoba12 commented on Nov 20, 2022

    @ccordoba12
    Member

    Hey @rear1019, thanks for reporting. What do you propose to fix the issue? Removing the try/except you referenced?

  3. rear1019 commented on Nov 21, 2022

    @rear1019
    ContributorAuthor

    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.

    ¹ Or a variant thereof, depending on the required Python/Jedi compatibility.
    ² https://docs.python.org/3.10/library/os.path.html#os.path.samefile

  4. ccordoba12 commented on Nov 21, 2022

    @ccordoba12
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions