Skip to content
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

Add Support to DocumentSymbol when handling Document Symbols Request #15755

Open
4 of 10 tasks
hlouzada opened this issue Jun 1, 2021 · 2 comments
Open
4 of 10 tasks

Add Support to DocumentSymbol when handling Document Symbols Request #15755

hlouzada opened this issue Jun 1, 2021 · 2 comments

Comments

@hlouzada
Copy link
Contributor

hlouzada commented Jun 1, 2021

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

The LSP specifies that textDocumentSymbol request can respond with DocumentSymbol or SymbolInformation. Currently, spyder only supports SymbolInformation so I would like to suggest adding support to DocumentSymbol since it specifies children's objects, therefore reducing the Spyder's computational weight to search for possible parents.

Refer to Language Server Protocol for more details.

A workaround can be made by patching spyder.editor.widgets.codeeditor.CodeEditor.process_symbols:

    @handles(CompletionRequestTypes.DOCUMENT_SYMBOL)
    def process_symbols(self, params):
        """Handle symbols response."""
        try:
            symbols = params['params']
            symbols = [] if symbols is None else symbols

            if symbols and "location" not in symbols[0]:
                for symbol in symbols:
                    symbol["location"] = {"range": symbol["range"]}

            self.classfuncdropdown.update_data(symbols)
            if self.oe_proxy is not None:
                self.oe_proxy.update_outline_info(symbols)
        except RuntimeError:
            # This is triggered when a codeeditor instance was removed
            # before the response can be processed.
            return
        except Exception:
            self.log_lsp_handle_errors("Error when processing symbols")

What steps reproduce the problem?

  1. Configure any LSP Server that uses DocumentSymbol instead of SymbolInformation
  2. Open Document
  3. Open Outline panel

What is the expected output? What do you see instead?

It's expected a populated Tree in Outline Panel, but nothing is displayed.

Paste Traceback/Error Below (if applicable)

2021-06-01 13:27:42,322 [ERROR] [spyder.plugins.editor.widgets.codeeditor] -> Error when processing symbols
Traceback (most recent call last):
  File "c:\users\hendr\anaconda3\envs\ciermag-develop\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1121, in process_symbols
    self.classfuncdropdown.update_data(symbols)
  File "c:\users\hendr\anaconda3\envs\ciermag-develop\lib\site-packages\spyder\plugins\editor\panels\classfunctiondropdown.py", line 207, in update_data
    line_start = item['location']['range']['start']['line']
KeyError: 'location'

Versions

  • Spyder version: 5.0.3
  • Python version: 3.8.5
  • Qt version: 5.12.10
  • PyQt version: 5.12.3
  • Operating System name/version: Windows-10-10.0.21390-SP0

Dependencies


# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.19.0 (OK)
jedi =0.17.2                  :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  21.8.0 (OK)
nbconvert >=4.0               :  6.0.7 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
paramiko >=2.4.0              :  2.7.2 (OK)
parso =0.7.0                  :  0.7.0 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.8.1 (OK)
pylint >=1.0                  :  2.6.0 (OK)
pyls >=0.36.2;<1.0.0          :  0.36.2 (OK)
pyls_black >=0.4.6            :  0.4.6 (OK)
pyls_spyder >=0.3.2;<0.4.0    :  0.3.2 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=39.0.0           :  56.0.0 (OK)
sphinx >=0.6.6                :  3.4.3 (OK)
spyder_kernels >=2.0.3;<2.1.0 :  2.0.3 (OK)
textdistance >=4.2.0          :  4.2.0 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3;<2.0.0      :  1.0.2 (OK)
zmq >=17                      :  22.0.3 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=2.0.0            :  3.3.3 (OK)
numpy >=1.7                   :  1.19.5 (OK)
pandas >=1.1.1                :  1.2.1 (OK)
scipy >=0.17.0                :  1.6.0 (OK)
sympy >=0.7.3                 :  1.7.1 (OK)

# Spyder plugins:
spyder_f_language             :  1.3.dev (OK)

@steff456
Copy link
Member

steff456 commented Jun 2, 2021

Hi @hlouzada,

We definitely need to add this to Spyder 's client for it to work. If you are interested in helping us with this enhancement, we could give you all the guidance you need.

Thanks for reporting!

@hlouzada
Copy link
Contributor Author

Hi @steff456,

I would be delighted to help, but currently, I don't have enough time available and, as it's not critical for my Language Server project, it'll have to wait until I have more time. Although, there is another issue that I recently found (#15900) that I could help with if it's necessary as it's a critical bug.

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

No branches or pull requests

2 participants