Skip to content
/ snippets Public

LSP server for custom code snippets

Notifications You must be signed in to change notification settings

lamg/snippets

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
  • Multiple Installation Methods - Easy install scripts for Linux, macOS, and Windows

Quick Start

Installation

Linux/macOS:

cd Snippets
./install.sh

Windows (PowerShell):

cd Snippets
.\install.ps1

For development:

cd Snippets
./install-dev.sh

See INSTALL.md for detailed instructions.

Configuration

The tool looks for snippets at ~/.config/helix/snippets.toml

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 publish -c Release

Requirements

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

Example Helix config

After the snippets .NET tool is instealled 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

Watchers

Forks

Sponsor this project

 

Packages

No packages published