Skip to content

OCaml configuration

Documentation index · Editor reference

Cobalt starts with built-in defaults and executes your OCaml configuration to change them. Palette commands and keybindings subsequently change live session settings only. Cobalt never rewrites your configuration or saves preference overrides.

Location and first configuration

Create ~/.config/cobalt/config.ml. If XDG_CONFIG_HOME is an absolute nonempty path, use $XDG_CONFIG_HOME/cobalt/config.ml instead. Cobalt does not create the file for you. An absent configuration uses the defaults and needs no compiler.

Migrating from Ches

Move your existing ~/.config/ches/config.ml to ~/.config/cobalt/config.ml (or the equivalent directories under $XDG_CONFIG_HOME). In that file, change Ches_config references to Cobalt_config. The old configuration location is not read automatically. Update shell aliases or launchers to invoke cobalt. Configuration caches are rebuilt under $XDG_CACHE_HOME/cobalt/config or ~/.cache/cobalt/config; the old cache does not need to be copied.

Opening and editing configuration

From the command palette (Space c c), choose Open configuration to open this exact path in Cobalt. Existing unsaved config buffers are reused. If the file does not exist, it opens as an unsaved buffer; the command does not create files or directories or execute configuration. Save normally, then use Reload configuration to apply it. If the parent directory is absent, create it before saving.

open Cobalt_config

let () =
  Completion.set_enabled true;
  Completion.set_ghost_preview false;
  Completion.set_min_prefix_chars 1;
  Completion.set_prefer_local_snippets true;
  Signature_help.set_enabled true;
  View.set_line_numbers false;
  View.set_relative_line_numbers false;
  Theme.set "vim-classic"

This example specifies the current defaults. Change or omit whichever lines you like. An editable copy is available as config.example.ml.

The file is real executable OCaml: you can use local functions, conditionals, and the standard library. For example:

open Cobalt_config

let () =
  View.set_line_numbers true;
  match Sys.getenv_opt "COBALT_GHOST" with
  | Some "1" -> Completion.set_ghost_preview true
  | _ -> ()

Supported settings

Setter Default Meaning
Completion.set_enabled true Automatically request suggestions while typing
Completion.set_ghost_preview false Preview a simple selected completion suffix
Completion.set_min_prefix_chars 1 Positive number of identifier characters needed for automatic completion
Completion.set_prefer_local_snippets true Rank local snippet candidates ahead of LSP candidates
Completion.set_color ~role Theme-derived Override one completion-menu color with "#RRGGBB"
Signature_help.set_enabled true Automatically show server-provided call signatures while typing
View.set_line_numbers false Show absolute line numbers; applies across presentation profiles
View.set_relative_line_numbers false Show relative line numbers; enable both number settings for hybrid mode
View.set_startup_workspace false Start standalone Cobalt in Workspace instead of Zen
View.set_startup_silver_overview true Include Silver Overview in the initial standalone workspace
File_picker.set_include_ignored false Include files excluded by Git/ripgrep ignore rules in Find project files
File_picker.set_max_candidates 50_000 Positive file discovery candidate limit
File_picker.set_max_total_path_bytes 8 * 1024 * 1024 Positive retained candidate path-string budget, in bytes
Theme.set "vim-classic" Select a built-in theme by ID

For hybrid numbers (absolute current line, relative surrounding lines), use:

let () =
  View.set_line_numbers true;
  View.set_relative_line_numbers true

Both switches are reapplied on configuration reload in Workspace, Zen, and Bare.

Manual Ctrl-n and punctuation triggers bypass the minimum-prefix setting. Turning off local-snippet preference changes ranking, not availability. Prefix scanning remains bounded at 4096 bytes, so very large thresholds can suppress automatic identifier suggestions. Use cobalt --list-themes to find theme IDs; this command does not execute configuration. An explicit --theme NAME takes precedence over configuration at startup and on reload.

These setters are the initial supported API. Other editor options retain their existing CLI/keybinding behavior; arbitrary editor commands and external OCaml packages are not exposed through this configuration API.

Starting with just the editor, Status, and Problems

Add this to config.ml:

let () =
  Cobalt_config.View.set_startup_workspace true;
  Cobalt_config.View.set_startup_silver_overview false

History is already hidden at startup. --workspace still selects Workspace and honors the Overview setting; --bare takes precedence and returns to that workspace when toggled off. An explicit --silver-endpoint and --silver-project launch still starts in Workspace with Overview, unless you also pass --bare.

These settings apply only at startup; reloading does not rearrange the current session. Space v z still toggles Zen, Space v S toggles Overview, and Space v m toggles History. Layout: Default and Layout: Silver still apply their built-in layouts, both of which include Overview when available.

Finding ignored files

To search Git-ignored notes without changing what Git tracks:

let () =
  Cobalt_config.File_picker.set_include_ignored true;
  Cobalt_config.File_picker.set_max_candidates 100_000;
  Cobalt_config.File_picker.set_max_total_path_bytes (64 * 1024 * 1024)

The switch disables all ripgrep ignore rules, including .gitignore, .ignore and global ignores. Hidden paths and .git metadata remain excluded; directory symlinks are not followed. This affects Find project files (Space f f), not content search. It does not change .gitignore or add private files to Git.

Large trees may require both higher limits, as in the example. The byte budget counts root, absolute, relative and escaped display strings, not file contents; indexes and ranking require additional memory. Other discovery bounds remain unchanged (4 KiB/path, 32 MiB output, 30-second timeout). A truncated list is not exhaustive and is labelled in the picker.

After Reload configuration, close and reopen the file picker to use the new settings. Changed settings invalidate incompatible reopen-cache data. Removing the setters and reloading restores the defaults.

Session changes and reload

Completion menu colors

The completion menu has independent colors for candidate labels, source tags, detail/type strings, matching prefixes, and documentation. Selected rows share a subdued background without flattening all foregrounds into the Insert-mode color. The complete detail string uses one semantic color; it is not syntax-tokenized.

For example, add this dark-menu palette to config.ml:

let () =
  Completion.set_color ~role:"background" "#18212b";
  Completion.set_color ~role:"selected_background" "#283447";
  Completion.set_color ~role:"label" "#e1e7ef";
  Completion.set_color ~role:"selected_label" "#ffffff";
  Completion.set_color ~role:"source" "#91a0b5";
  Completion.set_color ~role:"selected_source" "#a9bad1";
  Completion.set_color ~role:"detail" "#b8d7a3";
  Completion.set_color ~role:"selected_detail" "#c9e8b4";
  Completion.set_color ~role:"match" "#82baff";
  Completion.set_color ~role:"selected_match" "#acd2ff";
  Completion.set_color ~role:"documentation" "#d0d9e6"
Role Applies to
background Unselected rows and documentation background
selected_background Entire selected row, including spacing and trailing padding
label / selected_label Candidate name and row marker/padding foreground
source / selected_source [LSP], [buffer], or [snippet]
detail / selected_detail Type/signature/detail string after the source
match / selected_match Actual typed-prefix match in the displayed candidate label
documentation Completion documentation text

Specify only the roles you want to override. Selected and unselected foregrounds are independent; setting detail alone does not set selected_detail. Omitted roles follow the current theme, including theme previews and switches. Defaults are adjusted for readability across dark and light palettes; explicit overrides are applied exactly as supplied. Matching prefixes are emphasized by the default font policy and remain tied to the original prefix while cycling candidates.

Colors must be strict six-digit hex strings; letter case is accepted either way. Repeated declarations are last-wins. Invalid roles or colors reject the entire configuration reload, preserving your active settings. Removing an override and reloading restores that role's theme default. Use Reload configuration after editing; completion color settings follow the same startup/session model as other preferences.

Applying session settings

After startup, toggling line numbers, completion, ghost text, or the theme affects only the running session. To make a setting permanent, edit config.ml.

Select Reload configuration in the command palette (Space c c) to:

  1. Construct fresh supported defaults.
  2. Compile if needed and execute your current configuration.
  3. Validate all settings, including the theme and snippet declarations.
  4. Apply settings and the snippet catalog together.

For settings other than the startup layout, removing a setter restores its default on reload. Successful reloads discard temporary changes to those settings while preserving buffers, unsaved text, and live layout preferences. Completion menus and theme previews are dismissed when the new settings take effect. A missing file reloads defaults.

A compile, execution, or validation failure preserves the current settings/catalog and reports the error. At startup, failure uses defaults and reports the diagnostic after opening the editor. Compiler errors reference the original filename and line.

Execution requirements

ocamlc must be on PATH when config.ml exists. Cobalt embeds the small Stdlib-only Cobalt_config API and compiles it with your file into a temporary helper. No installed Cobalt development libraries, Dune invocation, or PPX dependencies are needed. Cobalt caches compiled helpers, but executes the program on every startup and explicit reload. Environment-dependent settings and file reads remain fresh; evaluated settings and session toggles are never persisted.

The compiled cache lives at $XDG_CACHE_HOME/cobalt/config for an absolute nonempty XDG path, otherwise $HOME/.cache/cobalt/config. Changes to source text/path, the embedded API/protocol, compiler/toolchain, or relevant compile environment invalidate the entry. Corrupt/missing entries are rebuilt before execution. Unavailable cache storage falls back to temporary compilation. Removing this cache merely forces recompilation on the next load; it does not remove preferences or snippets.

The cache retains up to 16 entries / 64 MiB on a best-effort basis. Configurations using dependency-affecting OCAMLPARAM flags, such as external preprocessors, compile ephemerally rather than risking stale dependencies. A runtime error is reported without retrying your code, avoiding duplicate execution of its effects.

Startup waits for configuration before mounting the interactive UI. Reloading is asynchronous; editing continues, and obsolete results cannot overwrite a newer reload. Compilation has a ten-second deadline and execution a two-second deadline. Config source and result sizes are bounded at 1 MiB. Helpers and temporary files are cleaned up after success or failure.

The helper runs in a private temporary working directory, so use absolute paths for any files your configuration reads. It executes ordinary OCaml code, rather than a sandboxed expression language. Cobalt itself does not write your config file.

Snippets

Define templates in config.ml with Snippets.add:

let () =
  Snippets.add
    ~id:"personal.module"
    ~prefix:"mymod"
    ~scope:[ "systemverilog" ]
    ~description:"Module named after this file"
    {snippet|module ${1:${TM_FILENAME_BASE:untitled}} (
    $0
);
endmodule|snippet}

The filename supplies the first field's default, which stays selected and editable after acceptance. Linked $1 occurrences would mirror edits to it. The same body syntax supports ordinary defaults and choices. Use named quoted strings such as {snippet|...|snippet} when a body contains choices: the choice ending |} would prematurely close an unnamed {|...|} string. Named strings also let you include quotes and backslashes without OCaml escaping.

API:

Snippets.add ~id ~prefix ?scope ?collection ?description body
Snippets.disable ~id
Snippets.set_collection_enabled ~collection enabled
  • id is a stable identity; matching IDs override earlier declarations or starters.
  • prefix is the case-sensitive completion trigger. description is optional.
  • Omitted or empty scope is global. Recognized scopes are "systemverilog", "verilog", "ocaml", or extensions such as ".py".
  • collection optionally groups templates independently of file scope. All collections default to enabled; untagged templates remain enabled. Use Snippets.set_collection_enabled ~collection:"hardcaml" false to hide a collection and its dotted descendants. The last matching toggle wins.
  • Collection toggles preserve definitions for re-enabling; disable ~id removes an individual definition. Overrides use their own metadata and do not inherit the old collection. See collections and bundled templates for examples, naming rules, dependencies, and available triggers.
  • Declarations execute in order: the last operation for an ID wins. For example, Snippets.disable ~id:"sv.aff" removes the bundled clocked-block template.
  • Every declaration is validated, including ones replaced later. Errors identify the offending ID and reject the entire settings/catalog update.
  • A fresh evaluation begins with no OCaml snippet operations. Removing a declaration restores the underlying template on the next successful reload.

See snippets.example.ml for copyable templates and snippet controls for supported syntax.

To discover templates without remembering prefixes, choose Insert snippet from the palette in a file's Normal mode. Search by prefix, description, ID, or collection; the preview identifies the effective declaration's origin (bundled, legacy JSON, or OCaml), scope, collection, and raw body when space permits. Enter inserts the selected template at the cursor and activates its fields. Escape cancels without editing.

Legacy JSON compatibility

An existing snippets.json remains supported. Effective order is bundled starters → legacy JSON → OCaml declarations. Delayed JSON loads and Reload snippets reapply the current OCaml layer, so they cannot overwrite your OCaml definitions. Reload configuration applies settings and OCaml snippets together; Reload snippets reloads only the legacy JSON base.

When migrating, transfer your definitions into config.ml, validate/reload it, and move the JSON file to an inactive backup name. On restart, absent JSON means the base contains bundled starters only. This is a manual migration; the editor does not rewrite either file. The legacy format is documented in the editor reference.