Skip to content

Commit

Permalink
improve Emacs documentation for eglot and code actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Nov 17, 2024
1 parent 8e218e2 commit 9dd7a95
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
10 changes: 9 additions & 1 deletion content/zls/editors/emacs.smd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ The available configuration are documented [here](https://emacs-lsp.github.io/ls

### source.fixAll

Running `source.fixall` code actions without enabling the `force_autofix` config option is currently not supported See [emacs-lsp/lsp-mode#1842](https://github.com/emacs-lsp/lsp-mode/issues/1842)
Running `source.fixall` code actions is not natively supported by lsp-mode. See [emacs-lsp/lsp-mode#1842](https://github.com/emacs-lsp/lsp-mode/issues/1842)

ZLS can work around this limitation by enabling the `force_autofix` config option.

># [ZLS 0.13.0]($block.attrs('note'))
>
>The behaviour of ZLS 0.13.0 (anything before `0.14.0-dev.214+05ea40b50` to be precise) is different from the current nightly build.
>
>The `enable_autofix` option must be used instead of `force_autofix`.

### source.organizeImports

Expand Down
61 changes: 55 additions & 6 deletions content/zls/editors/emacs/gnu-emacs.smd
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,67 @@
># [Author's Notice]($block.attrs('warning'))
> This Documentation is [incomplete](https://github.com/zigtools/www.zigtools.org/issues/1).

## Eglot
## [Eglot](https://www.gnu.org/software/emacs/manual/html_node/eglot/index.html)

1. Install [Melpa](https://melpa.org/#/getting-started)
2. Install [zig mode](https://github.com/ziglang/zig-mode) (optional)
2. Install [zig mode](https://github.com/ziglang/zig-mode)

You can use the builtin [Eglot](https://www.gnu.org/software/emacs/manual/html_node/eglot/index.html) LSP Client.
To apply [in-editor-configuration](/zls/configure/in-editor) or manually specify the path to `zig` or `zls`, add the following:

- Use the inbuilt eglot mode. Make sure ZLS is in your PATH.
```
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(zig-mode . (
;; Use `zls` if it is in your PATH
"/path/to/zls_executable"
;; There are two ways to set config options:
;; - edit your `zls.json` that applies to any editor that uses ZLS
;; - set in-editor config options with the `initializationOptions` field below.
;;
;; Further information on how to configure ZLS:
;; https://zigtools.org/zls/configure/
;;
;; Support for `initializationOptions` in Emacs requires at least ZLS `0.14.0-dev.22+a263b8dc6`.
:initializationOptions
(;; Whether to enable build-on-save diagnostics
;;
;; Further information about build-on save:
;; https://zigtools.org/zls/guides/build-on-save/
;;enable_build_on_save t

;; omit the following line if `zig` is in your PATH
:zig_exe_path "/path/to/zig_executable"
)))))
```

Use `M-x eglot` in a zig-mode buffer to start the server.
Eglot also supports Project-specific or User-specific [server configuration](https://www.gnu.org/software/emacs/manual/html_node/eglot/Advanced-server-configuration.html).

Eglot supports [In-Editor configuration](https://www.gnu.org/software/emacs/manual/html_node/eglot/Advanced-server-configuration.html)
Use `M-x eglot` in a zig-mode buffer to start the server or add a hook:

```
(add-hook 'zig-mode-hook 'eglot-ensure)
```

### Code Actions

### source.fixAll

Add the following to run `source.fixAll` code action on save:

```
(add-hook 'zig-mode-hook
(lambda ()
(add-hook 'before-save-hook
(lambda ()
(eglot-code-actions nil nil "source.fixAll" t)))))
```

### source.organizeImports

># [Note]($block.attrs('note'))
>The `source.organizeImports` code action is available since ZLS `0.14.0-dev.188+2be424de5`.

Use `M-x eglot-code-action-organize-imports` to manually execute the code action.

# lsp-mode

0 comments on commit 9dd7a95

Please sign in to comment.