< 返回版块

erasin 发表于 2024-04-18 17:27

Tags:helix,editor

hx-lsp

一个提供了自定义代码片段 snippets 和 Code Action 的 lsp 工具。

提供了基本的功能,还在改进中,欢迎提供 pr。

功能

  • Completion: snippets
  • CodeAction: actions

安装

git clone https://github.com/erasin/hx-lsp.git
cd hx-lsp
cargo install --path .

https://github.com/erasin/helix-config/ 中有示例代码,另外我自己使用的分支已经合并了 helix#9081 Add a snippet system

使用

修改 helix 的语言配置文件 languages.toml, 修改下面文件任何一个即可

  • $XDG_CONFIG_HOME/helix/languages.toml helix 配置文件
  • WORKSPACE_ROOT/.helix/languages.toml 项目下配置文件

比如为 markdown 追加支持。

[language-server.hx-lsp]
command = "hx-lsp"

[[language]]
name = "markdown"
language-servers = [ "marksman", "markdown-oxide", "hx-lsp" ]

关于 language id 建议参考 helix/languages.toml 文件和 helix wiki language server configurations

配置文件

配置文件支持 jsonc 格式,即支持注释内容,但不支持多余的 ,

注释样式支持 // ..., /* ... */, # ...

Snippets 文件加载路径

  • $XDG_CONFIG_HOME/helix/snippets/
  • WORKSPACE_ROOT/.helix/snippets/

Actions 配置加载路径

  • $XDG_CONFIG_HOME/helix/actions/
  • WORKSPACE_ROOT/.helix/actions/

配置在 textDocument/didOpen 时候加载 language id 同名 lang_id.json 文件。

暂不支持配置文件的动态加载,修改配置文件后,可以使用 :lsp-restart 重启来重新加载文件。

Completion: snippets

Code snippets 兼容 vscode snippets 格式。同样文件后缀支持 全局后缀.code-snippets 和 语言包后缀.json

为了更好的使用 snippet 建议 heliix 合并 helix#9081 Add a snippet system 以支持 smart-tab。

.
└── snippets
    ├── global.code-snippets
    ├── html.json
    └── markdown.json

snipet 格式:

  • name: String 唯一内容,用于索引
  • prefix: StringVec<String> 提供给 helix 编辑器的补全列表使用
  • body: StringVec<String>
  • description: Option<String> 提示内容
{
  "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

snipet 格式:

  • title: String helix 显示条目内容
  • catch: String 捕捉内容,regex 适配内容的时候,显示 code action
  • shell: StringVec<String> 执行的 shell 脚本
  • description: Option<String> 提示内容
{
  "tmux split window helix": {
    "title": "tmux split window in project",
    "catch": "fn",
    "shell": [
      "tmux split-window -h",
      "tmux send project"
    ],
    "description": "tmux split and open helix in project"
  }
}

Ext Link: https://github.com/erasin/hx-lsp

评论区

写评论

还没有评论

1 共 0 条评论, 1 页