lunjon / snippetls

A language server with snippet support only.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SnippetLS

A pure Go, although rudimentary, implementation of a language server for the language server protocol (LSP) that only provides snippet support.

Installation

Using go:

go get github.com/lunjon/snippetls

Usage

This language server was only developed in order to inject snippets into an editor with LSP snippet support.

Snippets are loaded per language as a file name <ext>.kdl put into the ~/.config/snippetls/. So, for instance, to load snippets for the rust programming language you would create such a file named rs.kdl.

Snippet definitions

The snippets are defined in kdl files, since they are typically very simple.

Example

# go.kdl

// You can use raw strings in order to define snippets
// containing " easily:
log r#"log.Printf("$1")"#

iferr "if err != nil {
    $1 
}"

// The node name is the trigger
map {
    // Snippet can be specified using the "snippet" node name
    snippet "map[string]$1"
    // Defined one or more aliases for the trigger
    aliases "m" "mp"
}

Global snippets

Global are snippets that are included for all file types. They can be defined in a file called global.kdl. That is, create a file called global.kdl and these snippets will be available for all file types.

Configuration

You can create a file called config.kdl (in the same directory as the snippets).

This is used to configure snippetls:

// This section can also be called "extends"
valid-for {
    ex "exs"            // Include all snippets in ex.kdl for exs files as well
    ts "tsx" "js" "jsx" // The ts.kdl snippets are valid for JS and react files
    md "txt"            // The markdown snippets are also valid for .txt files
}

About

A language server with snippet support only.

License:MIT License


Languages

Language:Go 99.4%Language:Just 0.6%