Code Monkey home page Code Monkey logo

ada_language_server's Introduction

Ada Language Server

Build binaries Download

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

Current features:

  • GNAT project files support.
  • 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.
  • Document/Workspace symbol search.
  • Code folding and formatting.

We also provide Visual Studio Code extension at the Marketplace and the latest build as .vsix file.

Table of Contents

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

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:

  • A GNAT compiler
  • Libadalang library (it should be built)
  • The VSS library
  • The a process spawn library

Project files of the libraries must be available via the GPR_PROJECT_PATH environment variable.

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

Usage

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
  • --help - Display supported command like options and exit.

You can turn some debugging and experimental features trought the traces file.

The server also gets configuration via workspace/didChangeConfiguration notification. See more details here. Each LSP client provides its-own way to set such settings.

Supported LSP Server Requests

General Requests

Request Supported
initialize
initialized
shutdown
exit
$/cancelRequest

Workspace Requests

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

Synchronization Requests

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

Text Document Requests

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

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 ALS via the .vscode/settings.json settings file. See the setting list here.

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. See the setting list here.

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 Neovim's built-in LSP client

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:

  • Use your favorite Neovim plugin manager to add the default set of LSP configuration files to Neovim.
  • (Optional) Run :LspInstall als to ask Neovim to install the Ada Language Server for you.
  • Enable the Ada Language Server by adding :lua require('nvim_lsp').als.setup{} to your init.vim.

If you decided to install the Ada Language Server yourself instead of using :LspInstall als, you will need to specify a command:

require('nvim_lsp').als.setup{ cmd = "/path/to/als/executable" }

Configuring the language server's settings can be achieved like this:

require('nvim_lsp').als.setup{
  settings = {
    ada = {
      projectFile = "project.gpr";
      scenarioVariables = { ... };
    }
  }
}

See the setting list here.

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.

Integration with QtCreator

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. QtCreator doesn't send any configuration request to the language server, so the only option to enable project support is to have a single .gpr file in the QtCreator project folder. For a projectless configuration, you could also place all Ada sources in the project root folder, this should work as well.

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

ada_language_server's People

Contributors

adrienboulanger avatar anthonyleonardogracio avatar dgautherot avatar entomy avatar enzbang avatar gcluzel avatar glacambre avatar godunko avatar joaopsazevedo avatar lambourg avatar leogermond avatar ogorodnik avatar pmderodat avatar ptroja avatar raja-s avatar raph-amiard avatar reznikmm avatar roldak avatar setton avatar simonjwright avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.