Skip to content

Repository files navigation

Snippets

.NET F# License: MIT NuGet Version Tests

A Language Server Protocol (LSP) implementation for code snippet completion, designed to integrate with the Helix editor and other LSP-compatible editors.

asciicast

Features

  • LSP-Compliant - Full support for the Language Server Protocol
  • TOML Configuration - Simple TOML format for snippet definitions
  • Helix Integration - Optimized for the Helix editor
  • Case-Sensitive Matching - Configurable snippet matching
  • Debug Logging - Built-in debugging capabilities
  • Cross-Platform Install - Build and install via dotnet fsi build.fsx
  • RID-Aware Tool Packages - NuGet publishes Native AOT binaries when available, with any fallback

Quick Start

Installation

Run from the repository root:

Linux/macOS:

dotnet fsi build.fsx

Windows (PowerShell):

dotnet fsi build.fsx

For development:

dotnet fsi build.fsx --target InstallGlobalDev

See INSTALL.md for detailed instructions.

Configuration

The tool looks for snippets at ~/.config/helix/snippets.toml Snippets/snippets.toml in this repository is a valid snippets file and a good starting point.

Example snippets file:

forloop=for i in 0..10 do
ifblock=if condition then
  // code
endif

Usage

Run the language server:

snippets

Enable debug logging:

SNIPPETS_DEBUG=1 snippets

Architecture

The project consists of:

  • Types.fs - Core data types and configuration
  • TomlParser.fs - TOML snippet file parsing
  • SnippetMatcher.fs - Snippet matching and ranking
  • CompletionProvider.fs - LSP completion item generation
  • LspProtocol.fs - LSP protocol implementation
  • JsonRpc.fs - JSON-RPC message handling
  • MessageHandler.fs - Message routing and processing
  • Program.fs - Server entry point

Development

Build

dotnet build

Run Tests

dotnet test

Build Release

dotnet fsi build.fsx --target Pack

Requirements

  • .NET 10.0 or later
  • F# 8.0 or later

Example Helix config

After the snippets .NET tool is installed you can configure Helix to use this server for Markdown files, by writing the following at ~/.config/helix/languages.toml

[language-server.snippets]
command = "snippets"

[[language]]
name = "markdown"
file-types = ["md"]
language-servers = ["snippets"]

The completions are triggered by the character :. The snippet file should be at ~/.config/helix/snippets.toml. Example content:

:eq=≡
:neq=≢
:and=∧
:or=∨
:implies=⇒
:follows=⇐

Testing

The project includes comprehensive tests for:

  • TOML parsing
  • Snippet matching
  • Completion provider logic
  • JSON-RPC message handling

Run tests with:

dotnet test

Environment Variables

  • SNIPPETS_DEBUG - Set to 1 to enable debug logging (default: depends on config)

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

About

LSP server for custom code snippets

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages