Allow to use common word completion and snippets for Helix editor
demo.mp4
Based on comment
From GitHub:
$ cargo install --git https://github.com/estin/simple-completion-language-server.git
From local repository:
$ git clone https://github.com/estin/simple-completion-language-server.git
$ cd simple-completion-language-server
$ cargo install --path .
You can install simple-completion-language-server
using the nix package manager from nixpkgs.
Note
At the moment the package is only available on the unstable channel of nixpkgs.
# Add it to a temporary shell environment
nix shell nixpkgs#simple-completion-language-server
# Add it to your current profile
nix profile install nixpkgs#simple-completion-language-server
Note
The above instructions assume you have enabled the experimental features nix-command
flakes
. If you are unsure about what this means or how to check read here.
If you are on NixOS or are using home-manager you can do one of the following:
# NixOS configuration.nix
environment.systemPackages = [pkgs.simple-completion-language-server];
# or home-manager config
home.packages = [pkgs.simple-completion-language-server];
# This will let `hx` know about the location of the binary without putting it in your $PATH
programs.helix.extraPackages = [pkgs.simple-completion-language-server];
For Helix on ~/.config/helix/languages.toml
# introduce new language server
[language-server.scls]
command = "simple-completion-language-server"
[language-server.scls.config]
max_completion_items = 100 # set max completion results len for each group: words, snippets, unicode-input
feature_words = true # enable completion by word
feature_snippets = true # enable snippets
snippets_first = true # completions will return before snippets by default
snippets_inline_by_word_tail = false # suggest snippets by WORD tail, for example text `xsq|` become `x^2|` when snippet `sq` has body `^2`
feature_unicode_input = false # enable "unicode input"
feature_paths = false # enable path completion
feature_citations = false # enable citation completion (only on `citation` feature enabled)
# write logs to /tmp/completion.log
[language-server.scls.environment]
RUST_LOG = "info,simple-completion-language-server=info"
LOG_FILE = "/tmp/completion.log"
# append language server to existed languages
[[language]]
name = "rust"
language-servers = [ "scls", "rust-analyzer" ]
[[language]]
name = "git-commit"
language-servers = [ "scls" ]
# etc..
# introduce a new language to enable completion on any doc by forcing set language with :set-language stub
[[language]]
name = "stub"
scope = "text.stub"
file-types = []
shebangs = []
roots = []
auto-format = false
language-servers = [ "scls" ]
Read snippets from dir ~/.config/helix/snippets
or specify snippets path via SNIPPETS_PATH
env.
Default lookup directory can be overriden via SCLS_CONFIG_SUBDIRECTORY
as well (e.g. when SCLS_CONFIG_SUBDIRECTORY = vim
, SCLS will perform it's lookups in ~/.config/vim
instead)
Currently, it supports our own toml
format and vscode json
(a basic effort).
Filename used as snippet scope (language id), filename snippets.(toml|json)
will not attach scope to snippets.
For example, snippets with the filename python.toml
or python.json
would have a python
scope.
Snippets format
[[snippets]]
prefix = "ld"
scope = [ "python" ] # language id https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
body = 'log.debug("$1")'
description = "log at debug level"
Configure sources in ~/.config/helix/external-snippets.toml
(or via env EXTERNAL_SNIPPETS_CONFIG
)
-
Declare list of sources by key
[[sources]]
-
Optionally, declare paths to load snippets on current source by
[[source.paths]]
.
Highly recommended to declare concrete paths with scopes. To explicit configure required snippets and its scopes.
Snippets suggestion filtered out by document scope.
Scope it's language id and not file extension by language server protocol.
If [[source.paths]]
isn't specified for source then all files with extensions .json
and .toml
would be tried to load. Scope at that case would be equal filename.
To apply snippets the filename must be one of known language id.
- Run commands to fetch and validate snippets
# Clone or update snippets source repos to `~/.config/helix/external-snippets/<repo path>`
simple-completion-language-server fetch-external-snippets
# Try to find and parse snippets
simple-completion-language-server validate-snippets
# first external source to load snippets
[[sources]] # list of sources to load
name = "source1" # optional name shown on snippet description
git = "https://example.com/source1.git" # git repo with snippets collections
[[sources.paths]] # explicit list of paths to load on current source
scope = ["scope1", "scope2"] # optional scopes (language id) for current snippets
path = "path-in-repo/snippets1.json" # where snippet file or dir located in repo
[[sources.paths]]
scope = ["scope3"]
path = "path-in-repo/snippets2.json"
# next external source to load snippets
[[sources]]
name = "source2"
git = "https://example.com/source2.git"
[[sources.paths]]
scope = ["scope1"]
path = "path-in-repo-of-source2/snippets1.json"
Load python snippets from file https://github.com/rafamadriz/friendly-snippets/blob/main/snippets/python/python.json
File ~/.config/helix/external-snippets.toml
[[sources]]
name = "friendly-snippets"
git = "https://github.com/rafamadriz/friendly-snippets.git"
[[sources.paths]]
scope = ["python"]
path = "snippets/python/python.json"
Clone or update snippets source repos to ~/.config/helix/external-snippets/<repo path>
$ simple-completion-language-server fetch-external-snippets
Validate snippets
$ simple-completion-language-server validate-snippets
Read unicode input config as each file from dir ~/.config/helix/unicode-input
(or specify path via UNICODE_INPUT_PATH
env).
Unicode input format (toml key-value), for example ~/.config/helix/unicode-input/base.toml
alpha = "α"
betta = "β"
gamma = "γ"
fire = "🔥"
Validate unicode input config
$ simple-completion-language-server validate-unicode-input
Citation keys completion from bibliography file declared in current document.
When completion is triggered with a prefixed @
(which can be configured via citation_prefix_trigger
settings), scls will try to extract the bibliography file path from the current document (regex can be configured via the citation_bibfile_extract_regexp
setting) to parse and use it as a completion source.
To enable this feature, scls must be compiled with the --features citation
flag.
$ cargo install --features citation --git https://github.com/estin/simple-completion-language-server.git
And initialize scls with feature_citations = true
.
[language-server.scls.config]
max_completion_items = 20
feature_citations = true
For more info, please check #78
- erasin/hx-lsp
- metafates/buffer-language-server
- rajasegar/helix-snippets-ls
- quantonganh/snippets-ls
- Stanislav-Lapata/snippets-ls
- ...(please add another useful links here)
- rafamadriz/friendly-snippets
- ...(please add another useful links here)