thanhvg / lspce

LSP Client for Emacs implemented as a module using rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LSPCE

Introduction

LSPCE - LSP Client for Emacs, is a simple lsp client that is implemented as an Emacs module.

CAUTION: This package is still in beta stage, and I’ve just tested it with Emacs 28 running in Linux.

It does not want to be a full-featured lsp client. The features it supports are:

  • find definitions/references/implementatoins (as a xref backend)
  • completion (as a capf function) support snippet and auto import.
  • diagnostics (as a flymake backend) process diagnostics when idle.
  • hover (triggered by lspce-help-at-point)
  • signature/hover help (as an eldoc-documentation-functions function)
  • code action (triggered by lspce-code-actions)
  • rename (triggered by lspce-rename )

All features I need have been implemented now, and my next step is to make it more robust and more performant.

I have tested LSPCE with `pyright` and `rust-analyzer` in Emacs 28, and I’m using it to develop itself :).

Below are some images to illustrate what LSPCE looks like.

Complete using company-capf. images/completion.png

Use xref to find references. images/references.png

Display signature and hover at the same time. images/eldoc.png

Installation

At the moment, you can only install LSPCE by cloning this repo and compile rust code manually.

Installing from the Git Repository

Before installing LSPCE, you should install rust and cargo.

$ 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 can rename the .so file (and copy it to another directory )
$ mv target/debug/liblspce_module.so lspce-module.so 

Or (if you use Linux) you can download a .so file I compiled on a Manjaro with rust 1.61.0.

Get started

You need to install f.el and yasnippet .

(use-package lspce
  :load-path "/path/to/lspce/lisp"
  :config (progn
            (setq lspce-send-changes-idle-time 1)

            ;; log file
            (lspce-set-log-file "/tmp/lspce.log")

            ;; By default, lspce will write log to what `lspce-set-log-file' sets.
            ;; To disable logging, use 
            ;; (lspce-disable-logging)
            ;; You can enable logging on the fly by calling `lspce-enable-logging'

            ;; enable lspce in particular buffers
            ;; (add-hook 'rust-mode-hook 'lspce-mode)

            ;; modify `lspce-server-programs' to add or change a lsp server, see document
            ;; of `lspce-lsp-type-function' to understand how to get buffer's lsp type.
            )
  )

Architecture

images/Architecture_of_LSPCE.png

Some notes about the architecture:

  1. Every project is represented by a Project struct in LSPCE (aka the largest Box in the above image).
  2. LSPCE sends requests/notifications to LSP server(rust-analyzer, pyright, etc.) processes via a Transport.
  3. Responses/notifications/requests issued by LSP servers are sent to Transport and then dispatched into three different queues by Message Dispatcher. Note that diagnositcs are disptched into a separate queue, from where LSPCE reads them and shows them using flymake.
  4. After sending a request, LSPCE will read the response from the response queue in an interruptable way, so it won’t block Emacs.

TODOs

There are some bugs/issues that should be fixed. Here is the list:

  • renaming class name in Java won’t rename the file name (LSPCE does not support file rename/create/delete now)
  • support server request `workspace/configuration` I’ve decided not to support it, unless this makes it impossible to implement some necessary features/functions.
  • support workspaceFolders (or not, not decided yet)
  • new created files cannot be recognized by lsp server (workaround: revert it or close and then open it)
  • diagnostics does not work well, sometimes they won’t disappear.
  • completion has a little bug, where it may complete foo.bar to foo.barb when current text is foo.b
  • after editing pom.xml, jdt.ls cannot automatically update configuration(e.g. cannot find class from the new added jar)

Acknowledgements

Thanks to emacs-module-rs, which makes implementing LSPCE possible.

Thanks to eglot and lsp-mode, I learned a lot about LSP from both of them during developing this package.

Thanks to lsp-server from rust-analyzer, I used a lot of code from it (and modified them a little to make it suitable for a client).

About

LSP Client for Emacs implemented as a module using rust.


Languages

Language:Emacs Lisp 72.4%Language:Rust 27.6%