-
Notifications
You must be signed in to change notification settings - Fork 45
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
Class nested inside function causes exception in textDocument/documentSymbol #170
Comments
@pyscripter thanks for the suggestion, the examples, and the sample code!
My preference would be to find a way to omit namespaces held privately inside functions (without raising exceptions, of course): values defined in a function namespace, be they classes / functions / other, are not available to users outside of the function namespace and therefore (arguably) don't belong in the document symbols. |
The LSP provides for SymboInformation (flat view) or DocumentSymbol (hierarchical view). So it is reasonable to assume that clients expect the DocumentSymbol results to include some lower levels of the hierarchy. I agree that there is a danger of getting noise in the results (this is why for instance I did not include variables defined inside functions, function parameters etc.) which Jedi provides. On the other hand the symbols are used to present the user with a hierarchical view of the namespace, which is used among other things for navigation in the code. For example PyScripter has a docked view called Code Explorer. It would be useful to show nested types (classes) in that view for instance. Also classes nested inside other classes (which are currently also missing) or functions are not that common, so the extra noise will be minimal. Can we make it an initialization option? (e.g. nested_types) |
By the way and as you may have guessed, PyScripter now uses your project for IntelliSense. |
Ok, I agree with your reasoning! Also, as you've pointed out, the current implementation is somewhat broken. I'm going to take your suggestion and just implement it now as the default. In the future, if someone has a huge problem with seeing classes nested in functions, we can create an option to let them override that behavior. |
The following valid python code causes an exception in the language server when you request
Traceback:
If you repace the
__init__
constructor with a function, e.g.there is no exception but information about the nested class is not included.
Fix
The attached contains a change in lsp_utils.lsp_document_symbols that resolves both issues (avoids the crash and includes info about classes and functions nested inside functions).
jedi_utils.zip
The text was updated successfully, but these errors were encountered: