This repository contains an implementation of the Microsoft Language Server Protocol for Ada/SPARK and GPR project files.
Current features (general):
- GNAT project files support.
- Basic Alire support.
For Ada/SPARK, we provide the following:
- Code completion for names, keywords, aggregates, etc.
- Code navigation, such as Go to Definition/Declaration, Find All References, Call Hierarchies, etc.
- Code refactoring like insert named associations, auto-add
with
-clauses, etc. - Document/Workspace symbol search.
- Code folding and formatting.
The Ada Language Server now also supports the GPR language, via the
--language-gpr
option, providing support for the most used LSP features
such as navigation, outline and tooltips for GPR files. When this switch is
present, the server will only support GPR files. To support both GPR and
Ada/SPARK, you'll need to launch two instances of the server.
You can refer to the Supported LSP Server Requests
section for more information.
We also provide Visual Studio Code extension at the VS Marketplace and at the Open VSX Registry.
- Ada Language Server
The official releases contains ready-built packages for various platforms and architectures and should be your first choice when trying out the language server.
You can also build the language server from source. See build.md for details.
The ada_language_server
doesn't require any command line options,
but it understands these options:
--tracefile=<FILE>
- Full path to a file containing traces configuration--config=<FILE>
- Full path to a JSON file containing the server's configuration--help
- Display supported command like options and exit.
You can turn some debugging and experimental features through the traces file.
The server also gets configuration via workspace/didChangeConfiguration
notification and initializationOptions
of initialize
request.
See more details here. Each LSP
client provides its-own way to set such settings. You can use the --config
option if you want to provide the configuration directly via a JSON file
instead of specifying it via the requests listed just above.
The ada_language_server
relies on Libadalang to compute the cross references.
Most of this computation is done while indexing which will create an internal cache.
The expected memory size of this cache is around 300Mb per 100k lines of Ada code.
Furthermore, 450Mb are necessary for the runtime.
Please note that some Ada structures like generics and tagged types might
increase the memory usage. This is also the case when using aggregate projects.
These measures were taken using both Resident Set Size and Valgrind massif on Ubuntu 22.04LTS.
See WiKi page for the list of supported requests.
The Ada Language Server supports some features that are not in the official Language Server Protocol specification. See corresponding document.
A VS Code extension based on this Ada Language Server is available on the Visual Studio Marketplace. It provides a full set of features including syntax highlighting, navigation, building and debugging.
See the Ada & SPARK VS Code Extension User's Guide for more information.
If you want to use the Ada Language Server with Vim/Neovim, you can use the
Coc.NVim. You'll have to
install the Ada Language Server manually somewhere on your
computer. Follow installation instructions on Coc.NVim website and then
configure the Ada Language Server with :CocConfig
:
{
"languageserver": {
"ada": {
"settings": {
"ada": {
"projectFile": "gnat/vss_text.gpr"
}
},
"command": "<path>/ada_language_server",
"filetypes": [
"ads",
"adb",
"ada"
]
}
}
}
Alternatively to the above settings section, workspace-specific ALS Settings such as the projectFile
can be provided in a .als.json
file at the root of the workspace.
If you want to integrate the Ada Language Server into vim, you can use the vim-lsp.
You'll have to install the Ada Language Server manually somewhere on your
computer, and then you can add the following line to your .vimrc
file:
if executable('ada_language_server')
au User lsp_setup call lsp#register_server({
\ 'name': 'ada_language_server',
\ 'cmd': ['ada_language_server'],
\ 'allowlist': ['ada'],
\ })
endif
Workspace-specific ALS Settings such as the projectFile
can be provided in a .als.json
file at the root of the workspace.
If you want to integrate the Ada Language Server into Neovim, you can use the LanguageClient-neovim.
You'll have to install the Ada Language Server manually somewhere on your
computer, and then you can add the following line to your init.vim
file:
" replace the path below with the proper path to the ada_language_server executable
let g:LanguageClient_serverCommands = {
\ 'ada': ['path/to/ada_language_server'],
\ }
" if you already have LanguageClient_serverCommands, just add a line for ada.
Workspace-specific ALS Settings such as the projectFile
can be provided in a .als.json
file at the root of the workspace.
Neovim 0.5.0 and later have a built-in LSP client which can be used with the Ada Language Server. In order to use it with minimal effort, follow these steps:
- Install the ada language server and make sure it's in your $PATH.
- Use your favorite Neovim plugin manager to add the default set of LSP configuration files to Neovim.
- Add
require('lspconfig').ada_ls.setup{}
to your init.lua in order to enable the Ada Language Server.
If you would rather not have the ada language server in your path, you can give the lsp client an absolute path to the ALS executable:
require('lspconfig').ada_ls.setup{ cmd = "/path/to/als/executable" }
Configuring the language server's settings globally can be achieved like this:
require('lspconfig').ada_ls.setup{
settings = {
ada = {
projectFile = "project.gpr";
scenarioVariables = { ... };
}
}
}
Workspace-specific ALS Settings such as the projectFile
can be provided in a .als.json
file at the root of the workspace.
Alternatively, workspace-specific settings can also be configured as per the lspconfig wiki
Workspace-specific ALS Settings such as the projectFile
can be provided in a .als.json
file at the root of the workspace.
Alternatively the configuration for each project can be provided using a .dir-locals.el
file defined at the root of each project.
The scenario variables should be declared in your .emacs
or any loaded
Emacs configuration file.
(defgroup project-build nil
"LSP options for Project"
:group 'ada-mode)
(defcustom project-build-type "Debug"
"Controls the type of build of a project.
Default is Debug, other choices are Release and Coverage."
:type '(choice
(const "Debug")
(const "Coverage")
(const "Release"))
:group 'project-build)
Your .dir-locals.el
in the project root should be similar to:
((ada-mode .
((eval . (lsp-register-custom-settings
'(("ada.scenarioVariables.BINUTILS_SRC_DIR" project-binutils-dir)
("ada.scenarioVariables.BUILD_TYPE" project-build-type "Release"))))
(lsp-ada-project-file . "/home/username/project/project.gpr"))
))
The lsp-mode provides built-in support
for the ada_language_server
and defines default customizable configuration
values in the lsp-ada
group that can be edited similarly to
lsp-ada-project-file
in the example above.
Starting with version 4.9
, QtCreator supports a LSP plugin. Follow
the official documentation
to configure the Ada Language Server in this plugin. Make sure to set Startup behavior
to Start Server per Project
, otherwise QtCreator won't provide the project root to
the Ada Language Server.
Workspace-specific ALS Settings such as the projectFile
can be provided in a .als.json
file at the root of the workspace.
The LSP4IJ IntelliJ plugin
provides a template for Ada since version 0.14.0
, allowing users tu use the Ada Language Server from IntelliJ.
Follow the dedicated LSP4J documentation for more information.
- Maintained by AdaCore.
- Original author @MaximReznik.
- Support for the Visual Studio Code classifier and snippets contributed by @Entomy.
Feel free to dive in! Read the developer's guide.
Don't hesitate to open an issue or submit PRs.