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

Can we dynamically update the language server settings? #976

Closed
avneeshn opened this issue Sep 5, 2023 · 3 comments
Closed

Can we dynamically update the language server settings? #976

avneeshn opened this issue Sep 5, 2023 · 3 comments

Comments

@avneeshn
Copy link

avneeshn commented Sep 5, 2023

Context

We are developing an extension depending on jupyterlab-lsp's autocompletion functionality. We are using joe-re/sql-language-server. We want to be able to dynamically update the Language Server Protocol settings.

Description

sql-language-server requires settings of the following format

"sql-language-server": {
            "priority": 50,
            "serverSettings": {
                "sqlLanguageServer.connections": [
                    {
                        "name": "my_local_config",
                        "adapter": "json",
                        "filename": "/home/my-user/sql-schema.json",
                        "projectPaths": [
                            "."
                        ],
                        "ssh": null
                    }
                ]
            }
        }

As per my understanding, this is accessible via @jupyter-lsp/jupyterlab-lsp plugin. We want to be able to dynamically update "sqlLanguageServer.connections" to add more connection objects through our JupyterLab extension. Is there any way to do that?

@krassowski
Copy link
Member

If I am not mistaken JupyterLab extensions are capable of changing settings of other extensions. This goes like:

const extension: JupyterFrontEndPlugin<void> = {
  id: MY_PLUGIN_ID,
  autoStart: true,
  requires: [ISettingRegistry],
  activate: (app: JupyterFrontEnd, settingsRegistry: ISettingRegistry) => {
    const settings = settingsRegistry.load(ANOTHER_PLUGIN_ID);
    settings.set('setting', 'value');
  }
}

see https://github.com/jupyterlab/extension-examples/tree/main/settings.

In this case, that would be:

const settings = settingsRegistry.load('@jupyter-lsp/jupyterlab-lsp:plugin');
const current = settings.get('language_servers').user; // you may want to extract default connections (if any using `.composite`) but take the rest of settings from `.user` to polluting user settings with defaults
current['sql-language-server']['serverSettings']['sqlLanguageServer.connections'] = [MY_CONNECTION];
settings.set('language_servers', current);

Now, this is not guaranteed to work for jupyterlab-lsp - there may be some code path in how we handle the settings which breaks it. If that is the case, feel welcome to point it out/open a PR. Please let me know if this turned out to be a fruitful approach.

@krassowski
Copy link
Member

I assume this helped :) Closing as answered.

@avneeshn
Copy link
Author

It did help. Thank you :)

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