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

How to pass configuration data to language server? #167

Closed
sivakov512 opened this issue Nov 12, 2017 · 31 comments
Closed

How to pass configuration data to language server? #167

sivakov512 opened this issue Nov 12, 2017 · 31 comments
Labels

Comments

@sivakov512
Copy link

With vscode, I can send the settings to the language server. for example, the path to the virtual environment or used linters forpyls. How to do it with this plugin?

@bkchr
Copy link
Contributor

bkchr commented Nov 12, 2017

See here, that is the way it is done for the rust language server.

@vibhavp
Copy link
Member

vibhavp commented Nov 12, 2017

Could you give an example? What settings are you talking about?

@sivakov512
Copy link
Author

As far as I know this is a workspace/didChangeConfiguration.
It allow to pass settings for concrete language server. For example, pyls.configurationSources.

vscode accept a reference from language server like this https://github.com/palantir/python-language-server/blob/develop/vscode-client/package.json#L19

Without this feature I can not use this this plugin (

@bkchr
Copy link
Contributor

bkchr commented Nov 12, 2017

Yeah, as I have shown, you need to use lsp--set-configuration to send a workspace/didChangeConfiguration. You probably need to add a pr for lsp-python. The code would need to look like the following:

(defvar lsp-python--config-options (make-hash-table))

(defun lsp-python--set-configuration ()
  (lsp--set-configuration `(:pyls ,lsp-python--config-options)))

(add-hook 'lsp-after-initialize-hook 'lsp-python--set-configuration)

(defun lsp-python-set-config (name option)
  "Set a config option in the python lsp server."
  (puthash name option lsp-python--config-options))

(defun lsp-python-set-jedi-completion-enabled (enable)
  "Enable(t)/Disable(nil) the jedi completion plugin."
(lsp-python-set-config "plugins.jedi_completion.enabled" enable))

You will need to look into the linked package.json for all supported properties.

Edit:
I'm unsure with the following line (lsp--set-configuration `(:pyls ,lsp-python--config-options)), that probably need to look a little bit different, because the json for the python lsp server has more levels than the rust lsp server configuration json.

@sivakov512
Copy link
Author

@bkchr, thanks for help!
As it is then used? just call the appropriate function in my .dir-locals?

@sivakov512
Copy link
Author

sivakov512 commented Nov 13, 2017

I do not have a good experience with elisp ... @bkchr, can you help me with an example of how to set a value for a configurationSources property?

Interested property from package.json:

"pyls.configurationSources": {
                    "type": "array",
                    "default": ["pycodestyle"],
                    "description": "List of configuration sources to use.",
                    "items": {
                        "type": "string",
                        "enum": ["pycodestyle", "pyflakes"]
                    }

@bkchr
Copy link
Contributor

bkchr commented Nov 14, 2017

Sorry for the late answer. I'm also not the greatest elisp pro.

You could try:

 (lsp--set-configuration `(:pyls , (:configurationSources . ("pycodestyle", "pyflakes")))

You need to call this function after the lsp-workspace was setup correctly, so I'm unsure if the .dirlocals is the right file for that. I don't know when this file is loaded.

@sivakov512
Copy link
Author

Thanks for the help!

It seems to me that such implementations at the level of a separate plugin are rather complicated. It would be cool to be able to describe the configuration yaml-file at the project level.

@bkchr
Copy link
Contributor

bkchr commented Nov 14, 2017

Or maybe directly as json :D

@sivakov512
Copy link
Author

json is too hard for humans, but yaml is great =)

In any case it seems to me more convenient than writing functions in each separate plugin

@vibhavp
Copy link
Member

vibhavp commented Nov 14, 2017 via email

@sivakov512
Copy link
Author

vscode store setting in <project_dir/.vscode/settings.json
For example

{
    "python.pythonPath": "/home/cryptomaniac/Devel/Envs/py3_backoffice/bin/python",
    "python.envFile": "${workspaceRoot}/src/app/.env"
  }

Plugins provides allowed settings for vscode with files like this

@bkchr
Copy link
Contributor

bkchr commented Nov 14, 2017

I like the general idea, but for example for the rust language server I use some options that are globally the same for all my projects. I would not want to create configurations per project. So, we should find a way on how we could integrate both.

@cryptomaniac512 would you maybe want to create a pull request? Or do you think that your elisp knowledge is not sufficient?

@sivakov512
Copy link
Author

I would not want to create configurations per project.

vscode allow to store settings globally as user. For example this is my vscode settings (I tried to use it)

@sivakov512
Copy link
Author

sivakov512 commented Nov 14, 2017

vscode store setting in <project_dir/.vscode/settings.json

In reading the vscode settings it's the problem that they do not describe the configuration for the language server, but for the plug-in for the vscode that uses the language server

@sivakov512
Copy link
Author

sivakov512 commented Nov 14, 2017

would you maybe want to create a pull request? Or do you think that your elisp knowledge is not be enough?

I want it, but my elisp knowledge is bad (

it would be cool to quickly study it and try to do it yourself, for example, but I could not find worthy materials for this...

I'll try to do this in the next couple of weeks.

@ptxmac
Copy link

ptxmac commented Jan 4, 2018

Any update on this?

@cpbotha
Copy link

cpbotha commented Jun 8, 2018

I'm currently doing it in my init.el like this:

  ;; send pyls config via lsp-after-initialize-hook -- harmless for
  ;; other servers due to pyls key, but would prefer only sending this
  ;; when pyls gets initialised (:initialize function in
  ;; lsp-define-stdio-client is invoked too early (before server
  ;; start)) -- cpbotha
  (defun lsp-set-cfg ()
    (let ((lsp-cfg `(:pyls (:configurationSources ("flake8")))))
      ;; TODO: check lsp--cur-workspace here to decide per server / project
      (lsp--set-configuration lsp-cfg)))
 
  (add-hook 'lsp-after-initialize-hook 'lsp-set-cfg)

@yyoncho
Copy link
Member

yyoncho commented Dec 20, 2018

Now dir locals could be used in combination of :initialized-fn function in lsp--client .

@yyoncho yyoncho closed this as completed Dec 20, 2018
@arkhan
Copy link

arkhan commented Jan 8, 2019

Greetings @yyoncho , some example to be able to replicate it?

@yyoncho
Copy link
Member

yyoncho commented Jan 8, 2019

@arkhan - which language server do you want to use?

@arkhan
Copy link

arkhan commented Jan 8, 2019

@yyoncho

@arkhan - which language server do you want to use?

Python

@yyoncho
Copy link
Member

yyoncho commented Jan 8, 2019

@arkhan
Here it is the example what has to be performed for python and I have added 2 of the required properties:

yyoncho@72186e1

The rest of the settings(+ defaults) are here: https://raw.githubusercontent.com/palantir/python-language-server/develop/vscode-client/package.json

Do you want to provide a PR adding the rest of the properties? ( I could finish the PR when I have more time)

@arkhan
Copy link

arkhan commented Jan 8, 2019

@yyoncho
I'm trying to use only falke8 but I can not find a way to do it

@yyoncho
Copy link
Member

yyoncho commented Jan 9, 2019

@arkhan
If there is no such setting in https://raw.githubusercontent.com/palantir/python-language-server/develop/vscode-client/package.json you should ask in pyls project how to do that. My guess is that you could specify what pyls should use when it is installed, e. g. pip install 'python-language-server[yapf]'

@noctuid
Copy link

noctuid commented Feb 10, 2019

@yyoncho It would be awesome to have lsp-clients-python-settings. Does it actually need to contain all settings to work or could it just contain the settings that are different from the defaults?

@yyoncho
Copy link
Member

yyoncho commented Feb 10, 2019

@noctuid I do not use pyls, my guess is that the settings should be present in the set configuration request or it will default to nil/false.

@yyoncho
Copy link
Member

yyoncho commented Feb 10, 2019

@noctuid just saw that user @hrehfeld have converted the vscode json to elisp - I will cleanup/organize and commit the changes.

@axelson
Copy link
Contributor

axelson commented Mar 12, 2019

Is there an example of setting configuration when you run with only use-package instead of a custom plugin that calls lsp-register-client?

@yyoncho
Copy link
Member

yyoncho commented Mar 13, 2019

@axelson the best option is to extend the language server configuration that you want to use in lsp-clients.el to expose these options as a defcustom and then you could customize them in use-package. You may take a look at lsp-clients.el (go lang server in particular).

You may register a function or the language server settings your language server using lsp-mode internal api but the approach with defcustoms is the recommended one.

(setf (lsp--client-initialization-options (gethash 'ccls lsp-clients))  options...)

@axelson
Copy link
Contributor

axelson commented Mar 13, 2019

@yyoncho okay, thanks. I'll give that a shot.

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

9 participants