spyder-ide / spyder

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

Provide API to add a new language to the LSP service #11326

Open hlouzada opened 4 years ago

hlouzada commented 4 years ago

Issue Report Checklist

Problem Description

I am trying to add a new language support in Spyder to connect via LSP in a user plugin. My plugin should modify the dictionary and lists containing the languages and show them in the setup a new server options on the LSP server editor preferences panel. If reseted preferences with spyder --reset it will work until Spyder is restarted

What steps reproduce the problem?

fIDE.zip

  1. Install the extension
  2. Open Spyder
  3. Open preferences: setup a new server in LSP server editor; command file to lunch the server is located in plugin_install_location/fIDE/spyder_fIDE/server/bin/br.ifsc.ciermag.flang.ide; the port is 5008; host is set to 127.0.0.1
  4. Close Spyder
  5. Open preferences

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

It is expected that the spyder automatically lunches and connects to the F language server, but nothing happens and when the preferences is opend there is an error.

Paste Traceback/Error Below (if applicable)

Traceback (most recent call last): File "/home/hendrik/anaconda3/envs/fIDE/lib/python3.7/site-packages/spyder/app/mainwindow.py", line 3128, in show_preferences widget = completion_plugin._create_configwidget(dlg, self) File "/home/hendrik/anaconda3/envs/fIDE/lib/python3.7/site-packages/spyder/plugins/base.py", line 117, in _create_configwidget configwidget.initialize() File "/home/hendrik/anaconda3/envs/fIDE/lib/python3.7/site-packages/spyder/preferences/configdialog.py", line 71, in initialize self.setup_page() File "/home/hendrik/anaconda3/envs/fIDE/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/confpage.py", line 1115, in setup_page self.table = LSPServerTable(self, text_color=ima.MAIN_FG_COLOR) File "/home/hendrik/anaconda3/envs/fIDE/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/confpage.py", line 589, in init self.load_servers() File "/home/hendrik/anaconda3/envs/fIDE/lib/python3.7/site-packages/spyder/plugins/completion/languageserver/confpage.py", line 624, in load_servers server.language = LSP_LANGUAGE_NAME[server.language.lower()] KeyError: 'f'

Versions

Dependencies

atomicwrites >=1.2.0 : 1.3.0 (OK) chardet >=2.0.0 : 3.0.4 (OK) cloudpickle >=0.5.0 : 1.2.2 (OK) diff_match_patch >=20181111 : 20181111 (OK) intervaltree : None (OK) IPython >=4.0 : 7.11.1 (OK) jedi =0.14.1 : 0.14.1 (OK) keyring : None (OK) nbconvert >=4.0 : 5.6.1 (OK) numpydoc >=0.6.0 : 0.9.2 (OK) pexpect >=4.4.0 : 4.7.0 (OK) pickleshare >=0.4 : 0.7.5 (OK) psutil >=0.3 : 5.6.7 (OK) pygments >=2.0 : 2.5.2 (OK) pylint >=0.25 : 2.4.4 (OK) pyls >=0.31.2;<0.32.0 : 0.31.2 (OK) xdg >=0.26 : 0.26 (OK) zmq >=17 : 18.1.0 (OK) qdarkstyle >=2.7 : 2.7 (OK) qtawesome >=0.5.7 : 0.6.0 (OK) qtconsole >=4.6.0 : 4.6.0 (OK) qtpy >=1.5.0 : 1.9.0 (OK) rtree >=0.8.3 : 0.8.3 (OK) sphinx >=0.6.6 : 2.3.1 (OK) spyder_kernels >=1.8.1;<2.0.0: 1.8.1 (OK) watchdog : None (OK) cython >=0.21 : None (NOK) matplotlib >=2.0.0 : None (NOK) numpy >=1.7 : None (NOK) pandas >=0.13.1 : None (NOK) scipy >=0.17.0 : None (NOK) sympy >=0.7.3 : None (NOK)

ccordoba12 commented 4 years ago

There's no entry for the F language server here:

Selección_087

so that's probably why you're having the error above.

So I think you need to add it in a PR for your plugin to work. The available LSP languages are available here:

https://github.com/spyder-ide/spyder/blob/68d75e00e95b95a3e1ef5a3136f0778ad3867fb5/spyder/plugins/completion/languageserver/__init__.py#L21_L26

dpizetta commented 4 years ago

Hi @ccordoba12, yes, as you pointed that is the problem, but instead of adding that language to the Spyder main project, may Spyder can provide a function to add new languages as plugins using LSP, so when the plugin is installed, Spyder adds the new language configuration needed without hard-coded changes.

ccordoba12 commented 4 years ago

I agree: we should provide an API for external plugins to register a new LSP language along with its configuration. @andfoy, please take a look at that.

However, for that @jogufe would have to wait a couple of months because right now we're busy fixing some important bugs. So it's his call.

hlouzada commented 4 years ago

Thank you for your reply. I will stick with modifying the code until the API is provided.

dalthviz commented 6 months ago

Hi there, as part of the Improving external completion plugins development support in Spyder NumFOCUS Small Development Grant and the interest shown for AI code assistants integration with Spyder at https://github.com/spyder-ide/spyder/issues/20632 (which checking seems like most of them rely on the LSP in some extend) some elements/ideas that could be important to take into account when creating/defining a public API to extend the LSP based functionality that has Spyder:

And not completly related with the LSP support but related to its usage and the response handling from the Editor:

ccordoba12 commented 6 months ago

Thanks for the summary @dalthviz! I think we should start talking about this with @hlouzada after releasing Spyder 6 to make it a reality in 6.1