spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.62k forks source link

Add Support to DocumentSymbol when handling Document Symbols Request #15755

Open hlouzada opened 3 years ago

hlouzada commented 3 years ago

Issue Report Checklist

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

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 commented 3 years ago

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 commented 3 years ago

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 (https://github.com/spyder-ide/spyder/issues/15900) that I could help with if it's necessary as it's a critical bug.