af / ocaml-language-server

A language server for OCaml and related languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ocaml-language-server

The engine that powers OCaml and Reason's editors support!

How Does This Work?

This is an implementation of the language server protocol. It's a simple idea: every mainstream editor implements a language client, which receives your editor actions (autocompletion, jump-to-definition, show type, etc.) and calls a language server, which returns the asked information.

The insight is to standardize the way every editor queries the language server. This way, instead of reimplementing e.g. one Reason plugin for every single editor out there, we implement everything once inside our language server, and all editors that support language client receives the feature. Diagram here.

Features

Every editor using this language-server should in theory have all the following features:

  • OCaml support
  • Reason support
  • compiler diagnostics
  • incremental document synchronization
  • code action provider
  • code lens provider
  • completion provider
  • definition provider
  • document formatting provider (Reason)
  • document highlight provider
  • document range formatting provider (Reason)
  • document symbol provider
  • hover provider
  • references provider
  • workspace symbol provider
  • BuckleScript build system integration (currently only activated for vscode)

Installation

The Language Server (This Project)

npm install -g ocaml-language-server

The server relies on some external dependencies you have to install yourself. If you're a pure OCaml user:

  • OCaml 4.02.3 or greater
  • merlin 2.5.0 or greater

If you're a Reason/BuckleScript user:

Install Reason + OCaml + Merlin through Reason's recommended installation or the alternative OPAM installation.

The Language Client

Pick your favorite editor and install the plugin! They should all work with ocaml-language-server. Some of them are called "myeditor-reason", but they support both Reason and OCaml.

Launching the Server

Your editor's language-client should have a configuration to start the server.

The server can be launched in the following ways:

ocaml-language-server --node-ipc
ocaml-language-server --socket={number}
ocaml-language-server --stdio

For node-based clients like vscode-reasonml --node-ipc is the most efficient approach. Clients written in other languages should use --stdio or --socket.

Contributing

Clone the repo and do:

yarn install                 # install dependencies
node ./bin/server --stdio    # start the server

About

A language server for OCaml and related languages

License:Apache License 2.0


Languages

Language:TypeScript 97.5%Language:JavaScript 2.5%