Open chasecaleb opened 1 year ago
I have the same issue with the same setup.
I also observe that automatic formatting is broken with nil
.
I'm not familiar with emacs but the log seems weird since it sends initializationOptions
but responding [nil]
for workspace/configuration
requests. I tried to use initializationOptions
with workspace/configuration
disabled under nvim and it seems to work fine.
Could you set env var NIL_LOG
to be nil=debug
and provide the stderr of the server? If it's hard to retrieve the server's stderr, NIL_LOG_PATH
can also be set to a file path to write the log into.
I have this working with the following config. looks like, when you set initializationOptions
for a language server, the options are nested under the name of the language server already. so, having your options under (:nil)
is actually incorrect.
(use-package eglot
:ensure nil
:after inheritenv
:hook
(prog-mode . eglot-ensure)
(prog-mode . (lambda () (add-hook 'before-save-hook 'eglot-format nil t)))
:config
(with-eval-after-load 'eglot
(dolist (mode '((nix-mode . ("nil" :initializationOptions
(:formatting (:command [ "nixpkgs-fmt" ]))))))
(add-to-list 'eglot-server-programs mode))))
@cmacrae This might be irrelevant to the original issue, but I had some problems setting this up. I did it without using the with-eval-after-load
macro and that didn't work although I see the eglot-server-programs
getting updated correctly. Your config worked for me, could you please explain why you're doing it this way?
@yzhou216 glad it works for you :) without with-eval-after-load
eglot may not have finished loading. even though eglot-server-programs
may be getting updated, if eglot hasn't finished loading, evaluation of the list may somehow not be effective - i can only surmise without digging into eglot's machinery
@cmacrae Thank you for the explanation! That was very helpful :)
Overview
I'm not sure if I'm doing it wrong or if there's a bug in either nil or Emacs eglot, so I'm hoping you can help me. I'm trying to switch from lsp-mode to eglot with Emacs 29 and I can't seem to get initialization-time formatter configuration to work. I expect that calling
eglot-format-buffer
should work regardless of whether the formatter is configured during initialization or at run-time, but only the latter does anything.For reference, here's an online version of eglot's info page: https://joaotavora.github.io/eglot/#User_002dspecific-configuration
Version info:
Broken: initializationOptions
Config:
LSP messages shown after loading a nix file and running
eglot-format-buffer
:I notice there's a
workspace/didChangeConfiguration
message here, even though I'm not telling eglot to do that sinceeglot-workspace-configuration
is nil, but I think(:settings #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ())))
represents an empty table?Working: post-initialization settings
If I use this config instead, formatting works:
Messages: