Skip to content

How to set configurations to client? #201

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
zerocewl opened this issue Feb 20, 2020 · 12 comments
Closed

How to set configurations to client? #201

zerocewl opened this issue Feb 20, 2020 · 12 comments
Labels

Comments

@zerocewl
Copy link

Is there a way to send client config settings to a language client, e.g pyls?

I read the example from #32, where a simple example was provided. However the vscode api changed, in fact the provided example does not work.
I tried to adapt the example to the changed api, but my config is not send to pyls.

Is there any minimal working example for this?

@stale
Copy link

stale bot commented Apr 23, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 23, 2020
@stale stale bot closed this as completed Apr 30, 2020
@raxod502
Copy link

@TypeFox Any update here? There is no documentation provided on how to do this, and without such documentation it is impossible to use this project with Python language servers among others.

@raxod502
Copy link

Oh thank god I finally figured it out (by spending some hours inspecting the innards of vscode-languageserver-node). You have to add a middleware, like this:

new MonacoLanguageClient({
  name: "Your Name",
  clientOptions: {
    documentSelector: [{ pattern: "**" }],
    middleware: {
      workspace: {
        configuration: (params, token, configuration) => {
          return [{ foo: "bar" }];
        },
      },
    },
  },
  connectionProvider: {
    get: (errorHandler, closeHandler) =>
      Promise.resolve(
        createConnection(connection, errorHandler, closeHandler)
      ),
  },
})

(I won't guarantee the other stuff in that code will work for you, I had to hack a bunch of other things as well. But the middleware key should be correct. Of course you must adjust the actual content of the LSP configuration to taste.)

The relevant part of vscode-languageserver-node is where the middleware is pulled out and turned into config.

@raxod502
Copy link

For anyone wondering how to actually use this project, you can refer to a complete working example integrating with backend language servers for Python, Ruby, Bash, Go, Rust, and 19 other languages.

@umesh-timalsina
Copy link

Hello @raxod502. What is the middleware key are you referring to? Is it the name of the language server? Or is it something else?

@raxod502
Copy link

By "middleware key" I simply meant the data that appears immediately after middleware: in the sample code.

@umesh-timalsina
Copy link

In Riju, I see that you are using Microsoft's python language server. Is the binary available somewhere? Also, what steps did you take to configure it. It would be helpful for my use case to use a standalone server written in a single language rather than a patchwork of different libraries and extensions.

@raxod502
Copy link

I suggest referring to the code.

@itthought
Copy link

I am running Microsoft's python language server on a separate machine and want to connect with the monaco editor. And as per language server documentation I need to pass "python.linting.enabled": true config setting to the language server for enabling linting support.

I am using below config for creating MonacoLanguageClient instance.

new MonacoLanguageClient({
      name: 'Simple Client',
      clientOptions: {
        // use a language id as a document selector
        documentSelector: ['python'],
        initializationOptions: {
          interpreter: {
            properties: {
              UseDefaultDatabase: true,
              Version: '2.7',
              InterpreterPath: '/usr/bin/python',
              LibraryPath: '/usr/lib/python2.7'
            }
          },
          asyncStartup: true,
        },

        middleware: {
          workspace: {
            configuration: (params, token, configuration) => {
              return[{python: { linting: {enabled: true}}}];
            },
          }
        },
        synchronize: {
          configurationSection: ''
        },

        // disable the default error handler
        errorHandler: {
          error: () => ErrorAction.Continue,
          closed: () => CloseAction.DoNotRestart
        }
      },
      // create a language client connection from the JSON RPC connection on demand
      connectionProvider: {
        get: (errorHandler, closeHandler) => {
          return Promise.resolve(createConnection( connection as any, errorHandler, closeHandler));
        }
      }
    });

Its always sending blank setting to language server.
{"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{}}}

Is there anyway to send custom setting to language server?

@raxod502
Copy link

I can't speak for the didChangeConfiguration message, Riju (linked above) has support for setting the initializationOptions in the initialize method (key init in Riju language configuration) as well as sending configuration in response to the workspace/configuration message (key config in Riju language configuration, currently unused but I just tested that it does work).

@dkattan
Copy link

dkattan commented Jun 6, 2021

@itthought did you ever have any success populating the settings payload?

@raxod502 it looks like Riju was taken down, did you perhaps rename it?

@raxod502
Copy link

raxod502 commented Jun 7, 2021

it looks like Riju was taken down, did you perhaps rename it?

Unfortunately, that's not what happened. Please see https://intuitiveexplanations.com/tech/replit/ for the details.

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

No branches or pull requests

5 participants