Skip to content

Migration

github-actions[bot] edited this page Jan 31, 2025 · 1 revision

πŸ“– Migration Guide

⚑ Cord - Rich Presence Reimagined

The plugin in question, cord.nvim, has been rewritten from scratch with a new client-server architecture in mind, bringing significant improvements in reliability and customization. Here's what you need to know when upgrading.

✨ What's New

  • We have switched to Cargo for building instead of directly calling rustc in build scripts, which often caused inconsistencies. But don't worry, the dependency count is still at zero! Plus, users can benefit from incremental builds.

  • The plugin now runs as a server that handles all your Neovim instances. When you start Neovim, it launches a server in the background and connects to it. Any additional Neovim instances will connect to the same server, ensuring only one Rich Presence is shown. The most recent activity always takes priority.

  • A new smart idle system has been implemented - you're only shown as idle when all your Neovim instances are actually idle. When an instance goes idle, it automatically switches back to show your most recent active one.

  • The plugin is now event-driven, meaning changes are reflected instantly without any polling delays. When all instances disconnect, the server, as well as the connection to Discord, stay alive for a little while (configurable) before shutting down, which helps to avoid rate limiting issues.

  • A new variables option allows users to define custom variables, including functions, for dynamic text templates. This enhances the flexibility and customization of the Rich Presence display.

  • Many of the icons have been redesigned, and a new theme has been introduced. The previous style, now called "Pastel" has been replaced with the new default style, "Onyx" which features a sleek and modern dark theme. You can switch between themes by using the display.theme option.

Important

The Rust compiler is no longer required. Cord's server can now be downloaded from GitHub via the :Cord update command. However, if you wish to build Cord from source, make sure to have Rust >= 1.85.0 nightly installed, and run the :Cord update build command.

πŸ”§ Configuration Changes

The config structure has been updated to be more flexible. Most notably, the majority of string options now support functions, giving you full control over the Rich Presence display. Additionally, a new variables option has been introduced to allow custom dynamic values in text templates.

Note

Full configuration options can be found here.

Changed Options

-- Removed Options
-- timer.interval (now event-driven)
-- display.show_repository
-- display.show_cursor_position
-- display.workspace_blacklist
-- lsp
-- usercmds (now always available under 'Cord <command>')

-- Renamed Options
timestamp = {             -- was timer
  enabled = true,         -- was display.show_time
  reset_on_idle = true,   -- was timer.reset_on_idle
  reset_on_change = true, -- was timer.reset_on_change
}

editor = {
  icon = nil,             -- was editor.image
}

idle = {
  enabled = true,         -- was idle.enable
  details = 'Idling',     -- was idle.text
  ignore_focus = false,   -- was idle.disable_on_focus (inverted)
}

Removed Features

Several built-in features have been removed in favor of customization through functions:

  • Workspace blacklist
  • Cursor position display
  • Problem count (The diagnostics plugin should be used instead)
  • ToggleTerm handling

These can now be implemented using hooks and custom functions. See examples.

🎨 Function-Based Customization

The new version moves most of the functionality handled in Rust, to the Lua side, giving you unprecedented control over your Rich Presence. Almost every string option can now be a function that receives contextual information:

text = {
    -- Example of dynamic text based on file type
    editing = function(opts)
        if opts.filetype == 'rust' then
            return 'πŸ¦€ Crafting in Rust'
        end
        return 'Editing ' .. opts.filename
    end,

    -- New types of mappings
    docs = 'Reading docs', -- Shown when in docs buffers
    dashboard = 'Home',    -- Shown when in dashboard buffers
}

-- Modify buttons dynamically
buttons = {
    {
        label = function(opts)
            if opts.repo_url then
                return 'View Repository'
            end
            return 'My Website'
        end,
        url = function(opts)
            return opts.repo_url or 'https://example.com'
        end
    }
}

-- New 'text' option that will override the entire text
assets = {
    ['Cargo.toml'] = {
        text = 'Managing dependencies' -- As opposed to 'Editing Cargo.toml'
    }
}

More information can be found in the Configuration Guide.