hx-lsp

April 28, 2026 · View on GitHub

中文文档

An LSP tool that provides custom code snippets and Code Actions for Helix Editor.


Features

LSP Commands

  • reload snippets - Reload snippet configurations
  • reload actions - Reload action configurations

Core Features

FeatureDescriptionRelated PR
CompletionVSCode-style code snippetshelix#9801
Code ActionsCustom shell script actions-
Document ColorsCSS/Bevy color previewhelix#12308
Word Case Conversionsnake_case, CamelCase, PascalCase-

Markdown-Specific Features

  • Table Formatter - Auto-align table columns (selection must contain header separator |:-)
  • Text Styling - Bold, Italic, Strikethrough
  • List Conversion - Ordered, Unordered, Task lists

Installation

cargo install --force hx-lsp

From Source

git clone https://github.com/erasin/hx-lsp.git
cd hx-lsp
cargo install --path .

Configuration

hx-lsp is configured through Helix's languages.toml file using the TOML format.

Helix Language Configuration

Helix uses languages.toml for LSP and language server configuration:

  • Global: $XDG_CONFIG_HOME/helix/languages.toml
  • Project: WORKSPACE_ROOT/.helix/languages.toml

About WORKSPACE_ROOT: Obtained from the rootPath in Helix's initialize request. When multiple .helix directories exist at different levels, the closest one is used.

Configuration Example

Add hx-lsp support for Markdown with custom configuration:

[language-server.hx-lsp]
command = "hx-lsp"

[language-server.hx-lsp.config]
markdown = false              # Disable markdown features
documentColor = true         # Enable document color

[[language]]
name = "markdown"
language-servers = ["hx-lsp"]

[[language]]
name = "html"
language-servers = [
  "vscode-html-language-server",
  "hx-lsp"
]

About language id: Refer to helix/languages.toml and Helix Wiki.

Helix supports filtering LSP features using only-features and except-features. hx-lsp supports:

  • completion - Code completion
  • code-action - Code actions
  • document-colors - Document colors

LSP Configuration Protocol

hx-lsp supports dynamic configuration via the LSP protocol. Configuration can be passed through:

  1. language-server.hx-lsp.config in languages.toml (TOML format)
  2. initializationOptions during server initialization (JSON format)

Configuration Options

OptionTypeDefaultDescription
markdownbooleantrueEnable/disable markdown language features
documentColorbooleantrueEnable/disable document color provider

Configuration Formats

TOML format (in languages.toml):

[language-server.hx-lsp.config]
markdown = false
documentColor = true

JSON format (initializationOptions):

{ "markdown": true, "documentColor": true }

Or nested format:

{
  "settings": {
    "markdown": true,
    "documentColor": true
  }
}

Configuration Files

Configuration files use jsonc format (supports comments, but no trailing commas).

Supported comment styles: // ..., /* ... */, # ...

File Loading Paths

Snippets:

  • Global: $XDG_CONFIG_HOME/helix/snippets/
  • Project: WORKSPACE_ROOT/.helix/snippets/

Actions:

  • Global: $XDG_CONFIG_HOME/helix/actions/
  • Project: WORKSPACE_ROOT/.helix/actions/

When LSP receives textDocument/didOpen request, it automatically loads configuration files for the corresponding language.

Use Helix command :lsp-workspace-command to open the command picker and manually reload snippets or actions.


Snippets

hx-lsp is compatible with VSCode Snippets format.

File Naming Convention

  • Global snippets: {name}.code-snippets
  • Language-specific: {language_id}.json
snippets/
├── global.code-snippets    # Global snippets
├── html.json              # HTML snippets
└── markdown.json          # Markdown snippets

Snippet Format

FieldTypeDescription
prefixString or String[]Trigger keywords for completion
bodyString or String[]Snippet content
descriptionString or String[]Description (optional)

Example

{
  "mdbookNote": {
    "prefix": "mdbookNote",
    "body": [
      "```admonish note ${1:title=\"\$2\"}",
      "${3:content}",
      "```"
    ],
    "description": "mdbook admonish note"
  },

  "mdbookBob": {
    "prefix": "mdbookBob",
    "body": "```svgbob\n\$1\n```",
    "description": "mdbook svgbob"
  },

  "dir": {
    "prefix": "dir",
    "body": [
      "TM_FILENAME: $TM_FILENAME",
      "TM_FILENAME_BASE: $TM_FILENAME_BASE",
      "TM_DIRECTORY: $TM_DIRECTORY",
      "TM_FILEPATH: ${TM_FILEPATH}",
      "RELATIVE_FILEPATH: $RELATIVE_FILEPATH",
      "WORKSPACE_NAME: $WORKSPACE_NAME",
      "WORKSPACE_FOLDER: $WORKSPACE_FOLDER"
    ],
    "description": "Show current file path information"
  }
}

Code Actions

Actions allow conditional execution of shell scripts and insert the output into the editor.

actions/
├── html.json
└── markdown.json

Action Format

FieldTypeDescription
titleStringTitle displayed in Helix
filterString or String[]Shell script, action enabled when returning true, 1, or empty
shellString or String[]Shell script, output replaces selected text
descriptionString or String[]Description (optional)

Note: Selected text is passed via Stdio::piped. Use $(cat) to capture it in scripts, or use variable $TM_SELECTED_TEXT.

Examples

Markdown text formatting:

/* actions/markdown.json */
{
  "bold": {
    "title": "Bold",
    "filter": "",
    "shell": ["echo -n \"**${TM_SELECTED_TEXT}**\""],
    "description": "Make selected text bold"
  },
  "italic": {
    "title": "Italic",
    "filter": "",
    "shell": ["echo -n \"_${TM_SELECTED_TEXT}_\""],
    "description": "Make selected text italic"
  }
}

Go language run script:

/* actions/go.json */
{
  "run main": {
    "title": "Run main",
    "filter": "[[ \"$TM_CURRENT_LINE\" == *main* ]] && echo true || echo false",
    "shell": [
      "alacritty --hold --working-directory ${TM_DIRECTORY} -e go run ${TM_FILENAME};",
      "notify-send \"Golang\" \"RUN: ${TM_FILENAME}\""
    ],
    "description": "Run Go main program in new terminal"
  },
  "run main in tmux": {
    "title": "tmux: Run main",
    "filter": "[[ \"$(cat)\" == *main* ]] && echo true || echo false",
    "shell": [
      "tmux split-window -h -c ${WORKSPACE_FOLDER}; tmux send 'go run ${TM_FILENAME}' Enter"
    ],
    "description": "Run Go main program in tmux"
  }
}

Variables

Variables can be used in snippet.body, action.filter, and action.shell.

Syntax: Supports both $VARIABLE and ${VARIABLE} formats.

VariableDescription
TM_SELECTED_TEXTCurrently selected text
TM_CURRENT_LINEContent of the line where cursor is
TM_CURRENT_WORDWord under cursor
TM_LINE_INDEXLine index (0-based)
TM_LINE_NUMBERLine number (1-based)
TM_FILENAMECurrent filename
TM_FILENAME_BASECurrent filename without extension
TM_DIRECTORYDirectory of current file
TM_FILEPATHFull path of current file
RELATIVE_FILEPATHFile path relative to workspace
CLIPBOARDClipboard content
WORKSPACE_NAMEWorkspace/folder name
WORKSPACE_FOLDERWorkspace/folder path
CURSOR_INDEXCursor index (0-based)
CURSOR_NUMBERCursor index (1-based)

Date & Time

VariableDescriptionExample
CURRENT_YEARCurrent year2025
CURRENT_YEAR_SHORTLast two digits of year25
CURRENT_MONTHMonth (zero-padded)02
CURRENT_MONTH_NAMEFull month nameFebruary
CURRENT_MONTH_NAME_SHORTShort month nameFeb
CURRENT_DATEDate (zero-padded)08
CURRENT_DAY_NAMEFull day nameSaturday
CURRENT_DAY_NAME_SHORTShort day nameSat
CURRENT_HOURHour (24-hour format)14
CURRENT_MINUTEMinute30
CURRENT_SECONDSecond45
CURRENT_SECONDS_UNIXUnix timestamp1738930245
CURRENT_TIMEZONE_OFFSETTimezone offset+08:00

Random Values

VariableDescription
RANDOM6-digit random number
RANDOM_HEX6-digit random hex string
UUIDUUID v4

Comment Symbols (Reserved)

VariableDescription
BLOCK_COMMENT_STARTBlock comment start symbol
BLOCK_COMMENT_ENDBlock comment end symbol
LINE_COMMENTLine comment symbol

Document Color

hx-lsp supports recognizing various color formats and displaying color previews in the editor.

Standard CSS Colors

Hexadecimal:

  • #ffffff - Standard 6-digit hex

RGB/RGBA:

  • rgb(255, 255, 255) - Integer format
  • rgb(2.0, 255.0, 255.0) - Float format
  • rgb(100%, 0%, 50%) - Percentage format
  • rgba(1.0, 0.0, 0.0, 0.5) - With alpha

HSL/HSLA:

  • hsl(240, 50%, 50%) - Hue 0-360 degrees, saturation/lightness percentages
  • hsl(180, 0.5, 0.5) - Float format
  • hsla(300, 100%, 100%, 0.5) - With alpha

HSV/HSVA:

  • hsv(300, 100%, 100%) - Hue 0-360 degrees, saturation/value percentages
  • hsv(180, 0.5, 0.5) - Float format
  • hsva(180, 0.5, 0.5, 0.5) - With alpha

Bevy Game Engine Colors

  • srgb(1.0, 0.0, 0.0) - Standard RGB (0.0-1.0)
  • srgba(1.0, 0.0, 0.0, 0.8) - With alpha

References