jadestrong / lsp-copilot

An LSP client for Emacs implemented in Rust.
GNU General Public License v3.0
12 stars 0 forks source link

+title: LSP-COPILOT

The features it supports are:

[[file:images/show.gif]]

+begin_src elisp

;; Doom Emacs (set-lookup-handlers! 'lsp-copilot-mode :definition '(lsp-copilot-find-definition :async t) :references '(lsp-copilot-find-references :async t) :implementations '(lsp-copilot-find-implementations :async t) :type-definition '(lsp-copilot-find-type-definition :async t) :documentation '(lsp-copilot-describe-thing-at-point :async t))

+end_src

The configuration for a new language can refer to the [[https://github.com/helix-editor/helix/blob/master/languages.toml][Helix configuration]]. Supported fields are based on [[https://github.com/jadestrong/lsp-copilot/blob/main/languages.toml][the built-in configuration file]], and only LSP-related fields are supported. Open custom language config file by ~lsp-copilot-open-config-file~ and add your config, then execute ~lsp-copilot-restart~.

The configuration fields for adding language support are: ~name、roots、language-id、file-types、language-servers~ . Other fields in the Helix configuration are not supported.

[[language]] name = "vue" roots = ["package.json"] language-id = "vue" file-types = ["vue"] language-servers = ["vls"]

+end_src

+begin_src toml

[language-server.typescript-language-server] config.plugins = [ { name = "@vue/typescript-plugin", location = "${your-path}/node_modules/@vue/typescript-plugin", languages = ["vue"]} ]

[language-server.vue-language-server] command = "vue-language-server" args = ["--stdio"] config.typescript = { tsdk = "${your-path}/node_modules/typescript/lib" } config.vue = { hybridMode = false }

[[language]] name = "vue" roots = ["package.json"] language-id = "vue" file-types = ["vue", "ts"] language-servers = ["vue-language-server", "typescript-language-server"]

Override the build-in config. The built-in configuration uses vtsls, but it seems incompatible with vue-language-server. It could also be that my configuration is incorrect.

Others, such as JavaScript and TSX, can be added as needed.

[[language]] name = "typescript" language-id = "typescript" file-types = ["ts", "mts", "cts"] roots = ["package.json"] language-servers = [ { name = "typescript-language-server", except-features = [ "format", ] }, { name = "eslint", support-workspace = true, config-files = [".eslintrc.js", ".eslintrc.cjs", ".eslintrc.yaml", ".eslintrc.yml", ".eslintrc", ".eslintrc.json"] }, ]

+end_src

;; corfu (setq corfu-auto-delay 0) (setq corfu-popupinfo-delay '(0.1 . 0.1))

+end_src

** company-box

+begin_src elisp

(defun company-box-icons--lsp-copilot (candidate) (-when-let* ((copilot-item (get-text-property 0 'lsp-copilot--item candidate)) (lsp-item (plist-get copilot-item :item)) (kind-num (plist-get lsp-item :kind))) (alist-get kind-num company-box-icons--lsp-alist)))

(setq company-box-icons-functions (cons #'company-box-icons--lsp-copilot company-box-icons-functions))

+end_src

** flycheck or flymake Currently, only Flycheck is supported. You can refer to the configuration in [[https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-diagnostics.el][lsp-mode]] to add support for others.

Regarding the communication between Emacs and Lsp-Copilot, I would like to especially thank [[https://github.com/copilot-emacs/copilot.el][copilot.el]] and [[https://github.com/rust-lang/rust-analyzer][rust-analyzer]]. The usage of jsonrpc.el was learned from copilot.el, while the approach to receiving and handling Emacs requests was inspired by the implementation in rust-analyzer.

The various methods used to implement LSP-related functionality on the Emacs side were learned from [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]] and [[https://github.com/joaotavora/eglot][eglot]]. Without their guidance, many of these features would have been difficult to implement.

Regarding the communication data format between Emacs and Lsp-Copilot, I would like to especially thank [[https://github.com/blahgeek/emacs-lsp-booster][emacs-lsp-booster]]. The project integrates the implementation of emacs-lsp-booster, which encodes the JSON data returned to Emacs, further reducing the load on Emacs.