From add0c567ad4377ceba9ce92be0bb369dde9d73dc Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Sun, 21 Mar 2021 17:28:32 +0800 Subject: [PATCH] Emacs: update setup instructions `lsp-mode` now has built-in configuration for zls, so the only configuration that might be required is setting the location of the zls executable (or placing it in the PATH). `doom-emacs` has not updated to use the latest version of `lsp-mode` yet, so its configuration cannot be simplified. However, I've updated the snippet for configuration to avoid loading `lsp-mode` on startup, which can cause significant slowdown to Emacs startup, and instead defer loading it until it is required. --- README.md | 31 +++++++++++++++---------------- build.zig | 29 ++++++++++++----------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 4957240..63ce4fc 100644 --- a/README.md +++ b/README.md @@ -216,13 +216,12 @@ let g:LanguageClient_serverCommands = { - [zig mode](https://github.com/ziglang/zig-mode) is also useful ```elisp -(require 'lsp) -(add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) -(lsp-register-client - (make-lsp-client - :new-connection (lsp-stdio-connection "") - :major-modes '(zig-mode) - :server-id 'zls)) +;; Setup lsp-mode as desired. +;; See https://emacs-lsp.github.io/lsp-mode/page/installation/ for more information. +(require 'lsp-mode) + +;; Either place zls in your PATH or add the following: +(setq lsp-zig-zls-executable "") ``` ### Doom Emacs @@ -231,17 +230,17 @@ let g:LanguageClient_serverCommands = { - Install the [zig-mode](https://github.com/ziglang/zig-mode) package (add `(package! zig-mode)` to your `packages.el` file ```elisp -(require 'lsp) (use-package! zig-mode - :hook ((zig-mode . lsp)) + :hook ((zig-mode . lsp-deferred)) :custom (zig-format-on-save nil) - :init - (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) - (lsp-register-client - (make-lsp-client - :new-connection (lsp-stdio-connection "") - :major-modes '(zig-mode) - :server-id 'zls))) + :config + (after! lsp-mode + (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) + (lsp-register-client + (make-lsp-client + :new-connection (lsp-stdio-connection "") + :major-modes '(zig-mode) + :server-id 'zls)))) ``` ## Related Projects diff --git a/build.zig b/build.zig index 9c2e565..799ecf3 100644 --- a/build.zig +++ b/build.zig @@ -146,31 +146,26 @@ pub fn config(step: *std.build.Step) anyerror!void { \\Zig mode (https://github.com/ziglang/zig-mode) is also useful! \\Then, add the following to your emacs config: \\ - \\(require 'lsp) - \\(add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) - \\(lsp-register-client - \\ (make-lsp-client - \\ :new-connection (lsp-stdio-connection "") - \\ :major-modes '(zig-mode) - \\ :server-id 'zls)) + \\(require 'lsp-mode) + \\(setq lsp-zig-zls-executable "") , .{}); }, .Doom => { std.debug.warn( \\To use ZLS in Doom Emacs, enable the lsp module - \\And install the zig mode (https://github.com/ziglang/zig-mode) package by adding `(package! zig-mode)` to your packages.el file. + \\And install the `zig-mode` (https://github.com/ziglang/zig-mode) package by adding `(package! zig-mode)` to your packages.el file. \\ - \\(require 'lsp) \\(use-package! zig-mode - \\ :hook ((zig-mode . lsp)) + \\ :hook ((zig-mode . lsp-deferred)) \\ :custom (zig-format-on-save nil) - \\ :init - \\ (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) - \\ (lsp-register-client - \\ (make-lsp-client - \\ :new-connection (lsp-stdio-connection "") - \\ :major-modes '(zig-mode) - \\ :server-id 'zls))) + \\ :config + \\ (after! lsp-mode + \\ (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) + \\ (lsp-register-client + \\ (make-lsp-client + \\ :new-connection (lsp-stdio-connection "") + \\ :major-modes '(zig-mode) + \\ :server-id 'zls)))) , .{}); }, .Other => {