3 releases
0.1.2 | Jul 10, 2024 |
---|---|
0.1.1 | Jul 7, 2024 |
0.1.0 | May 17, 2024 |
#122 in Text editors
73KB
1.5K
SLoC
hx-lsp
An LSP tool that provides custom code snippets and Code Actions for Helix Editor.
features
- Completion: snippets
- CodeAction: actions
Install
From crate
cargo install --force hx-lsp
From source
git clone https://github.com/erasin/hx-lsp.git
cd hx-lsp
cargo install --path .
Use
Modify the language configuration file languages.toml
for Helix Editor.
$XDG_CONFIG_HOME/helix/languages.toml
: Helix Configuration file.WORKSPACE_ROOT/.helix/languages.toml
: Configuration file under project workspace root.
About 'WORKSPACE_ROOT', It is read the 'rootPath' from the 'initialize' provided by Helix, when there are multiple levels of rootPath(
language.roots
of languages.toml), It will read the closest of root '.helix'.
Example, Add support for markdown.
[language-server.hx-lsp]
command = "hx-lsp"
[[language]]
name = "markdown"
language-servers = [ "marksman", "markdown-oxide", "hx-lsp" ]
About
language id
, Read helix/languages.toml and helix wiki language server configurations。
Configuration
The Configuration file supports the jsonc
format.
Comment style:
// ...
,/* ... */
,# ...
。
Snippets file loading path:
$XDG_CONFIG_HOME/helix/snippets/
WORKSPACE_ROOT/.helix/snippets/
Actions file loading path:
$XDG_CONFIG_HOME/helix/actions/
WORKSPACE_ROOT/.helix/actions/
In LSP textDocument/didOpen
request, The Configuration file with name that is language_id.json
will be loading.
Unsupported Dynamic loading config. If you modify configuration file, use
:lsp-restart
to restart lsp and reload the file.
Completion: snippets
Code Snippets support vscode snippets format. The same file suffix supports global suffixes such as. code-snippets
and language pack suffixes such as. json
.
For better use snippet completion, Use helix master and merge helix#9081 Add a snippet system to support smart-tab。
.
└── snippets
├── global.code-snippets
├── html.json
└── markdown.json
Snippet Format:
- name:
String
, index - prefix:
String
OrVec<String>
, editor completion item - body:
String
OrVec<String>
, snippet connent - description:
Option<String>
, Tip
{
"markdown a": {
// name
"prefix": "mda", // string
"body": "mda in .helix: ${1:abc} : ${2:cde}", // string
"description": "test a info content in .helix",
},
"markdown b": {
"prefix": [
// array
"mdb",
],
"body": "mdb: ${1:abc} : ${2:cde}", // string
"description": "test b info content",
},
"markdown c": {
"prefix": [
// array
"mdc",
"mdd",
],
"body": [
// array
"mda: ${1:abc} : ${2:cde}",
"test",
],
"description": "test c,d info content",
},
}
CodeAction: actions
.
└── actions
├── html.json
└── markdown.json
Snippet Formatter:
- title:
String
helix editor show Code Action Item - catch:
String
catch line content,regex ,code action - shell:
String
OrVec<String>
, take shell script - description:
Option<String>
Tip content
/* actions/go.json */
{
"run main": {
"title": "go run main",
"catch": "func main",
"shell": [
"alacritty --hold --working-directory ${TM_DIRECTORY} -e go run ${TM_FILENAME}"
],
"description": "go run main"
},
"run main in tmux": {
"title": "tmux: go run main",
"catch": "func main",
"shell": [
"tmux split-window -h -c ${WORKSPACE_FOLDER};",
"tmux send 'go build' Enter"
],
"description": "go run main"
}
}
/* test */
{
"tmux split window helix": {
"title": "tmux split window in project",
"catch": "fn",
"shell": [
"tmux split-window -h",
"tmux send \"cd ${WORKSPACE_FOLDER}\n\""
],
"description": "tmux split and open helix in project"
}
}
catch:
- regex line
- selected content
- match in regex
Variables
Support variable for snippet body and action shell.
Support like $UUID
和 ${UUID}
。
path
-
TM_SELECTED_TEXT
-
TM_CURRENT_LINE
-
TM_CURRENT_WORD
-
TM_LINE_INDEX
-
TM_LINE_NUMBER
-
TM_FILENAME
-
TM_FILENAME_BASE
-
TM_DIRECTORY
-
TM_FILEPATH
-
RELATIVE_FILEPATH
-
CLIPBOARD
-
WORKSPACE_NAME
-
WORKSPACE_FOLDER
time
-
CURRENT_YEAR
-
CURRENT_YEAR_SHORT
-
CURRENT_MONTH
-
CURRENT_MONTH_NAME
-
CURRENT_MONTH_NAME_SHORT
-
CURRENT_DATE
-
CURRENT_DAY_NAME
-
CURRENT_DAY_NAME_SHORT
-
CURRENT_HOUR
-
CURRENT_MINUTE
-
CURRENT_SECOND
-
CURRENT_SECONDS_UNIX
-
CURRENT_TIMEZONE_OFFSET
other
-
RANDOM
-
RANDOM_HEX
-
UUID
action catch
-
CATCH1..9
Dependencies
~14–27MB
~406K SLoC