Setting up the Ada Language Server in VIM

I am new to Ada programming and just want to setup my editor with basic language support (go to definition, rename, etc). This has been quite frictionless with Javascript, Typescript, Python and Bash, for basic cases, but I am struggling getting this working in Ada.

This is what I want to achieve:
check out a repo like ALS and open a given file (like this and be able to

  • “Go to Definition”
  • “Rename”
    etc

What kind of configuration do I need to add for this to work? It is not immediately obvious to me as a complete beginner to ADA what to add to the project specific config, if anything.

I did read about the settings and so I have added this in the directory I found the closest gpr file:

testsuite/ada_lsp/declaration.overridings_on_usage on HEAD (76c0255) [?]
$ cat .als.json
{
  "projectFile": "default.gpr"
}

That did not seem to achieve anything. All operations still fail.

Typical output from the log files

==> /home/oscko/.als/ada_ls_log.2025-03-06T104750.56864.log <==
[ALS.MAIN] Exception while handling LSP.SERVER_REQUESTS.RENAME.REQUEST
[ALS.MAIN] raised CONSTRAINT_ERROR : gpr2-project-tree.ads:501 access check failed
_ALS.MAIN_ [/home/oscko/bin/ada_language_server]
_ALS.MAIN_ 0x1d17706
_ALS.MAIN_ 0x2046e13
_ALS.MAIN_ 0x1db07a1
_ALS.MAIN_ 0x1ddc17d
_ALS.MAIN_ 0x1dd611b
_ALS.MAIN_ 0x1177af4
_ALS.MAIN_ 0x118157f
_ALS.MAIN_ 0x1d3e03b
_ALS.MAIN_ 0x3e93c85
_ALS.MAIN_ [/lib/x86_64-linux-gnu/libc.so.6]
_ALS.MAIN_ 0x7f40b7eb9aa2
_ALS.MAIN_ 0x7f40b7f46c3a
_ALS.MAIN_ 0xfffffffffffffffe
[ALS.MAIN] [/home/oscko/bin/ada_language_server]
_ALS.MAIN_ 0x1d17706
_ALS.MAIN_ 0x2046e13
_ALS.MAIN_ 0x1db07a1
_ALS.MAIN_ 0x1ddc17d
_ALS.MAIN_ 0x1dd611b
_ALS.MAIN_ 0x1177af4
_ALS.MAIN_ 0x118157f
_ALS.MAIN_ 0x1d3e03b
_ALS.MAIN_ 0x3e93c85
_ALS.MAIN_ [/lib/x86_64-linux-gnu/libc.so.6]
_ALS.MAIN_ 0x7f40b7eb9aa2
_ALS.MAIN_ 0x7f40b7f46c3a
_ALS.MAIN_ 0xfffffffffffffffe

==> /home/oscko/.als/ada_ls_log.2025-03-06T104750.56691.log <==
[ALS.PROJECT] GPR2 messages after load:
   [ALS.PROJECT] embedded_kb/kb: warning: can't find a toolchain for the following configuration: language 'Ada', target 'x86_64-linux', default runtime
[ALS.PROJECT] Updating project sources
[ALS.PROJECT] GPR2 messages after updating sources:
   [ALS.PROJECT] embedded_kb/kb: warning: can't find a toolchain for the following configuration: language 'Ada', target 'x86_64-linux', default runtime
[ALS.PROJECT] Prepend Context Id: file:///home/oscko/dev/ada_language_server/testsuite/ada_lsp/declaration.overridings_on_usage/default.gpr
[ALS.PROJECT] Project status after loading:
_ALS.PROJECT_ (PROJECT_TYPE => CONFIGURED_PROJECT,
_ALS.PROJECT_  STATUS => VALID_PROJECT_WITH_WARNING,
_ALS.PROJECT_  PROJECT_FILE => {GNATCOLL.VFS.VIRTUAL_FILE object},
_ALS.PROJECT_  MISSING_ADA_RUNTIME => TRUE,
_ALS.PROJECT_  GPR2_MESSAGES => {GPR2.LOG.OBJECT object},
_ALS.PROJECT_  ALIRE_MESSAGES => {VSS.STRING_VECTORS.VIRTUAL_STRING_VECTOR object})
[ALS.MAIN] Creating fallback context
[ALS.MAIN] In Message_Handler Text_Document_Did_Open URI:
[ALS.MAIN] file:///home/oscko/dev/ada_language_server/testsuite/ada_lsp/declaration.overridings_on_usage/class_definition.subclass.adb
[ALS.MAIN] Out Message_Handler Text_Document_Did_Open

  [ALS.PROJECT] embedded_kb/kb: warning: can't find a toolchain for the >following configuration: language 'Ada', target 'x86_64-linux', default runtime

I think you might have this problem:

Thanks! I will check this out. It definitely seems like you are onto something, as I did not go that far down the error log list, but now I see this as well:

_ALS.PROJECT_  MISSING_ADA_RUNTIME => TRUE,

Will report back.

You were absolutely onto something! On my private mac, I got this working, rename and go to definition, but I was missing something on Ubuntu.

I only had alire and gnat studio installed, but did not have the standalone environment, so had to install that:

apt install gnat
apt install gprbuild

I now see _ALS.PROJECT_ MISSING_ADA_RUNTIME => FALSE, in the logs, but unlike on my mac, GPR PATH is unset. Not quite sure what to do there, but will check if installing the FSF builds work.

I am able to get feedback from the compiler inline, at least:

The logs still show this as failing when I try to rename or go to definition:

[ALS.PROJECT] Prepend Context Id: file:///home/oscko/dev/ada_language_server/gnat/lsp_server.gpr
[ALS.PROJECT] Project status after loading:
_ALS.PROJECT_ (PROJECT_TYPE => CONFIGURED_PROJECT,
_ALS.PROJECT_  STATUS => VALID_PROJECT_WITH_WARNING,
_ALS.PROJECT_  PROJECT_FILE => {GNATCOLL.VFS.VIRTUAL_FILE^@ object},
_ALS.PROJECT_  MISSING_ADA_RUNTIME => FALSE,
_ALS.PROJECT_  GPR2_MESSAGES => {GPR2.LOG.OBJECT^@ object},
_ALS.PROJECT_  ALIRE_MESSAGES => {VSS.STRING_VECTORS.VIRTUAL_STRING_VECTOR^@ object})
[ALS.MAIN] Creating fallback context
[ALS.MAIN] In Message_Handler Text_Document_Did_Open URI:
[ALS.MAIN] file:///home/oscko/dev/ada_language_server/testsuite/ada_lsp/called_by/p.adb
[ALS.MAIN] Out Message_Handler Text_Document_Did_Open
[ALS.MAIN] Exception while handling LSP.SERVER_REQUESTS.RENAME.REQUEST
[ALS.MAIN] raised CONSTRAINT_ERROR : gpr2-project-tree.ads:501 access check failed
_ALS.MAIN_ [/home/oscko/bin/ada_language_server]
_ALS.MAIN_ 0x1d17706
_ALS.MAIN_ 0x2046e13
_ALS.MAIN_ 0x1db07a1
_ALS.MAIN_ 0x1ddc17d
_ALS.MAIN_ 0x1dd611b
_ALS.MAIN_ 0x1177af4
_ALS.MAIN_ 0x118157f
_ALS.MAIN_ 0x1d3e03b
_ALS.MAIN_ 0x3e93c85
_ALS.MAIN_ [/lib/x86_64-linux-gnu/libc.so.6]
_ALS.MAIN_ 0x7fa994f0baa2
_ALS.MAIN_ 0x7fa994f98c3a

Nope, adding the FSF builds of GNAT 14 (ensuring gcc-ada and gcc are in sync) and adding it to the PATH did nothing. GPR PATH still unset.

[ALS.MAIN] ALS version: 26.0.202502240 ()
[ALS.MAIN] Initializing server ...
[ALS.MAIN] GPR PATH:
[ALS.MAIN] PATH: /home/oscko/.asdf/plugins/nodejs/shims:/home/oscko/.asdf/installs/nodejs/22.14.0/bin:/opt/gnat-x86_6
4-linux-14.2.0-1/bin:/home/oscko/gnatstudio/bin:...

Same errors, as well.

edit: I also downloaded the latest FSF GprBuild and added that to the PATH as well. No difference. grep GPR PATH ~/.als/ada_ls_* still only shows empty hits:

[ALS.MAIN] GPR PATH:
[ALS.MAIN] GPR PATH:
[ALS.MAIN] GPR PATH:
[ALS.MAIN] GPR PATH:

Forget about GPR PATH, that’s probably the value of the environment variables GPR_PROJECT_PATH or ADA_PROJECT_PATH. Mine is also empty, and that’s not a problem.

Have you followed the tutorial?

I was able to get the Ada Langauge Server working with nvim by installing the ada-language-server package using the Mason nvim package manager.

After I installed the language server I added this to my init.lua:

require("lspconfig").ads_ls.setup {
  settings = {
      ada = {
         projectfile = ""
        }
    }
}

@mgrojo Thanks for the tutorial link. Since I was not using VS Code, I did not follow the tutorial, although that does not seem to matter all that much. I looked through the steps, and I could see nothing relevant there that I did not already do. Basically, all it says is to make sure the GNAT tooling is available on the PATH. Which it is:

❯ which gprbuild ; which gcc
/opt/gprbuild-x86_64-linux-24.0.0-2/bin/gprbuild
/opt/gnat-x86_64-linux-14.2.0-1/bin/gcc

I did make one interesting find, though: the Ada Language Server in Ubuntu is working, but only in parts of the source tree?!

For instance, trying a rename of Do_Something in testsuite/ada_lsp/completion.invisible.insert_with_clause.renamed_units/bar.ads will fail with the above error about raised CONSTRAINT_ERROR : gpr2-project-tree.ads:501 access check failed, but renaming in source/ada/lsp-search.adb works fine.

Even stranger is that both of these files work fine (-ish - loads of other errors) with ALS on my macOS , using the same setup?! I have even compared pwd output to see if this mattered, but even when identical I still have issues with the files in testsuite/**.

@nerd_type That’s pretty much my config already :slight_smile:

macOS, ALS, Emacs, ada-ts-mode. I find that ALS can get confused if I ask it to handle code that isn’t accessed via the GPR; for example, a little sketch folder under tmp/ rather than src/.