1
Fork 0
No description
Find a file
2025-07-11 23:59:29 +03:00
.github add linux arm64 build 2025-06-22 10:19:05 +02:00
builtin Add more missing when statements (in addition to ) 2024-09-22 15:29:26 +02:00
editors Support document parse on runtime package 2025-05-26 18:34:02 +02:00
images upload showcase gifs and images 2023-07-02 17:40:54 +02:00
misc Update schema for new attribute: enable_auto_import 2025-06-22 23:54:20 +02:00
src Fix issue resolving overloaded proc when the string passed in came from a different package to the overloaded proc 2025-07-10 21:19:42 -04:00
tests Fix issue resolving overloaded proc when the string passed in came from a different package to the overloaded proc 2025-07-10 21:19:42 -04:00
tools/odinfmt fix trailing whitespace in matrix formatting 2025-06-27 12:17:43 +02:00
.editorconfig Add .editorconfig matching odilfmt.json 2023-06-11 22:40:04 +02:00
.gitignore added the Edit global config command 2024-12-31 13:44:56 -08:00
build.bat Grow stack size on windows binaries. Support foreign import with when correctly. 2025-06-25 15:02:05 +02:00
build.sh Fix make ols version work with GNU sed and BSD/macOS sed 2025-01-10 04:42:31 +03:00
ci.bat Grow stack size on windows binaries. Support foreign import with when correctly. 2025-06-25 15:02:05 +02:00
ci.sh make ci.sh executable 2024-07-11 21:15:57 +02:00
flake.lock Bump odin flake dep 2025-07-11 23:59:29 +03:00
flake.nix Add nix flake 2025-07-11 23:59:29 +03:00
LICENSE Create LICENSE 2021-05-02 18:23:16 +02:00
odinfmt.bat Automatically add shared collection. 2024-02-22 20:46:13 +01:00
odinfmt.json update odinfmt.json 2024-08-10 18:17:51 +02:00
odinfmt.sh Automatically add shared collection. 2024-02-22 20:46:13 +01:00
package-lock.json Add exclude path for workspace symbols. 2024-12-30 22:20:28 +01:00
README.md feat: updated readme for ols instructions for lsp-mode 2025-06-29 08:36:45 +01:00

ols

Language server for Odin. This project is still in early development.

Note: This project is made to be up to date with the master branch of Odin.

Table Of Contents

Installation

cd ols

# for windows
./build.bat
# To install the odinfmt formatter
./odinfmt.bat

# for linux and macos
./build.sh
# To install the odinfmt formatter
./odinfmt.sh

Configuration

In order for the language server to index your files, it must know about your collections.

To do that you can either configure ols via an ols.json file (it should be located at the root of your workspace).

Or you can provide the configuration via your editor of choice.

Example of ols.json:

{
	"$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
	"collections": [
		{ "name": "custom_collection", "path": "c:/path/to/collection" }
	],
	"enable_semantic_tokens": false,
	"enable_document_symbols": true,
	"enable_hover": true,
	"enable_snippets": true,
	"profile": "default",
	"profiles": [
		{ "name": "default", "checker_path": ["src"]},
		{ "name": "linux_profile", "os": "linux", "checker_path": ["src/main.odin"]},
		{ "name": "windows_profile", "os": "windows", "checker_path": ["src"]}
	]
}

You can also set ODIN_ROOT environment variable to the path where ols should look for core and vendor libraries.

Options:

enable_format: Turns on formatting with odinfmt. (Enabled by default)

enable_hover: Enables hover feature

enable_snippets: Turns on builtin snippets

enable_semantic_tokens: Turns on syntax highlighting.

enable_document_symbols: Turns on outline of all your global declarations in your document.

enable_fake_methods: Turn on fake methods completion. This is currently highly experimental.

enable_inlay_hints: Turn on inlay hints for editors that support it.

enable_procedure_snippet: Use snippets when completing procedures—adds parenthesis after the name. (Enabled by default)

enable_checker_only_saved: Turns on only calling the checker on the package being saved.

enable_references: Turns on finding references for a symbol. (Experimental)

enable_rename: Turns on renaming a symbol. (Experimental)

odin_command: Allows you to specify your Odin location, instead of just relying on the environment path.

checker_args: Pass custom arguments to odin check.

verbose: Logs warnings instead of just errors.

profile: What profile to currently use.

profiles: List of different profiles that describe the environment ols is running under.

Odinfmt configurations

Odinfmt reads configuration through odinfmt.json.

Example:

{
	"$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/odinfmt.schema.json",
	"character_width": 80,
	"tabs": true,
	"tabs_width": 4
}

Options:

character_width: How many characters it takes before it line breaks it.

spaces: How many spaces is in one indentation.

newline_limit: The limit of newlines between statements and declarations.

tabs: Tabs or spaces.

tabs_width: How many characters one tab represents

sort_imports: A boolean that defaults to true, which can be set to false to disable sorting imports.

Features

Support Language server features:

  • Completion
  • Go to definition
  • Semantic tokens
  • Document symbols
  • Rename
  • References
  • Signature help
  • Hover

Clients

VS Code

Install the extension https://marketplace.visualstudio.com/items?itemName=DanielGavin.ols

Sublime

Install the package https://github.com/sublimelsp/LSP

Configuration of the LSP:

{
	"clients": {
		"odin": {
			"command": [
				"/path/to/ols"
			],
			"enabled": false, // true for globally-enabled, but not required due to 'Enable In Project' command
			"selector": "source.odin",
			"initializationOptions": {
				"collections": [
					{
						"name": "collection_a",
						"path": "/path/to/collection_a"
					}
				],
				"enable_semantic_tokens": true,
				"enable_document_symbols": true,
				"enable_hover": true,
				"enable_snippets": true,
				"enable_format": true,
			}
		}
	}
}

Vim

Install Coc.

Configuration of the LSP:

{
	"languageserver": {
		"odin": {
			"command": "ols",
			"filetypes": ["odin"],
			"rootPatterns": ["ols.json"]
		}
	}
}

Neovim

Neovim has a builtin support for LSP.

There is a plugin that makes the setup easier, called nvim-lspconfig. You can install it with your preferred package manager.

A simple configuration that uses the default ols settings would be like this:

require'lspconfig'.ols.setup {}

And here is an example of a configuration with a couple of settings applied:

require'lspconfig'.ols.setup {
	init_options = {
		checker_args = "-strict-style",
		collections = {
			{ name = "shared", path = vim.fn.expand('$HOME/odin-lib') }
		},
	},
}

Neovim can run Odinfmt on save using the conform plugin. Here is a sample configuration using the lazy.nvim package manager:

local M = {
   "stevearc/conform.nvim",
   opts = {
      notify_on_error = false,
      -- Odinfmt gets its configuration from odinfmt.json. It defaults
      -- writing to stdout but needs to be told to read from stdin.
      formatters = {
         odinfmt = {
            -- Change where to find the command if it isn't in your path.
            command = "odinfmt",
            args = { "-stdin" },
            stdin = true,
         },
      },
      -- and instruct conform to use odinfmt.
      formatters_by_ft = {
         odin = { "odinfmt" },
      },
   },
}
return M

Emacs

For Emacs, there are two packages available for LSP; lsp-mode and eglot.

The latter is built-in, spec-compliant and favours built-in Emacs functionality and the former offers richer UI elements and automatic installation for some of the servers.

In either case, you'll also need an associated major mode.

Pick either of the below, the former is likely to be more stable but the latter will allow you to take advantage of tree-sitter and other packages that integrate with it.

The use-package statements below assume you're using a package manager like Straight or Elpaca and as such should be taken as references rather than guaranteed copy/pasteable. If you're using package.el or another package manager then you'll have to look into instructions for that yourself.

;; Enable odin-mode and configure OLS as the language server
(use-package odin-mode
  :ensure (:host github :repo "mattt-b/odin-mode")
  :mode ("\\.odin\\'" . odin-mode))

;; Or use the WIP tree-sitter mode
(use-package odin-ts-mode
  :ensure (:host github :repo "Sampie159/odin-ts-mode")
  :mode ("\\.odin\\'" . odin-ts-mode))

And then choose either the built-in eglot or lsp-mode packages below. Both should work very similarly.

lsp-mode

As of lsp-mode pull request 4818 ols is included as a pre-configured client. You will need to install lsp-mode from source until version 9.1 has been released. Just M-x lsp-install-server and select ols. This will download and install the latest version of ols from the releases. Then start lsp-mode with M-x lsp or add hook on the below package

;; Pull the lsp-mode package from elpa
(use-package lsp-mode
  :commands (lsp lsp-deferred))

;; OR Pull lsp-mode from source using Straight this snippet has the install instructions for installing straight.el
(defvar straight-use-package-by-default t)
(defvar straight-recipes-repo-clone-depth 1)
(defvar straight-enable-github-repos t)
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name
        "straight/repos/straight.el/bootstrap.el"
        (or (bound-and-true-p straight-base-dir)
            user-emacs-directory)))
      (bootstrap-version 7))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;; Configure straight.el
(straight-use-package 'use-package)

(use-package lsp-mode
  :straight (lsp-mode :host github :repo "emacs-lsp/lsp-mode")
  :commands (lsp lsp-deferred))

;; Add a hook to autostart OLS
(add-hook 'odin-mode-hook #'lsp-deferred)
(add-hook 'odin-ts-mode-hook #'lsp-deferred) ;; If you're using the TS mode

eglot

;; Add OLS to the list of available programs
;; NOTE: As of Emacs 30, this is not needed.
(with-eval-after-load 'eglot
  (add-to-list 'eglot-server-programs '((odin-mode odin-ts-mode) . ("ols"))))

;; Add a hook to autostart OLS
(add-hook 'odin-mode-hook #'eglot-ensure)
(add-hook 'odin-ts-mode-hook #'eglot-ensure) ;; If you're using the TS mode

Helix

Helix supports Odin and OLS by default. It is already enabled in the default languages.toml.

If ols or odinfmt are not on your PATH environment variable, you can enable them like this:

# Optional. The default configration requires OLS in PATH env. variable. If not,
# you can set path to the executable like so:
# [language-server.ols]
# command = "path/to/executable"

Micro

Install the LSP plugin

Configure the plugin in micro's settings.json:

{
	"lsp.server": "c=clangd,go=gopls,odin=ols"
}

Kate

First, make sure you have the LSP plugin enabled. Then, you can find LSP settings for Kate in Settings -> Configure Kate -> LSP Client -> User Server Settings.

You may have to set the folders for your Odin home path directly, like in the following example:

{
    "servers": {
        "odin": {
            "command": [
                "ols"
            ],
            "filetypes": [
                "odin"
            ],
            "url": "https://github.com/DanielGavin/ols",
            "root": "%{Project:NativePath}",
            "highlightingModeRegex": "^Odin$",
            "initializationOptions": {
                "collections": [
                    {
                        "name": "core",
                        "path": "/path/to/Odin/core"
                    },
                    {
                        "name": "vendor",
                        "path": "/path/to/Odin/vendor"
                    },
                    {
                        "name": "shared",
                        "path": "/path/to/Odin/shared"
                    },
                    {
                        "name": "src", // If your project has src-collection in root folder, 
                        "path": "src"  // this will add it as a collection
                    },
                    {
                        "name": "collection_a",
                        "path": "/path/to/collection_a"
                    }
                ],
                "odin_command": "path/to/Odin",
                "verbose": true,
                "enable_document_symbols": true,
                "enable_hover": true
            }
        }
    }
}

Kate can infer inlay hints on its own when enabled in LSP settings, so enabling it separately in the server config can cause some weird behavior.