Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Language Support for Ada (deprecated)New to Visual Studio Code? Get it now.

Language Support for Ada (deprecated)

Maxim Reznik

|
1,170 installs
| (1) | Free
A Language Server providing Ada and SPARK support in Visual Studio Code
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Ada Language Server

Build Status Download

ATTENTION: The extension is moving to the new Marketplace account.

We are going to move ALS extension to our new corporative Marketplace account.

Please, uninstall the extension and then launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.

ext install AdaCore.ada

About

This repository contains a prototype implementation of the Microsoft Language Server Protocol for Ada/SPARK.

Current features:

  • GNAT project files
  • Code completion
  • Go to definition
  • Find corresponding references
  • Document symbol search
  • Code folding

We also provide Visual Studio Code extension as .vsix file.

Install

You can install binary image or build language server from sources.

To install binary image download an archive corresponding to your OS and unpack it somewhere. You will find ada_language_server inside unpacked folder. We provide binaries for

  • Linux x86_64 - take linux.tar.gz
  • Window 64 bit - take win32.zip
  • Mac OS X - take darwin.tar.gz

To build is from source install dependencies and run

make

It will build .obj/server/ada_language_server file.

Dependencies

To build the language server you need at least a version of the GNAT compiler, and the Libadalang library to be built and available via the GPR_PROJECT_PATH.

To run the language server you need gnatls (parts of GNAT installation) somewhere in the path.

Usage

The ada_language_server doesn't require/understand any command line options.

Supported LSP Server Requests

General Requests

Request Supported
initialize Yes
initialized Yes
shutdown Yes
exit Yes
$/cancelRequest Yes

Workspace Requests

Request Supported
workspace/didChangeWorkspaceFolders
workspace/didChangeConfiguration Yes
workspace/didChangeWorkspaceFolders
workspace/didChangeWatchedFiles
workspace/symbol
workspace/executeCommand Yes

Synchronization Requests

Request Supported
textDocument/didOpen Yes
textDocument/didChange Yes
textDocument/willSave
textDocument/willSaveWaitUntil
textDocument/didSave
textDocument/didClose Yes

Text Document Requests

Request Supported
textDocument/completion Yes
completionItem/resolve
textDocument/hover Yes
textDocument/signatureHelp
textDocument/definition Yes
textDocument/declaration Yes
textDocument/typeDefinition Yes
textDocument/implementation Yes
textDocument/references Yes
textDocument/documentHighlight
textDocument/documentSymbol Yes
textDocument/codeAction Yes
textDocument/codeLens
codeLens/resolve
textDocument/documentLink
documentLink/resolve
textDocument/documentColor
textDocument/colorPresentation
textDocument/formatting
textDocument/rangeFormatting
textDocument/onTypeFormatting
textDocument/rename Yes
textDocument/prepareRename
textDocument/foldingRange Yes

Protocol extensions

The Ada Language Server supports some features that are not in the official Language Server Protocol specification. See corresponding document.

How to use the VScode extension

For the moment, this repository includes a vscode extension that is used as the reference extension for this implementation.

You can try it by running:

code --extensionDevelopmentPath=<path_to_this_repo>/integration/vscode/ada <workspace directory>

You can configure the GNAT Project File and scenario variables via the .vscode/settings.json settings file, via the keys "ada.projectFile" and "ada.scenarioVariables".

You can set the character set to use when the server has to use when reading files from disk by specifying an "ada.defaultCharset" key. The default is iso-8859-1.

You can explicitly deactivate the emission of diagnostics, via the "ada.enableDiagnostics" key. By default, diagnostics are enabled.

The language server is able to edit Ada comments while executing textDocument/rename request. To enable this just set ada.renameInComments setting to true.

By default, the server indexes the source files after loading a project, to speed up subsequent requests. This behavior can be controlled via the "ada.enableIndexing" flag in this request.

Here is an example config file from the gnatcov project:

{
    "ada.projectFile": "gnatcov.gpr",
    "ada.scenarioVariables": {
        "BINUTILS_BUILD_DIR": "/null",
        "BINUTILS_SRC_DIR": "/null"
    },
   "ada.defaultCharset": "utf-8",
   "ada.enableDiagnostics": false,
   "ada.renameInComments": false
}

Integration with LanguageClient-Neovim

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.

To configure the Ada Language Server for a specific workspace/project, you can use the .vim/settings.json file. It is mandatory as soon as you want to use a specific .gpr project file.

This is the way to specify a project file, eg. you cannot open a project file another way.

Here is an example of a settings file:

{
    "ada.projectFile": "project.gpr",
    "ada.scenarioVariables": {
        "GLFW_Version": "3",
        "GLFW_Lib": "-lglfw",
        "Windowing_System": "x11"
    }
}

The location where the .vim folder is located will determine the relative path of the project file (so no need to prefix with ..). When vim is opened in the folder containing this .vim directory, it will use those settings for the language server even for files which might have nothing to do with that specific project, so this needs to be taken into account. Ultimately what this means is that the configuration is determined by where you open vim.

Integration with emacs lsp-mode

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.

Authors & Contributors

  • Maintained by AdaCore.
  • Original author @MaximReznik.
  • Support for the Visual Studio Code classifier and snippets contributed by @Entomy.

Contribute

Feel free to dive in! Read the developer's guide.

Don't hesitate to open an issue or submit PRs.

License

GPL-3

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2019 Microsoft