zbelial / lspce

LSP Client for Emacs implemented as a module using rust.
GNU General Public License v3.0
154 stars 11 forks source link

-- eval: (org-appear-mode -1); --

+TITLE: LSPCE

+AUTHOR: zbelial

+EMAIL: zjyzhaojiyang@gmail.com

+DATE: 2022

+LANGUAGE: en

** Installing from the Git Repository

+BEGIN_SRC bash

 $ git clone https://github.com/zbelial/lspce.git ~/.emacs.d/site-lisp/lspce
 $ cd ~/.emacs.d/site-lisp/lspce
 $ cargo build
 # or, to build a release version
 $ cargo build --release
 # then you should rename the .so file (and copy it to another directory )
 $ mv target/debug/liblspce_module.so lspce-module.so 
 # or alternatively, if .d and .dylib files are created for you: (thanks @fast-90 for this)
 $ mv target/debug/liblspce_module.d lspce-module.d
 $ mv target/debug/liblspce_module.dylib lspce-module.dylib

+END_SRC

** Installing using Straight

+BEGIN_SRC elisp

 (straight-use-package
  `(lspce :type git :host github :repo "zbelial/lspce"
          :files (:defaults ,(pcase system-type
                               ('gnu/linux "lspce-module.so")
                               ('darwin "lspce-module.dylib")))
          :pre-build ,(pcase system-type
                        ('gnu/linux '(("cargo" "build" "--release") ("cp" "./target/release/liblspce_module.so" "./lspce-module.so")))
                        ('darwin '(("cargo" "build" "--release") ("cp" "./target/release/liblspce_module.dylib" "./lspce-module.dylib"))))))

+END_SRC

** About lsp servers' stderr Lspce support writing stderr message from lsp servers to the log file (set up by calling lspce-set-log-file) in the log level ERROR, and the log contains string "[stderr]".

** MAX_DIAGNOSTIC_COUNT This variable is defined in rust code, you can customize it via =lspce-change-max-diagnostics-count= . If it's negative, then all diagnostics will be retrieved.

** Logging On rust code side, there are 5 log level: DISABLED(0), ERROR(1), INFO(2), TRACE(3), DEBUG(4), and the default level is INFO. You can use functions =lspce-set-log-level-xxxx= to change log level to specific level. Before adding log level feature, two commands, =lspce-enable-logging= and =lspce-disable-logging=, already exist, which enable/disable logging entirely. Now =lspce-enable-logging= is equivalent of setting log level to DEBUG, and =lspce-disable-logging= is equivalent of setting log level to DISABLED.

** About python virtual environment *** pylsp and jedi-language-server ATM, you can use virtual environments with both pylsp and jedi-language-server in lspce, all you need is a variable =lspce-jedi-environment=, which can be specified to point to the python interpreter, and a =.dir-locals.el= file. The following is a simple .dir-locals.el:

+BEGIN_SRC elisp

  ((python-mode
    . ((eval . (progn
                 (setq-local lspce-jedi-environment "/home/XXXX/tmp/venv/.venv/bin/python")))))
   (python-ts-mode
    . ((eval . (progn
                 (setq-local lspce-jedi-environment "/home/XXXX/tmp/venv/.venv/bin/python")))))
   )

#+END_SRC

And you can see how =lspce-jedi-environment= is used in =lspce-jedi-initializationOptions= and =lspce-pylsp-initializationOptions=.

*** pyright If you want to use pyright with lspce, =.dir-locals.el= can also help you. But I haven't tested it throughly.

+BEGIN_SRC elisp

  ((python-mode
    . ((eval . (progn
                 (setq-local exec-path (append (list "/home/XXXX/tmp/venv/.venv/bin/") exec-path))
                 (setq-local lspce-inherit-exec-path t)))))
   (python-ts-mode
    . ((eval . (progn
                 (setq-local exec-path (append (list "/home/XXXX/tmp/venv/.venv/bin/") exec-path))
                 (setq-local lspce-inherit-exec-path t))))))
#+END_SRC

I personally do NOT recommend to use lspce with pyright though, and please do NOT create issues about it. Thanks.

** About environment variables Sometime, you may need to pass some environment variables to rust code so that lspce can use these environment variables to start lsp server processes. You can use =lspce-envs-pass-to-subprocess= then, which is a list of environment variables, and the values of these environment variables are retrieved from =process-environment=, except ~PATH~, which is from =exec-path=.

The reason why this feature works in this way is I don't want lspce to be tightly bound with other tools, such as direnv, python's venv, and so on. So you should use someway to populate =process-environment= first if you want to use this feature.

=lspce-envs-pass-to-subprocess= has made =lspce-inherit-exec-path= obsolete, even you can still use it. The logic is: all environment variables will be passed, and if =lspce-inherit-exec-path= is set true, PATH will be passed too.

*** cons

** lspce vs lsp-mode *** pros

*** cons

** lspce vs lsp-bridge *** pros

*** cons