diff --git a/docs/modules.org b/docs/modules.org index 1ca5b2da0..51cf378ee 100644 --- a/docs/modules.org +++ b/docs/modules.org @@ -152,6 +152,7 @@ Modules that bring support for a language or group of languages to Emacs. + terra - TODO + web =+lsp= - HTML and CSS (SCSS/SASS/LESS/Stylus) support. + [[file:../modules/lang/yaml/README.org][yaml]] =+lsp= - TODO ++ [[file:../modules/lang/zig/README.org][zig]] =+lsp= - Zig support. * :os diff --git a/init.example.el b/init.example.el index d592b0911..113e5b0a7 100644 --- a/init.example.el +++ b/init.example.el @@ -168,6 +168,7 @@ ;;terra ; Earth and Moon in alignment for performance. ;;web ; the tubes ;;yaml ; JSON, but readable + ;;zig ; C, but simpler :email ;;(mu4e +gmail) diff --git a/modules/lang/zig/README.org b/modules/lang/zig/README.org new file mode 100644 index 000000000..da69d1b32 --- /dev/null +++ b/modules/lang/zig/README.org @@ -0,0 +1,66 @@ +#+TITLE: lang/zig +#+DATE: March 18, 2021 +#+SINCE: v2.0.9 +#+STARTUP: inlineimages nofold + +* Table of Contents :TOC_3:noexport: +- [[#description][Description]] + - [[#maintainers][Maintainers]] + - [[#module-flags][Module Flags]] + - [[#plugins][Plugins]] +- [[#prerequisites][Prerequisites]] +- [[#features][Features]] + - [[#lsp-support][LSP support]] + - [[#keybinds][Keybinds]] +- [[#configuration][Configuration]] + - [[#customize-zls-path][Customize zls path]] + +* Description +This module adds [[https://ziglang.org/][Zig]] support, with optional (but recommended) LSP support via +[[https://github.com/zigtools/zls][zls]]. + ++ Syntax highlighting ++ Syntax-checking (~flycheck~) ++ Code completion and LSP integration (~zls~) + +** Maintainers ++ [[https://github.com/bnjmnt4n][@bnjmnt4n]] (Author) + +** Module Flags ++ =+lsp= Enables integration for the zls LSP server. It is highly recommended + you use this. + +** Plugins ++ [[https://github.com/ziglang/zig-mode][zig-mode]] + +* Prerequisites +To get started with Zig, you need the ~zig~ tool. Pre-built binaries for most +systems are available for download from [[https://ziglang.org/download/]] or from +[[https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager][system package managers]]. + +zls is a language server for Zig, which provides code completion, + +* Features +** LSP support +This module supports LSP integration. For it to work you'll need: + +1. zls installed. +2. The =:tools lsp= module enabled. Only =lsp-mode= is supported for now. +3. The ~+lsp~ flag on this module enabled. + +** Keybinds +| Binding | Description | +|-------------------+---------------------| +| ~ b~ | ~zig-compile~ | +| ~ f~ | ~zig-format-buffer~ | +| ~ r~ | ~zig-run~ | +| ~ t~ | ~zig-test-buffer~ | + +* Configuration +** Customize zls path +To customize the path of the =zls= executable, modify ~lsp-zig-zls-executable~. + +#+BEGIN_SRC elisp +;; in $DOOMDIR/config.el +(setq lsp-zig-zls-executable "~/path/to/zls") +#+END_SRC diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el new file mode 100644 index 000000000..733223254 --- /dev/null +++ b/modules/lang/zig/config.el @@ -0,0 +1,32 @@ +;;; lang/zig/config.el -*- lexical-binding: t; -*- + +(after! projectile + (add-to-list 'projectile-project-root-files "build.zig")) + + +;; +;;; Packages + +(use-package! zig-mode + :hook (zig-mode . rainbow-delimiters-mode) + :config + (setq zig-format-on-save (featurep! :editor format +onsave)) + + (when (featurep! +lsp) + (add-hook 'zig-mode-local-vars-hook #'lsp!)) + + (when (featurep! :checkers syntax) + (flycheck-define-checker zig + "A zig syntax checker using the zig-fmt interpreter." + :command ("zig" "fmt" (eval (buffer-file-name))) + :error-patterns + ((error line-start (file-name) ":" line ":" column ": error: " (message) line-end)) + :modes zig-mode) + (add-to-list 'flycheck-checkers 'zig)) + + (map! :localleader + :map zig-mode-map + "b" #'zig-compile + "f" #'zig-format-buffer + "r" #'zig-run + "t" #'zig-test-buffer)) diff --git a/modules/lang/zig/doctor.el b/modules/lang/zig/doctor.el new file mode 100644 index 000000000..ecbeca1a1 --- /dev/null +++ b/modules/lang/zig/doctor.el @@ -0,0 +1,13 @@ +;; -*- lexical-binding: t; no-byte-compile: t; -*- +;;; lang/zig/doctor.el + +(assert! (or (not (featurep! +lsp)) + (featurep! :tools lsp)) + "This module requires (:tools lsp)") + +(unless (executable-find "zig") + (warn! "Couldn't find zig binary")) + +(when (featurep! +lsp) + (unless (executable-find "zls") + (warn! "Couldn't find zls binary"))) diff --git a/modules/lang/zig/packages.el b/modules/lang/zig/packages.el new file mode 100644 index 000000000..dd7274664 --- /dev/null +++ b/modules/lang/zig/packages.el @@ -0,0 +1,4 @@ +;; -*- no-byte-compile: t; -*- +;;; lang/zig/packages.el + +(package! zig-mode :pin "2d0eb23e6b5c12b946f12c23803157605c90f02f") diff --git a/modules/tools/lsp/README.org b/modules/tools/lsp/README.org index 923c6aa83..bbd277d8e 100644 --- a/modules/tools/lsp/README.org +++ b/modules/tools/lsp/README.org @@ -56,6 +56,7 @@ As of this writing, this is the state of LSP support in Doom Emacs: | [[../../lang/swift/README.org][:lang swift]] | swift-mode | sourcekit | | [[../../lang/web/README.org][:lang web]] | web-mode, css-mode, scss-mode, sass-mode, less-css-mode | vscode-css-languageserver-bin, vscode-html-languageserver-bin | | [[../../lang/purescript/README.org][:lang purescript]] | purescript-mode | purescript-language-server | +| [[../../lang/zig/README.org][:lang zig]] | zig-mode | zls | ** Module Flags + =+peek= Use =lsp-ui-peek= when looking up definitions and references with