10000 The Language Server fails to provide document symbols for nested classes · Issue #1140 · pyscripter/pyscripter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

The Language Server fails to provide document symbols for nested classes #1140

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

Closed
pyscripter opened this issue Oct 21, 2021 · 5 comments
Closed

Comments

@pyscripter
Copy link
Owner
pyscripter commented Oct 21, 2021

Steps to reproduce

  • Add the following python code to a new file:
def myfunc():
    x = 3
    class MyClass(object):
        def __init__(self):
            pass

    return MyClass

print(myfunc().y)

The Code Explorer Window is empty.

However the following works (but no information is provided about the nested class):

def myfunc():
    x = 3
    class MyClass(object):
        def f(self):
            pass

    return MyClass

print(myfunc().y)

This is a bug in the language server.

@pyscripter pyscripter changed the title The Language server fails to provide document symbols for nested classes The Language Server fails to provide document symbols for nested classes Oct 21, 2021
@pyscripter
Copy link
Owner Author

For the record here is the Language server traceback for the first example.

Traceback (most recent call last):
  File "C:\ProgramData\PyScripter\Lsp\jls\jedilsp\pygls\protocol.py", line 331, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "C:\ProgramData\PyScripter\Lsp\jls\jedilsp\pygls\protocol.py", line 260, in _execute_request
    method_name, method_type, msg_id, handler(params))
  File "C:\ProgramData\PyScripter\Lsp\jls\jedilsp\jedi_language_server\server.py", line 388, in document_symbol
    document_symbols = jedi_utils.lsp_document_symbols(names)
  File "C:\ProgramData\PyScripter\Lsp\jls\jedilsp\jedi_language_server\jedi_utils.py", line 167, in lsp_document_symbols
    parent_symbol = _name_lookup[parent]
KeyError: <Name name='MyClass', description='class MyClass'>

@pyscripter
Copy link
Owner Author

Quick fix:

Replace C:\ProgramData\PyScripter\Lsp\jls\jedilsp\jedi_language_server\jedi_utils.py with the following:
jedi_utils.zip

This avoids the error but it still does not show the class nested inside the function. This requires a fix on the PyScripter side which will be made available in the next release. It does however correctly show nested classes.

@Hiltronix
Copy link

I can confirm that corrects the error and the Code Explorer pane now populates.
Thank you!

@pyscripter
Copy link
Owner Author
pyscripter commented Oct 22, 2021

I have committed the changes to show classes and functions nested inside functions.

@pyscripter
Copy link
Owner Author

Reported as pappasam/jedi-language-server#170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0