Setting Up Your Environment for Onyx
The following sections will help set up an environment for you to program Onyx effectively.
VS Code Vim / Neovim Sublime text Emacs Language Server
(If you don't see your favorite editor here, consider making a issue!)
Visual Studio Code
Onyx has an official published extension on the Visual Studio Marketplace. Search "Onyx Programming Language" in the extensions panel or install from the marketplace.
Alternatively, you can follow these steps to install the extension from the VSIX file included in the Onyx distribution.
- Hit "Control+Shift+P" on Windows/Linux, or "Command+Shift+P" on MacOS.
- Search for and select "Extensions: Install from VSIX".
Go to your
ONYX_PATH
and select the.vsix
file in themisc
folder.- Restart VS Code.
This extension does have support for the onyx lsp
, assuming that is setup.
Vim / NeoVim
Follow the instructions on the onyx.vim GitHub repo.
Note, that this extension currently does not setup the LSP. That must be done separately.
Sublime Text
Currently, Onyx does not have a published package on Sublime Text's Package Control, but like VS Code, you are able to install it manually.
In the misc
folder of your installation, there is a file called onyx.sublime-syntax
. Simply copy this into the Packages/User
folder for Sublime Text. See more details here.
Emacs
Currently, Onyx does not have a published package for Emacs.
However, in the misc
folder, there is an Emacs Lisp file that provides an onyx-mode
.
You should be able to load it into your Emacs config and enable onyx-mode
to get syntax highlighting.
Language Server
If you are unfamiliar, a Language Server abstracts the tooling and language specific functionality out of editors and into a reusable component. This way, it is easier to develop in-editor functionality across multiple editors, as the same work does not need to be replicated for each supported editor.
Installing the Language Server
On Linux, MacOS, or the Windows Subsystem for Linux, run the following commands.
# Clone the Onyx Language Server
git clone https://github.com/onyx-lang/onyx-lsp
cd onyx-lsp
# Make the install script executable
chmod +x ./install.sh
# Install the LSP (compiles and places the WASM file into $ONYX_PATH/tools)
./install.sh
On Windows, run the following commands.
REM Clone the Onyx Language Server
git clone https://github.com/onyx-lang/onyx-lsp
cd onyx-lsp
REM Install the LSP (compiles and places the WASM file into %ONYX_PATH%/tools)
install.bat
Visual Studio Code
Installing the extension automatically enables the language server in VS Code.
Neovim
To use the language server in NeoVim, you need to have the NeoVim lspconfig package installed.
Then, you need the following in your NeoVim configuration somewhere:
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'
configs.onyx = {
default_config = {
cmd = { "onyx", "lsp" },
filetypes = { "onyx" },
root_dir = function(filename)
local utils = require "lspconfig.util"
return utils.search_ancestors(filename, function(path)
if utils.path.is_file(utils.path.join(path, "onyx-lsp.kdl")) then
return path
end
end)
end;
settings = {}
}
}
lspconfig.onyx.setup {
on_attach = function(client)
print("Onyx LSP started.")
end
}
Sublime Text
Install the LSP
package, and add the following custom configuration.
See more information on the LSP package docs.
{
"clients": {
"onyx": {
"enabled": true,
"command": ["onyx", "lsp"],
"selector": "source.onyx"
}
}
}