https://github.com/estin/simple-completion-language-server
Language server to enable word completion and snippets for Helix editor
https://github.com/estin/simple-completion-language-server
completion helix language-server language-server-protocol snippets
Last synced: about 1 month ago
JSON representation
Language server to enable word completion and snippets for Helix editor
- Host: GitHub
- URL: https://github.com/estin/simple-completion-language-server
- Owner: estin
- License: mit
- Created: 2023-06-14T09:54:13.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T06:22:20.000Z (over 1 year ago)
- Last Synced: 2024-10-31T22:33:05.608Z (over 1 year ago)
- Topics: completion, helix, language-server, language-server-protocol, snippets
- Language: Rust
- Homepage:
- Size: 238 KB
- Stars: 216
- Watchers: 6
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
https://github.com/estin/simple-completion-language-server/assets/520814/10566ad4-d6d1-475b-8561-2e909be0f875
Based on [comment](https://github.com/helix-editor/helix/pull/3328#issuecomment-1559031060)
### Install
#### From source
From GitHub:
```console
$ cargo install --locked --git https://github.com/estin/simple-completion-language-server.git
```
From local repository:
```console
$ git clone https://github.com/estin/simple-completion-language-server.git
$ cd simple-completion-language-server
$ cargo install --locked --path .
```
#### Nix
You can install `simple-completion-language-server` using the [nix package manager](https://nixos.org/) from [nixpkgs](https://search.nixos.org/packages?channel=unstable&show=simple-completion-language-server&from=0&size=50&sort=relevance&type=packages&query=simple-comple).
> [!NOTE]
> At the moment the package is only available on the [unstable](https://nixos.org/manual/nixpkgs/unstable/#overview-of-nixpkgs) channel of nixpkgs.
```console
# 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](https://nixos.wiki/wiki/Flakes).
If you are on [NixOS](https://nixos.org/) or are using [home-manager](https://nix-community.github.io/home-manager/) you can do one of the following:
```nix
# 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];
```
### Configure
For Helix on `~/.config/helix/languages.toml`
```toml
# introduce new language server
[language-server.scls]
command = "simple-completion-language-server"
[language-server.scls.config]
feature_words = false # 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" ]
```
### Snippets
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][1]), 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
```toml
[[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"
```
### Use external snippets collections from git repos
Configure sources in `~/.config/helix/external-snippets.toml` (or via env `EXTERNAL_SNIPPETS_CONFIG`)
1. Declare list of sources by key `[[sources]]`
2. 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](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) 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.
3. Run commands to fetch and validate snippets
```console
# Clone or update snippets source repos to `~/.config/helix/external-snippets/`
simple-completion-language-server fetch-external-snippets
# Try to find and parse snippets
simple-completion-language-server validate-snippets
```
#### Config format for external snippets
```toml
# 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"
```
#### Example
Load python snippets from file https://github.com/rafamadriz/friendly-snippets/blob/main/snippets/python/python.json
File `~/.config/helix/external-snippets.toml`
```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/`
```console
$ simple-completion-language-server fetch-external-snippets
```
Validate snippets
```console
$ simple-completion-language-server validate-snippets
```
### Unicode input
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`
```toml
alpha = "α"
betta = "β"
gamma = "γ"
fire = "🔥"
```
Validate unicode input config
```console
$ simple-completion-language-server validate-unicode-input
```
### Citation completion
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.
```console
$ cargo install --features citation --git https://github.com/estin/simple-completion-language-server.git
```
And initialize scls with `feature_citations = true`.
```toml
[language-server.scls.config]
feature_citations = true
```
For more info, please check https://github.com/estin/simple-completion-language-server/issues/78
### Similar projects
- [erasin/hx-lsp](https://github.com/erasin/hx-lsp)
- [metafates/buffer-language-server](https://github.com/metafates/buffer-language-server)
- [rajasegar/helix-snippets-ls](https://github.com/rajasegar/helix-snippets-ls)
- [quantonganh/snippets-ls](https://github.com/quantonganh/snippets-ls)
- [Stanislav-Lapata/snippets-ls](https://github.com/Stanislav-Lapata/snippets-ls)
- ...(please add another useful links here)
### Useful snippets collections
- [rafamadriz/friendly-snippets](https://github.com/rafamadriz/friendly-snippets)
- ...(please add another useful links here)
[1]: "Known language identifiers"