Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Language Support

Issam Maghni edited this page May 29, 2019 · 41 revisions

Language Support

Oni utilizes the Language Server Protocol (LSP) to provide common IDE functionality for any arbitrary programming language. This enables features like code completion, go-to definition, and method signature help.

Included Language Servers

Oni comes with a few language servers bundled:

Configuration

Language options are configurable via the configuration settings in your config.js.

In general, language options are specified in the form language.<language-identifier>.<option>, where language-identifier corresponds to the file type.

Auto-Closing Pairs

Auto-closing pairs is a feature that automatically 'closes' certain character pairs.

This has two general settings:

  • autoClosingPairs.enabled - (boolean) - specifies whether auto-closing pairs are active. Default is true.
  • autoClosingPairs.default - (AutoClosingPair[]) - specifies the default set of auto-closing pairs, if not overridden by a language setting.

With the default set of auto-closing pairs defined as:

    "autoClosingPairs.default": [
        { "open": "{", "close": "}" },
        { "open": "[", "close": "]" },
        { "open": "(", "close": ")" },
    ],

Auto-closing pairs can be specified per language via the language.<language-identifier>.autoClosingPairs setting, in the same format as above.

Language Servers

Language servers are configurable via the language.<language-identifier>.languageServer.<setting>, and the following settings are available:

  • command - (String) (required) - The command to start the language server. This could be a javascript file or an executable. REQUIRED
  • arguments (String[]) (optional) - An array of arguments to pass to the language server
  • rootFiles (String[]) (optional) - A set of files that are treated as the root. When this is specified, Oni will search upward for this, and start the language server in the root folder
  • configuration (any) (optional) - Additional javascript objects to send to the language server via the workspace/onConfigurationChanged event

An example configuration might be:

"language.reason.languageServer.command": "ocaml-language-server",
"language.reason.languageServer.arguments": ["--stdio"],
"language.reason.languageServer.rootFiles": [".merlin", "bsconfig.json"],
"language.reason.languageServer.configuration": {}

The only required option is the language server command, however, some language servers may require you to use the full set of parameters.

NOTE: Language servers implement different transports - stdio, ipc, socket. Today, Oni only supports stdio

To find a language server, check out langserver.org

Other Settings

Aside from language servers, there are other settings available for customizing languages in Oni:

  • language.<language-identifier>.completionTriggerCharacters (string[]) - an array of characters that can trigger completion.

  • NOT IMPLEMENTED YET - language.<language-identifier>.autoPairs

Language Notes

Bash

Bash language support is provided via the bash-language-server.

Example Bash configuration:

"language.bash.languageServer.command": "bash-language-server",
"language.bash.languageServer.arguments": ["start"],

C/C++

C and C++ language support is set up by default to use clangd, and expects clangd available in your path.

  • Get a working clangd (both code and executables are available here)
  • Make sure that clangd is available globally (for instance, by adding it to an environment variable)

For information on setting it up, please refer to the clangd documentation.

If you want code completion popups to appear when typing -> and ::, you can add the following to your Oni config

"language.cpp.completionTriggerCharacters": [".", ">", ":"],

Note that Oni only supports single trigger characters at the time of writing, so you may get spurious popups.

cquery

cquery is an alternative to clangd that supports more of the language server specification (at time of writing). You must pass a cache directory for it to use in the initialisation arguments.

"language.cpp.languageServer.command": "/path/to/cquery",
"language.cpp.languageServer.arguments": [
    `--init={"cacheDirectory": "/tmp/cquery.cache"}`
],
"language.cpp.languageServer.rootFiles": ["compile_commands.json"]

ccls

ccls is a fork of cquery that promises to be more lightweight.

"language.cpp.languageServer.command": "/path/to/ccls",
"language.cpp.languageServer.rootFiles": ["compile_commands.json"]

C#

C# language support is not configured by default, and requires the oni-language-csharp plugin, which provides language capabilities for both .NET and Mono.

Follow the installation instructions to get started.

Dart

Dart language support is provided via the dart_language_server.

Example Dart configuration:

"language.dart.languageServer.command": "dart_language_server",

Docker

Docker language support is provided via the dockerfile-language-server-nodejs.

Example Docker configuration:

"language.dockerfile.languageServer.command": "docker-langserver",
"language.dockerfile.languageServer.arguments": ["--stdio"],

Go

Go language support depends on the go-langserver, which provides language support for Go. Follow their installation instructions as this language server is not bundled out-of-the-box with Oni.

go-langserver must be available in your PATH. You can override this by setting the language.go.languageServer.command configuration value.

Example Golang configuration:

// language server configuration
"language.go.languageServer.rootFiles": [".git"], // In a git repository
"language.go.languageServer.command": "go-langserver",
"language.go.languageServer.arguments": ["--gocodecompletion", "--freeosmemory", "false"],

Haskell

Haskell language support is provided via the haskell-ide-engine.

Example Haskell configuration:

"language.haskell.languageServer.command": "hi",
"language.haskell.languageServer.arguments": ["--lsp"],
"language.haskell.languageServer.rootFiles": [".git"],

Java

Java language support is provided via the eclipse.jdt.ls. The lastest version can be found on this link. Decompress the file and put the folder on the PATH (for example C:\dev\jdt-language-server-latest).

Configuration for Oni on Windows using Java 8:

"language.java.languageServer.command": "C:\\dev\\java\\jdk1.8.0_161_i586\\bin\\java",
"language.java.languageServer.arguments": [
    "-Declipse.application=org.eclipse.jdt.ls.core.id1",
    "-Dosgi.bundles.defaultStartLevel=4",
    "-Declipse.product=org.eclipse.jdt.ls.core.product",
    "-Dlog.level=NONE",
    "-noverify",
    "-Xmx1G",
    "-jar",
    "C:\\dev\\jdt-language-server-latest\\plugins\\org.eclipse.equinox.launcher_1.5.0.v20180207-1446.jar",
    "-configuration",
    "C:\\dev\\jdt-language-server-latest\\config_win",
    "-data"
],
"language.java.languageServer.rootFiles": ["pom.xml"],

JavaScript and TypeScript

JavaScript and TypeScript support is enabled out-of-the-box using the TypeScript Standalone Server. No setup and configuration is necessary, however, you will get better results if you use a tsconfig.json or a jsconfig.json to structure your project.

JavaScript and Flow

If you would like to add flow support (a static type checker for javascript), you will need to add the flow-language-server, This can be done by running yarn global add flow-language-server or npm install -g flow-language-server, then adding the following lines to your oni config.js

  'language.javascript.languageServer.command': 'flow-language-server',
  'language.javascript.languageServer.arguments': ['--stdio'],

JavaScript and Vue

To add language support for vue, the javascript framework and it's filetype, you will need to complete the following steps.

  1. Run npm install -g vue-language-server
  2. Add the following to your config.js
 'language.vue.languageServer.command':'vls'

Lua

Lua language support is provided via the lua-lsp.

Example Lua configuration:

"language.lua.languageServer.command": "lua-ls",
"language.lua.languageServer.rootFiles": [".git"],

Python

Python language support depends on pyls, which provides language support for Python. Follow their installation instructions as this language server is not bundled out-of-the-box with Oni.

pyls must be available in your PATH. You can override this by setting the language.python.languageServer.command configuration value.

Reason and OCaml

Oni comes with ocaml-language-server out-of-the-box, however, make sure you have the other pre-requisites installed and that merlin is configured properly.

Ruby

Ruby language support is provided via solargraph.

Example Ruby configuration:

"language.ruby.languageServer.command": "solargraph",
"language.ruby.languageServer.arguments": ["stdio"],

Rust

Rust language support is provided via the rls an example configuration is

// Language Support - Rust
"language.rust.languageServer.command": "rustup",
"language.rust.languageServer.arguments": ["run", "stable", "rls"],
"language.rust.languageServer.rootFiles": ["Cargo.toml"],