python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.9k stars 197 forks source link

`textDocument/documentSymbol` returns imported symbols #467

Closed niqodea closed 11 months ago

niqodea commented 11 months ago

When requesting textDocument/documentSymbol, pylsp includes symbols in import statements. This is, from what I could observe, different from pyright, which instead ignores these symbols when providing the result.

I don't know if there is any specific reason for this. However, I argue that pyright's behavior is more useful when it comes to the use case of simply visualizing symbols in neovim's quickfix list or in aerial.nvim.

Would it be possible to change the behavior and only return symbols defined in the file?

niqodea commented 11 months ago

Checked in the source code and it seems like there is already an option to do this! It's called

pylsp.plugins.jedi_symbols.include_import_symbols

and it defaults to True.

ccordoba12 commented 11 months ago

Glad you found the solution by yourself!