joaotavora / eglot

A client for Language Server Protocol servers
GNU General Public License v3.0
2.27k stars 200 forks source link

Error in dotspacemacs/user-config: Symbol’s value as variable is void: eglot-server-programs #238

Closed cocodrino closed 5 years ago

cocodrino commented 5 years ago

Hello...I'm trying to add eglot for elixir to my spacemacs config, following this tutorial https://elixirforum.com/t/emacs-elixir-setup-configuration-wiki/19196

I add this to my user config

  (add-to-list
   'eglot-server-programs
   '(elixir-mode . ("sh" "/home/yo/Descargas/proj/elixir/elixir-ls/rel/language_server.sh")))
  )

that path exist and there is the file .sh

now when I restart I get this error


(Spacemacs) Error in dotspacemacs/user-config: Symbol’s value as variable is void: eglot-server-programs

do you know which could be the problem here? thank you so much

joaotavora commented 5 years ago

If you have (package-install 'eglot) somewhere in your config file and that happens before the the (add-to-list...) line, then it should work.

You can also try (require 'eglot) before teh (add-to-list...) line.

Other than that, I'm afraid I'm not of great "spacemacs" help. I use regular Emacs.

cocodrino commented 5 years ago

thank you so much @joaotavora , now the error was gone but still doesnt works, I opened an elixir file, then run the "eglot" command, nothing happen (neither error nor log)...if I run eglot-reconnect I get

jsonrpc-error: "No current JSON-RPC connection", (jsonrpc-error-code . 32603), (jsonrpc-error-message . "No current JSON-RPC connection")

my eglot config is

  (add-to-list
   'eglot-server-programs
   '(elixir-mode  "/home/yo/Descargas/proj/elixir/elixir-ls/rel/language_server.sh"))
  )

is it the right way to save the lsp path???...thank you so much joao...

cocodrino commented 5 years ago

update:

I change the config to

  (add-to-list
   'eglot-server-programs
   '(elixir-mode . ("sh" "/home/yo/Descargas/proj/elixir/elixir-ls/rel/language_server.sh")))

but not works neither, then I run eglot-shutdown and eglot again and seems works!...not works the autocomplete but I suppose than I still need some configuration

cocodrino commented 5 years ago

update...thanks @joaotavora , seems that I didn't need any other config, after run company I get aucompletion and works pretty well :smile:

but I don't get any warning with syntax error through flymake, I delete some function end keyword and I don't get any error...would be I missing some config?..thank you!

cocodrino commented 5 years ago

update...flymake seems work sometime, with small projects works great but with projects like phoenix based projects simply doesnt start...

I get this logs Warning [flymake mix.exs]: Disabling backend flymake-proc-legacy-flymake because (error Can’t find a suitable init function) Warning [flymake timer_channel.ex]: Disabling backend flymake-proc-legacy-flymake because (error Can’t find a suitable init function) Warning [flymake timer_channel.ex]: Disabling backend flymake-proc-legacy-flymake because (error Can’t find a suitable init function) Warning [flymake user_socket.ex]: Disabling backend flymake-proc-legacy-flymake because (error Can’t find a suitable init function)

not sure what these mean or if these logs are related to my issue...

joaotavora commented 5 years ago

not sure what these mean or if these logs are related to my issue...

They are not, don't worry about these.

nicobao commented 4 years ago

Hi! Got similar errors in Spacemacs. Rather annoying. It indeed appears rather randomly after a startup. Solution: Do NOT use the package-install command in spacemacs. Adding eglot in dotspacemacs-additional-packages is enough. Add in your (defun dotspacemacs/user-config ():

  (require 'eglot)
  (add-to-list 'eglot-server-programs '(elixir-mode "/home/nicolas/elixir-ls/release/language_server.sh"))

(Don't forget to edit the path to your language_server script, and choose the one that corresponds to your OS: .bat for Windows for instance.) You can also add after the require 'eglot instruction: (add-hook 'elixir-mode-hook 'eglot-ensure) to not have to type M-x eglot manually.

My full spacemacs config is here, in case you need more guidance: https://github.com/NicoGim/setup/blob/master/spacemacs/.spacemacs

Note: I tried before putting the require block in (defun dotspacemacs/user-load () where it would logically fits, but it simply does not work for me.

nicobao commented 4 years ago

Hi, for info I left more information on how to use Eglot in Spacemacs in the Elixir forum: https://elixirforum.com/t/emacs-elixir-setup-configuration-wiki/19196/172?u=nicogim @joaotavora it may be useful to add the information in the Readme for future Spacemacs users (It was rather difficult for me to get my head around that as I am still a newbie in Spacemacs and Emacs.)

joaotavora commented 4 years ago

Hi @NicoGim. Thanks for you interest in Eglot. It only supports Emacs. I don't have time for more, sorry.

It may support Spacemacs because Spacemacs is probably Emacs with fancy dinner garments (sometimes you step on the fancy dress, end up with your head in the wedding cake, your nether regions exposed).

I don't know how it works and there's also doom emacs, guy next door emacs, etc etc. Maybe you can post your spacemacs recipe right here and I'll link to it from the README, but that's as far as I'd go in supporting Spacemacs.

nicobao commented 4 years ago

I understand, time is not infinitely extensible.

Spacemacs is widely used today and has a strong community of newbies that attract more newbies to the Emacs world. I think it's a good thing for the community and we should try to promote that. Also, Spacemacs is 100% compatible with all Emacs packages. Same for Doom Emacs.

I can edit your README directly with appropriate information covering Spacemacs when necessary. Do you accept pull-requests? I know how to use eglot from Spacemacs, maybe someone else could one day add Doom Emacs related instructions.

joaotavora commented 4 years ago

I'd rather point to this issue than keep actual source (even if just README content) devoted to non-emacs.

Just post your info here, and then we'll make it discoverable.

And of course I do accept pull requests, just not for this :-)

nicobao commented 4 years ago

Instructions for Spacemacs

Package installation

eglot does not have a supported layer. package-install is not supported in Spacemacs (I mean yes but whenever you'll restart, the package will be deleted). In your .spacemacs file, add eglot in dotspacemacs-additional-packages.

Package configuration

Put all your eglot configuration in dotspacemacs/user-config:

(require 'eglot)
;; Your configuration goes AFTER the require statement. Example:
(add-hook 'elixir-mode-hook 'eglot-ensure)
(add-to-list 'eglot-server-programs '(elixir-mode "/path/to/language-server/language_server.sh"))

Note: Be careful with language spacemacs layers. For example the elixir layer is only compatible with lsp-mode and alchemist at the moment. So you need to install elixir-mode directly in dotspacemacs-additional-packages instead.

nicobao commented 4 years ago

Indeed, I still have some issues finally...:( "No jump handler was able to find this symbol. [8 times]". Maybe related to that issue, I don't know. I can't use vim interactions like gd. Also flymake does not automatically show errors on my screen like before. I need to explicitely call eglot-help-at-point...

joaotavora commented 4 years ago

@NicoGim, I'm sorry it doesn't work for you. These "layer" thing in Spacemacs seems to be, ultimately, just elisp code. I don't have time to go through that code to understand how it works, you have to ask the Spacemacs developers for that. I also don't know what the gd vim interaction is, because I use Emacs, not Vim. Again, Eglot supports Emacs.

Spacemacs is 100% compatible with all Emacs packages.

This doesn't seem to be true, does it?

package-install is not supported in Spacemacs

Yep, I think we should deduct at least a couple of % for that one, don't you think.

My advice, which you are totally free to take or to ignore, is: learn Emacs, not Spacemacs. Let go of you vimisms and your vscodeisms. It'll take a week to get used to, I won't kid you, but in the end you'll see it's much easier. Subscribe to help-gnu-emacs@gnu.org and report bugs to bug-gnu-emacs@gnu.org. You'll find helpful people there. And you'll find help here, of course.

Thank you.

PS: also read this https://github.com/joaotavora/eglot#reporting-bugs when you find the time.

nicobao commented 4 years ago

I didn't mean to ask you to debug my code, you've made it clear that you don't support Spacemacs. It was just for the record, for those Spacemacs users who pass by this issue and think it was solved, but actually, I am not sure it was.

gd is how to "go to definition" in evil-mode (vim-like keybindings in emacs): https://github.com/emacs-evil/evil-collection

Spacemacs is just Emacs, with lots of Elisp "configuration". Your eglot Elisp code should be compatible, it is just about how to configure it well in Spacemacs. package-install do work. But the package added this way is not permanent. You need to put it in dotspacemacs-additional-packages if you want to keep the package for good.

Thanks for your advice.

I did try plain vanilla Emacs. To me, it is more of a sketch of an editor than a real editor. I don't have weeks to take trying to have a somewhat modern tool to work with. No wonders why lots of people are on VSCode :/. Also, the original keybindings are in my opinion rather unusable. I'll never leave the vim keybindings. Managing to get evil-mode in Emacs to integrate correctly with all the other packages can be a mess at times.

The main advantage of Spacemacs is that a package expert (ex: the package maintainer - but not necessarily) can make the "layer" for you and you just use it, instead of having to get your head around it yourself. Now, if you want, you can still read layer code - but you don't have to.

That being said, I will, ultimately, come back to Emacs, when I will know which packages I really need. Spacemacs itself is much more beginner-friendly, it helps newcomers discover an advanced Emacs configuration and packages by using them. The Emacs mailing list is I am certain very helpful, but I prefer to learn by doing and using.

Learning how to make a Spacemacs Layer, or how to configure eglot for Spacemacs do indeed need Emacs knowledge, so ultimately I am already in the process of learning Emacs. I just happen to have an usable editor at the same time, and not having to wait X weeks to write code efficiently.

PS: thanks for the link I indeed already read it. I didn't expect to report a bug here, as I know you're not supporting Spacemacs anyway. Sorry for the unnecessary notification though, and also thanks for eglot!!!

joaotavora commented 4 years ago

My practical advice, if you insist on Spacemacs is to ask the Spacemacs people to make one of these "layers" for you that somehow includes Eglot. But if you then find a bug in Eglot, I am going to ask you to reproduce it in plain Emacs (or I won't be able to be of much assistance).

Now a digression:

You might not have found your way about it, but I think it is naive to call vanilla Emacs ia "sketch of an editor. I'll go out on a limb and say that, to make that assertion, you must have explored about 1% of it. And I say this because I know very well the feeling. Here's a story. Around 15 years ago, when I started programming professionally they made me use Emacs 21 because it was an official tool at that company. I hated it, had hated it throughout all of my studies, scoffed at the geeks who used it. So when I had to use it, I fought it for about 2 years. Learned elisp and endeavoured to make it work just like Eclipse, my favourite IDE (yeah Eclipse was cool at the time). I worked around all those yucky parts of Emacs: "the mark", "narrowing", "macros", "prefixes", blargh. Even "buffers" was a stupid concept to me, and why can't it just have completions like Visual C++??? A piece of crap, I thought, but hey at least it's programmable. So I changed every keybinding I can think of and had lots and lots of elisp code. I had it working decently in the end, had CUA bindings, a file drawer, show/hide blocks, tabs, fancy themes, etc etc.

Then one day, I saw a colleague trying out vanilla Emacs. For fun, he said. He was to give up shortly after that conversation and went back to my own "Eclipse extensions", which I had shared with others. But before he did so, he said these these very wise words:

I'm trying to understand why they designed it to behave like this out of the box.

I was very intrigued by this idea. Ultimately, I think he didn't understand. But to this day, I still try to understand, and I'm always pleasantly surprised. If nothing else, that's the advice I have for you. A basic argument of authority, I guess. Goes like this: some very clever people have been painstakingly crafting and using this editor for almost 40 years, following certain conventions, discussing and agreeing on every detail: surely they must have had very good reasons for making it like that and the products of their labour deserve some more investment.

nicobao commented 4 years ago

My practical advice, if you insist on Spacemacs is to ask the Spacemacs people to make one of these "layers" for you that somehow includes Eglot. But if you then find a bug in Eglot, I am going to ask you to reproduce it in plain Emacs (or I won't be able to be of much assistance).

If I have time, I might make the layer myself, I think it can be a great learning experience.

Thank you for sharing your story. It is very insightful and inspiring. I hope my previous post didn't sound condescending. I have the deepest respect for advanced Emacs users, considering how hard the tool is to master, and I do know it can be an incredibly powerful tool... It was sincerely the reasoning that pushed me to Spacemacs. It is still Emacs under the hood, I resisted the temptation to go back to Eclipse/IntelliJ/VSCode, and frankly I am glad I did so because I already enjoy the benefits.

some very clever people have been painstakingly crafting and using this editor for almost 40 years, following certain conventions, discussing and agreeing on every detail: surely they must have had very good reasons for making it like that and the products of their labour deserve some more investment.

Next time I go back to Vanilla Emacs (still in evil-mode ;)), and I most probably will, I'll keep that in mind! ;)