Emacs mode, alire, and assorted new-user difficulties

New user, so I may be missing some obvious solutions. I am on ubuntu 24.04, and I prefer using emacs. I have installed alire 2.1.0 from alire.ada.dev.

I would like at least a basic ada mode for emacs. At least syntax highlighting and formatting defaults, but a way to search for names, definitions, etc. would of course be very nice also.

I got the toolchain installed without a lot of trouble, but it initially only showed me the 13.x versions, and 15.x is available. I ran some command to update the index and now I’m on gnat_native 15.2.1 and gprbuild 25.0.1, which I think means I have full 2022 support, right? I was also able to get gnatprove, which I’m happy about, because this is the first time I’ve been able to try that.

(I still have some lingering confusion about the GCC based toolchain and the adacore community edition. If I install through Alire, then I get the GCC one, right? The community edition is standalone?)

In emacs, I tried M-x package-install RET ada-mode RET. That installs ada-mode, but then there’s a warning:

Ada parser exec 'ada_mode_wisi_lr1_parse' not found; install it, or set ada-*-backend to eglot.

Then I tried alr install emacs_ada_mode. That installs some dependencies:

   Dependencies (solution):
      emacs_ada_mode=8.1.0
      emacs_wisi=4.3.2
      gnat=15.2.1 (gnat_native)
      gnatcoll=22.0.0
      libgpr=22.0.0
      re2c=3.1.0
      stephes_ada_library=3.7.3
      wisitoken=4.2.1
      xmlada=22.0.0

and emacs_wisi fails with:

 Building emacs_wisi=4.3.2/wisi_alire.gpr...
gnatcoll.gpr:254:07: warning: value "windows" is not used as label
Compile
   [Ada]          wisi.adb
wisi.adb:1031:19: error: ambiguous left-hand side in assignment

   compilation of wisi.adb failed

gprbuild: *** compilation phase failed

I thought I’d try installing the dependencies individually to see which ones would succeed. gnat, gnatcoll, xmlada, libgpr seem fine. re2c said something about a system install, and I said “no”, and installed it from ubuntu, which I think is OK.

stephes_ada_library fails with:

sal-time_conversions.ads:263:51: warning: instance uses predefined, not primitive, operator "mod" at line 97
sal-time_conversions-config.ads:35:74: warning: instance uses predefined, not primitive, operator "mod" at sal-time_conversions.ads:97
sal-time_conversions-config.ads:36:83: warning: instance uses predefined, not primitive, operator "mod" at sal-time_conversions.ads:97
sal-time_conversions-config.ads:38:77: warning: instance uses predefined, not primitive, operator "mod" at sal-time_conversions.ads:97

   compilation of sal-time_conversions.adb failed
   compilation of sal-time_conversions-config.ads failed

gprbuild: *** compilation phase failed

I only see warnings there, so maybe I’m using the wrong flags somehow?

and wisitoken fails with:

wisitoken-lexer-regexp.ads:61:15: error: instantiation error at wisitoken-lexer.ads:142
wisitoken-lexer-regexp.ads:61:15: error: expected an access type with designated type "Instance" defined at wisitoken-lexer.ads:116
wisitoken-lexer-regexp.ads:61:15: error: found an access type with designated type "Instance" defined at line 188
wisitoken-lexer-regexp.ads:61:15: error:   ==> in call to "Has_Source" at wisitoken-lexer.ads:128

   compilation of wisitoken-lexer-regexp.adb failed

gprbuild: *** compilation phase failed

(Aside: This process clones the same repo 3+ times. Unfortuantely, when I first tried, that repo took about an hour to clone for some reason, which was very frustrating and wasteful. It only needs a single tag for each package, I assume. It would also be nice if I could just download the repo myself and point it to that, because each time the compilation failed it started over and re-cloned the repo. Now the repo clones in seconds so it’s not a big deal, but still seems like it could be better.)

So, dead end. Not sure why the packages would fail to compile… wouldn’t they fail for everyone? Or do I have too new of a toolchain and the package maintainers haven’t updated? Or maybe the packages are just unmaintained or something? Or something about my configuration, like compiler flags, or my index is out of date (I did alr index --update-all)? Or maybe it’s getting confused because of some missing ubuntu packages, or packages that are installed but not the right version or getting in the way somehow?

Then I tried installing the language server with alr install ada_language_server, which worked after a long compile. But when I configured emacs to use it, it was incredibly slow to load a file, like 3+ seconds. I suppose there are ways to autoload it or something, but got a bit fatigued on the whole process, and couldn’t find docs for how to actually use the language server from emacs (some tutorial on useful commands, etc.), so I thought I’d post here.

Also, along the way, I tried a bunch of stuff in alire and probably installed stuff I don’t need. How do I list what I installed globally (not part of an actual alire crate) to see if I should remove some stuff?

Any advice appreciated. Am I on the right track?

If you’re using Linux x86_64, you can get the binaries already linked from here: GitHub - mgrojo/emacs-ada-mode-binaries: AppImages of the Emacs ada-mode executables, or you can take a look at how they are linked there in the GitHub action: emacs-ada-mode-binaries/.github/workflows/main.yml at a1bdd586ab3417d286bdcd07d3c2fc4f94d985d5 · mgrojo/emacs-ada-mode-binaries · GitHub

There are also alternatives to ada-mode, as GitHub - brownts/ada-ts-mode: Ada major mode using tree-sitter for Emacs and a distribution of ada-ts-mode for Doom Emacs: GitHub - tomekw/doom-ada: Doom Emacs Ada language module with syntax highlighting, LSP and Alire support

Finally, if you don’t mind reading a lot, you have useful information in this other topic: Getting Emacs ada-mode working

I followed up some more on the language server approach, and I think it’s just a bad ada_language_server binary.

$ ada_language_server --version
ALS version: latest (unknown)
$ ada_language_server 

Unhandled Exception raised
raised TASKING_ERROR : s-tasren.adb:377
Load address: 0x5ed2bbd4b000
[$HOME/.alire/bin/ada_language_server]
0x5ed2c13c88fd System.Tasking.Rendezvous.Call_Simple at s-tasren.adb:377
0x5ed2beb171f9 Lsp.Servers.Finalize at lsp-servers.adb:143
0x5ed2bc63da3e Lsp.Ada_Driver at lsp-ada_driver.adb:663
0x5ed2bc64ca01 Main at b__lsp-ada_driver.adb:10965
[/lib/x86_64-linux-gnu/libc.so.6]
0x7841a3c2a1c8
0x7841a3c2a289
[$HOME/.alire/bin/ada_language_server]
0x5ed2bc639503 _start at ???
0xfffffffffffffffe

It’s a bit strange that it doesn’t report an actual version. It looks like the following versions are available: 25.0.0, 24.0.0, 23.0.0, and 22.0.0.

I did alr --force install ada_language_server=25.0.0, and it succeeded in compiling/linking, but I think that was the same version as before, which failed when I tried to run it (same as above).

24.0.0 and earlier seemed to download an entire earlier version of the toolchain, but then failed to compile & link.

So I think if I was able to install a working ada_language_server, then emacs might work like I want it to.

Sure enough, I downloaded a prebuilt binary for ada_language_server, placed it in my PATH, and everything works now.

Solution:

  1. install ada-mode and vertico via elpa.

  2. get working ada_language_server from Releases · AdaCore/ada_language_server · GitHub (I got 24.0.6) and put in your PATH

  3. put the following in .emacs:

(package-initialize)

(require 'eglot)
(add-to-list 'eglot-server-programs '('ada-mode "ada_language_server"))
(add-hook 'ada-mode-hook 'eglot-ensure)
(setq ada-face-backend 'none) ;; suppress a warning

;; More convenient minibuffer interaction                                                                                                  
(vertico-mode 1)

Thank you!

Also, it seems that sometimes navigation (e.g. M-f) using ada-mode and the language server freezes up; maybe while building an index or something. If you try to C-g, then it ends up crashing emacs. Not ideal, but as long as it’s not too often it should be fine, just wait a moment for it to un-freeze.

Sounds like you got it to work, but for the benefit of future searchers I found Forward in code: Ada TS Mode very useful myself.

2 Likes

I would not try to use the legacy ada-mode. Instead, I’d use anything based on tree-sitter.

Recently-ish, Doom Emacs added support for Ada:

1 Like

Great, I’ll check that out. Thank you.