Nox
Nox is a lightweight, high-performance LSP client for Emacs
Install / Use
/learn @manateelazycat/NoxREADME
NOTE
Thanks to all users who support Nox, I have develop new LSP client lsp-bridge -- the fastest LSP client for Emacs.
The issue and PR of current project will no longer reply, thank you! ;)
Nox
Nox is a LSP client for Emacs, code fork from eglot.
The project has three goals:
- Function: only provide core functions, include code completion, jump definition, code references and rename
- Design: Keep UX simple and clean, does not interfere user
- Performance: cutting useless functions, optimizing code efficiency, ensure coding fluency
Why named Nox?
The Nox are considered to be a member of the Alliance of Four Great Races", along with the Alterans, Asgard, and Furlings.
My favorite a word from Nox:
Maybe one day you will learn, that your way is not the only way -- Anteaus
Install dependences
Nox depend on company-mode and posframe
Install Nox
-
Clone this repository and put nox.el in your load-path
-
Add below configure in your ~/.emacs
(require 'nox)
(dolist (hook (list
'js-mode-hook
'rust-mode-hook
'python-mode-hook
'ruby-mode-hook
'java-mode-hook
'sh-mode-hook
'php-mode-hook
'c-mode-common-hook
'c-mode-hook
'csharp-mode-hook
'c++-mode-hook
'haskell-mode-hook
))
(add-hook hook '(lambda () (nox-ensure))))
- Open file, that's all.
Note: suggestion upgrade emacs to 27.x or 28.x, JSON parser much faster, and Nox completion will much smooth.
<a name="connecting"></a>
Connecting to a server
M-x nox can guess and work out-of-the-box with these servers:
- Javascript's [javascript-typescript-stdio][javascript-typescript-langserver]
- Rust's [rls][rls]
- Python's [mspyls][mspyls], [pyls][pyls] or [pyright][pyright]
- Ruby's [solargraph][solargraph]
- Java's [Eclipse JDT Language Server][eclipse-jdt]
- Bash's [bash-language-server][bash-language-server]
- PHP's [intelephense][intelephense] or [php-language-server][php-language-server]
- C/C++'s [ccls][ccls] ([cquery][cquery] and [clangd][clangd] also work)
- CSharp [OmniSharp][OmniSharp]
- Haskell's [IDE engine][haskell-ide-engine]
- Elm's [elm-language-server][elm-language-server]
- Kotlin's [kotlin-language-server][kotlin-language-server]
- Go's [gopls][gopls]
- Ocaml's [ocaml-language-server][ocaml-language-server]
- R's [languageserver][r-languageserver]
- Dart's [dart_language_server][dart_language_server]
- Elixir's [elixir-ls][elixir-ls]
- Ada's [ada_language_server][ada_language_server]
- Scala's [metals][metals]
- TeX/LaTeX's [Digestif][digestif]
- Dockerfile's [dockerfile_language_server][dockerfile_language_server]
- HTML [html_language_server][html_language_server]
- CSS's [css_language_server][css_language_server]
- JSON's [json_language_server][json_language_server]
I'll add to this list as I test more servers. In the meantime you can
customize nox-server-programs:
(add-to-list 'nox-server-programs '(foo-mode . ("foo-language-server" "--args")))
Let me know how well it works and we can add it to the list.
To skip the guess and always be prompted use C-u M-x nox.
Connecting via TCP
The examples above use a "pipe" to talk to the server, which works fine on Linux and OSX but in some cases [may not work on Windows][windows-subprocess-hang].
To circumvent this limitation, or if the server doesn't like pipes,
you can use C-u M-x nox and give it server:port pattern to
connect to a previously started TCP server serving LSP information.
If you don't want to start it manually every time, you can configure Nox to start it and immediately connect to it. Ruby's [solargraph][solargraph] server already works this way out-of-the-box.
For another example, suppose you also wanted start Python's pyls
this way:
(add-to-list 'nox-server-programs
`(python-mode . ("pyls" "-v" "--tcp" "--host"
"localhost" "--port" :autoport)))
You can see that the element associated with python-mode is now a
more complicated invocation of the pyls program, which requests that
it be started as a server. Notice the :autoport symbol in there: it
is replaced dynamically by a local port believed to be vacant, so that
the ensuing TCP connection finds a listening server.
Per-project server configuration
Most servers can guess good defaults and will operate nicely out-of-the-box, but some need to be configured specially via LSP interfaces. Additionally, in some situations, you may also want a particular server to operate differently across different projects.
Per-project settings are realized with Emacs's directory variables
and the Elisp variable nox-workspace-configuration. To make a
particular Python project always enable Pyls's snippet support, put a
file named .dir-locals.el in the project's root:
((python-mode
. ((nox-workspace-configuration
. ((:pyls . (:plugins (:jedi_completion (:include_params t)))))))))
This tells Emacs that any python-mode buffers in that directory
should have a particular buffer-local value of
nox-workspace-configuration. That variable's value should be
association list of parameter sections which are presumably
understood by the server. In this example, we associate section
pyls with the parameters object (:plugins (:jedi_completion (:include_params t))).
Now, supposing that you also had some Go code in the very same
project, you can configure the Gopls server in the same file. Adding
a section for go-mode, the file's contents become:
((python-mode
. ((nox-workspace-configuration
. ((:pyls . (:plugins (:jedi_completion (:include_params t))))))))
(go-mode
. ((nox-workspace-configuration
. ((:gopls . (:usePlaceholders t)))))))
If you can't afford an actual .dir-locals.el file, or if managing
these files becomes cumbersome, the Emacs manual teaches you
programmatic ways to leverage per-directory local variables.
Handling quirky servers
Some servers need even more special hand-holding to operate correctly. If your server has some quirk or non-conformity, it's possible to extend Nox via Elisp to adapt to it. Here's an example on how to get [cquery][cquery] working:
(add-to-list 'nox-server-programs '((c++ mode c-mode) . (nox-cquery "cquery")))
(defclass nox-cquery (nox-lsp-server) ()
:documentation "A custom class for cquery's C/C++ langserver.")
(cl-defmethod nox-initialization-options ((server nox-cquery))
"Passes through required cquery initialization options"
(let* ((root (car (project-roots (nox--project server))))
(cache (expand-file-name ".cquery_cached_index/" root)))
(list :cacheDirectory (file-name-as-directory cache)
:progressReportFrequencyMs -1)))
See nox.el's section on Java's JDT server for an even more
sophisticated example.
<a name="reporting bugs"></a>
Reporting bugs
Having trouble connecting to a server? Expected to have a certain capability supported by it (e.g. completion) but nothing happens? Or do you get spurious and annoying errors in an otherwise smooth operation? We may have help, so open a new issue and try to be as precise and objective about the problem as you can:
-
Try to replicate the problem with as clean an Emacs run as possible. This means an empty
.emacsinit file or close to it (just loadingnox.el,company.elandyasnippet.elfor example, and you don't even needuse-package.elto do that). -
Include the log of LSP events and the stderr output of the server (if any). You can find the former with
M-x nox-events-bufferand the latter withM-x nox-stderr-buffer. You run these commands in the buffer where you enabled Nox, but if you didn't manage to enable Nox at all (because of some bootstrapping problem), you can still find these buffers in your buffer list: they're named like*NOX <project>/<major-mode> events*and*NOX <project>/<major-mode> stderr*. -
If Emacs errored (you saw -- and possibly heard -- an error message), make sure you repeat the process using
M-x toggle-debug-on-errorso you get a backtrace of the error that you should also attach to the bug report.
Some more notes: it's understandable that you report it to Nox first, because that's the user-facing side of the LSP experience in Emacs, but the outcome may well be that you will have to report the problem to the server's developers, as is often the case. But the problem can very well be on Nox's side, of course, and in that case we want to fix it! Also bear in mind that Nox's developers have limited resources and no way to test all the possible server combinations, so you'll have to do most of the testing.
<a name="commands"></a>
Commands and keybindings
Here's a summary of available commands:
-
M-x nox, as described above; -
M-x nox-reconnectreconnects to the server; -
M-x nox-shutdownsays bye-bye to the server; -
M-x nox-renameask the server to rename the symbol at point, if rename work, please use commandnox-stderr-buffer, must something rename tool not install, sch as python needropefor rename operation; -
M-x nox-formatasks the server to format buffer or the active region; -
M-x nox-show-docshow documentation for symbol at point. -
M-x nox-events-bufferjumps to the events buffer for debugging communication with the server. -
M-x nox-stderr-bufferif the LSP server is printing useful debug information in stderr, jumps to a buffer with these contents. -
M-x nox-signal-didChangeConfigurationupdates t
