robocorp / robotframework-lsp

Robocorp extensions for VS Code: Robocorp Code and RFW LSP
https://robocorp.com/docs/developer-tools/visual-studio-code
Apache License 2.0
205 stars 93 forks source link

Configuration from pyproject.toml #908

Open drunyd opened 1 year ago

drunyd commented 1 year ago

I am able to use robotframework-lsp from within EMACS. lsp-mode can fire it up for me fine. But I can not set configuration.

Describe the solution you'd like If configurations config could be set in pyproject.toml file. Like robot.variables etc. it would be perfect...

Is it already possible and I just do not know the proper sytax? Thanks in advance

fabioz commented 1 year ago

Unfortunately no, it's not possible to read that from a pyproject.toml right now.

The config must be set in the language server config (which is the responsibility of the language server client -- I bet that emacs lsp-mode does have a way to set configurations to a language server, but unfortunately I don't really know how emacs lsp-mode does that -- I'm not really an emacs user).

I'll leave the request open to set it through pyproject.toml, but I don't have any plans to tackle it on the short/mid term.

drunyd commented 1 year ago

Hello and thanks for the great work first of all.

Meanwhile, I managed to get the configuration to the server from Emacs. I'm leaving it here in case anyone else has the same struggle as I did.

Just as you said, lsp-mode has ways to handle this. One I have found is lsp-register-client function which launches the robotframework-ls if configured properly. Here's my configuration:

(use-package lsp-mode
  :config
  (lsp-register-client
   (make-lsp-client :new-connection (lsp-stdio-connection '("python3.8" "-m" "robotframework_ls"))
            :major-modes '(robot-mode)
            :server-id 'robot-framework-ls
            :priority 0
                    :initialized-fn (lambda (workspace)
                      (with-lsp-workspace workspace
                    (lsp--set-configuration  rsettings))))))

The main part of my configuration is the :initialized-fn where I am sending the configuration via the rsettings variable. You can set the config there like this:

For robot.variables, create a hash-table and push in the variables you want to set:

(setq rf-variables (make-hash-table :test 'equal))

(puthash "VARIABLE1" "value1" rf-variables)
(puthash "VARIABLE2" "value2" rf-variables)

When you set them up, add it to the rsettings along with other single value configuration settings (like the lint.robotcop below):


(setq rsettings (list (cons (intern "robot.lint.robocop.enabled") "true")
                  (cons (intern "robot.variables") rf-variables)))

This should fire up the lsp for you in Emacs with the config you want. I'm planning to make a module for this so Emacs users can easily set it in the future. Not as if it would be difficult now.

Anyway, thanks for the great work. I'm still looking for more ways to use the provided features in Emacs. But your work is definitely a great help and makes my work much more fun and easy!