impl LSP (Language Server Protocol) Server for librime

Overview

rime-ls

为 rime 输入法核心库 librime (的部分功能) 实现 LSP 协议, 从而通过编辑器的代码补全功能输入汉字.

项目还处在早期阶段, 各方面都非常不成熟.

目标是提供 rime + LSP 的通用解决方案, 在不同编辑器内实现与其他 rime 前端类似的输入体验.

Features

  • 用 rime 能输入的东西按理说都能输入 ( 汉字, 标点, emoji ...)
  • 支持按数字选择补全项
  • 支持候选词翻页
  • 多种触发方式
    • 默认开启, 随时补全, 用快捷键控制关闭 (写大量汉字)
    • 平时关闭, 检测到配置的特殊字符或光标前有非英文字符时触发补全 (写少量汉字)
  • 可以按配置其他 rime 输入法的方式去配置 (只有能影响候选项的配置是有用的)
  • 可以同步系统中已有 rime 输入法的词频
demo.mp4

Build

Ubuntu

  1. 配置 Rust 环境, 安装额外依赖 clanglibrime-dev
  2. 编译
    • librime >= 1.6 => cargo build --release
    • librime < 1.6 => cargo build --release --features=no_log_dir

ArchLinux

可以通过我在 AUR 上打的包 rime-ls 安装

其他 linux 发行版类似

Windows

  1. 配置 Rust 环境, 安装额外依赖 clanglibrime
  2. 依赖的 librime-sys 包没有针对 Windows 优化, 直接编译可能失败, 需要先下载到本地, 手动修改下 build.rs 引入头文件. 例如,
diff --git a/build.rs b/build.rs
index a53dd2c..e51a63e 100644
--- a/build.rs
+++ b/build.rs
@@ -11,6 +11,7 @@ fn main() {

     let bindings = bindgen::Builder::default()
         .header("wrapper.h")
+        .clang_arg("-IC:\\Users\\wlh\\Downloads\\rime-1.7.3-win32\\dist\\include")
         .generate()
         .expect("Unable to generate bindings");
  1. 修改本项目的 Cargo.toml 指向本地的依赖
  2. i686 的 target 编译 (因为 librime 只给了 32 位的 dll)

Usage

Warning 第一次启动时 rime 需要做大量工作, 可能会很慢

  1. 将编译好的二进制文件放在喜欢的目录下
  2. 配置 LSP 客戶端, 例如:
  3. 默认輸入拼音, 就可以看到补全提示
  4. 可以通过改变配置控制补全行为

个人词库同步

Warning 不推荐与系统中的已有 rime 输入法共用一个用户目录, 免得出什么问题

使用前备份自己的数据, 避免因作者对 rime API 理解不到位可能造成的数据损失

目前 rime-ls 还不能拿到补全的反馈, 向 rime 提交选择的汉字, 所以自身的用户词库总是空的. 但可以通过 rime 的 sync 功能将系统中已安装的 rime 输入法的词库同步过来.

如需同步词库, 可以在 rime-ls 自己的用户目录下的 installation.yaml 添加sync_dir: "/<existing user data dir>/sync" 配置项, 每次 rime-ls 启动时会触发 rime 的同步.

也可以通過 LSP 的 workspace/executeCommand 手動調用 rime-ls.sync_user_data 的命令同步 (since v0.1.2)

TODO

  • 實現更多 librime 的功能
    • 按数字键选择候选项
    • 与 rime API 同步翻页
    • 与 rime API 同步提交
    • 输入标点符号
    • 输入方案选择
  • 实现更友好的触发条件
    • 计划实现光标前面有汉字就开启, 但发现不同编辑器行为不一致, 搁置 多加了一次正则匹配解决了, 不知道性能如何
  • 读 LSP 文档, 继续提升补全的使用体验
  • 參數可配置 (用户目录, 触发条件, 候选数量)
  • 實現一個更好的 librime 的 rust wrapper 庫
  • 測試其他 LSP clients
  • 测试不同操作系统和 librime 版本
  • 测试与不同 rime 配置的兼容性

Known Issues

  • 補全的觸發條件很奇怪,現在我是手動觸發補全寫的這些字 解决, 要设置 is_incomplete 来连续补全
  • 還沒完成開始這個項目的最初目的, 即直接復用 rime 配置 直接设置不同的用户目录好像可以, 比如我现在可以写简体了, 还需要进一步测试
  • 沒有完全實現 rime 功能, 只是读取了候选项, 沒有把选到的字真正提交 (因为还没获取到补全的反馈, 计划自己处理用户输入再与 rime 交互, 感觉有点麻烦, 可能搁置)
  • 第一次嘗試從 Rust 調用 C 接口,寫的非常不專業且 unsafe
  • 同时开启多个共用同一个用户目录的程序时,会因为用户数据库的锁导致不工作

Credits

受到以下項目啓發

You might also like...
Experimental treesiter based language server, let's see how far this goes 😆.

tsls Tree-sitter based language server for general languages. Warning: It's in active development right now, and bug is expected. Features Go To Defin

A brand-new language server for Typst, plus a VS Code extension

Typst LSP A brand-new language server for Typst. Features Syntax highlighting, error reporting, code completion, and function signature help Compiles

Rust language support in Atom - LOOKING FOR MAINTAINER, see #144

Rust language support in Atom Adds syntax highlighting and snippets to Rust files in Atom. Install Install the package language-rust in Atom (Preferen

RustDT is an Eclipse based IDE for the Rust programming language:
RustDT is an Eclipse based IDE for the Rust programming language:

Project website: http://rustdt.github.io/ As of 2017, RustDT is no longer actively maintained, see this blog post for more information. If you are int

The official Sublime Text 3 package for the Rust Programming Language
The official Sublime Text 3 package for the Rust Programming Language

Rust Enhanced About This is a Sublime Text 3 package which supports Rust starting with version 1.0, it makes no attempt at supporting earlier incompat

rust-analyzer is a modular compiler frontend for the Rust language
rust-analyzer is a modular compiler frontend for the Rust language

rust-analyzer is a modular compiler frontend for the Rust language. It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust.

AIDL Language Server Protocol (LSP) server

AIDL Language Server Protocol (LSP) server Experimental AIDL LSP server based on rust-aidl-parser. Features: diagnostics workspace symbols (Ctrl+T in

A LSP (Language Server Protocol) server for OpenSCAD.

openscad-LSP A LSP (Language Server Protocol) server for OpenSCAD. inspired by dzhu/openscad-language-server Tested with VSCode on Mac and Windows. Te

Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

Language Server Protocol (LSP) support for vim and neovim.
Language Server Protocol (LSP) support for vim and neovim.

For legacy python implementation, see branch master. LanguageClient-neovim Language Server Protocol support for vim and neovim. More recordings at Upd

Fennel language server protocol (LSP) support.

fennel-language-server Fennel language server protocol (LSP) support. fennel-language-server is currently in a very early stage and unreliable. Use it

Todo-server impl by using actix.rs

Todo-Server Todo-server impl by using actix.rs Why actix.rs 1. It's blazing fast Benchmark From now on, Actix is the second fastest web framework in t

Erlang Language Platform. LSP server and CLI.
Erlang Language Platform. LSP server and CLI.

Erlang Language Platform (ELP) Description ELP integrates Erlang into modern IDEs via the language server protocol. ELP was inspired by rust-analyzer.

my attempt at compromise between unwrapping and bullying my dependencies' authors for Error impl

string-eyre Has this happened to you? error[E0599]: the method `wrap_err` exists for enum `Result(), tauri::Error`, but its trait bounds were not sa

Decode SCALE bytes into custom types using a scale-info type registry and a custom Visitor impl.

scale-decode This crate attempts to simplify the process of decoding SCALE encoded bytes into a custom data structure given a type registry (from scal

Fills an `impl` with the associated items required by the trait.

portrait Fill impl-trait blocks with default, delegation and more. Motivation Rust traits support provided methods, which are great for backwards comp

Markdown LSP server for easy note-taking with cross-references and diagnostics.
Markdown LSP server for easy note-taking with cross-references and diagnostics.

Zeta Note is a language server that helps you write and manage notes. The primary focus is to support Zettelkasten-like1, 2 note taking by providing an easy way to cross-reference notes (see more about features below).

Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo workspace

ra-multiplex   Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo wor

lsp server for finding ES statements that throw!
lsp server for finding ES statements that throw!

Well, Does it Throw? TLDR; This is a blazingly fast lsp server to find throw statements in your javascript code. It's written in Rust and based on SWC

Comments
  • rust编译出错 v0.1.0

    rust编译出错 v0.1.0

    发行版: Debian testing clang: 14.0.6 cargo: 1.65.0 librime-dev: 1.7.3 rime-ls: 0.1.0 编译命令: cargo build --release

    编译报错 输出:

    Updating crates.io index
        Updating git repository `https://github.com/lotem/librime-sys`
       Compiling proc-macro2 v1.0.50
       Compiling quote v1.0.23
       Compiling unicode-ident v1.0.6
       Compiling syn v1.0.107
       Compiling libc v0.2.139
       Compiling version_check v0.9.4
       Compiling autocfg v1.1.0
       Compiling memchr v2.5.0
       Compiling futures-core v0.3.25
       Compiling glob v0.3.1
       Compiling cfg-if v1.0.0
       Compiling pin-project-lite v0.2.9
       Compiling serde_derive v1.0.152
       Compiling log v0.4.17
       Compiling futures-task v0.3.25
       Compiling tinyvec_macros v0.1.0
       Compiling serde v1.0.152
       Compiling futures-channel v0.3.25
       Compiling unicode-width v0.1.10
       Compiling futures-sink v0.3.25
       Compiling regex-syntax v0.6.28
       Compiling textwrap v0.11.0
       Compiling tinyvec v1.6.0
       Compiling libloading v0.7.4
       Compiling nom v5.1.2
       Compiling proc-macro-error-attr v1.0.4
       Compiling termcolor v1.2.0
       Compiling slab v0.4.7
       Compiling futures-util v0.3.25
       Compiling clang-sys v1.4.0
       Compiling bitflags v1.3.2
       Compiling bindgen v0.57.0
       Compiling strsim v0.8.0
       Compiling once_cell v1.17.0
       Compiling vec_map v0.8.2
       Compiling humantime v2.1.0
       Compiling ansi_term v0.12.1
       Compiling aho-corasick v0.7.20
       Compiling tokio v1.24.2
       Compiling lock_api v0.4.9
       Compiling proc-macro-error v1.0.4
       Compiling rustc-hash v1.1.0
       Compiling lazycell v1.3.0
       Compiling smallvec v1.10.0
       Compiling atty v0.2.14
       Compiling unicode-normalization v0.1.22
       Compiling which v3.1.1
       Compiling clap v2.34.0
       Compiling futures-io v0.3.25
       Compiling parking_lot_core v0.9.6
       Compiling unicode-bidi v0.3.9
       Compiling lazy_static v1.4.0
       Compiling shlex v0.1.1
       Compiling peeking_take_while v0.1.2
       Compiling pin-utils v0.1.0
       Compiling serde_json v1.0.91
       Compiling percent-encoding v2.2.0
       Compiling form_urlencoded v1.1.0
       Compiling num_cpus v1.15.0
       Compiling tracing-core v0.1.30
       Compiling scopeguard v1.1.0
       Compiling ryu v1.0.12
       Compiling bytes v1.3.0
       Compiling idna v0.3.0
       Compiling async-trait v0.1.61
       Compiling itoa v1.0.5
       Compiling httparse v1.8.0
       Compiling tracing v0.1.37
       Compiling tower-layer v0.3.2
       Compiling tower-service v0.3.2
       Compiling hashbrown v0.12.3
       Compiling dirs-sys v0.3.7
       Compiling regex v1.7.1
       Compiling cexpr v0.4.0
       Compiling str_indices v0.4.1
       Compiling dashmap v5.4.0
       Compiling directories v4.0.1
       Compiling ropey v1.5.1
       Compiling env_logger v0.8.4
       Compiling futures-macro v0.3.25
       Compiling pin-project-internal v1.0.12
       Compiling tokio-macros v1.8.2
       Compiling serde_repr v0.1.10
       Compiling auto_impl v0.5.0
       Compiling tower-lsp-macros v0.6.0
       Compiling pin-project v1.0.12
       Compiling librime-sys v0.1.0 (https://github.com/lotem/librime-sys#094db695)
       Compiling tokio-util v0.7.4
       Compiling futures v0.3.25
       Compiling tower v0.4.13
       Compiling url v2.3.1
       Compiling lsp-types v0.93.2
       Compiling tower-lsp v0.17.0
       Compiling rime_ls v0.1.0 (/home/yaowj/.local/share/nvim/lazy/rime-ls)
    error[E0658]: `let...else` statements are unstable
      --> src/lsp.rs:68:9
       |
    68 | /         let Ok(settings) = serde_json::from_value::<Settings>(params) else {
    69 | |             return ;
    70 | |         };
       | |__________^
       |
       = note: see issue #87335 <https://github.com/rust-lang/rust/issues/87335> for more information
    
    For more information about this error, try `rustc --explain E0658`.
    error: could not compile `rime_ls` due to previous error
    warning: build failed, waiting for other jobs to finish...
    
    opened by yao-weijie 7
Releases(v0.1.2)
  • v0.1.2(Jan 23, 2023)

    rime-ls v0.1.1

    Breaking Changes

    • execute_command 所支持的命令的名称都增加了 rime-ls. 的前缀

    Fix

    • 修复了因更新位置在边界处导致的 LSP server 不能同步更新文档内容的问题

    Feat

    • 现在可以通过命令手动触发用户目录同步
    • 执行 rime-ls.toggle-rime 命令后会返回执行后的当前状态

    tested on Linux / Windows with neovim / vim / vscode

    $ sha256sum rime_ls.exe c7344a53777eb89411275701f522475343dc6c95df79ef17453c5882969c3ef4 rime_ls.exe

    Source code(tar.gz)
    Source code(zip)
    rime-ls-0.1.2-win32.zip(1.28 MB)
  • v0.1.1(Jan 20, 2023)

    rime-ls v0.1.1

    Fix

    • 全局模式下,补全时会删掉拼音前未提交的标点符号

    Feat

    • 触发模式下,光标前有非英文字符时可以自动触发补全继续输入

    tested on Linux / Windows with neovim / vim / vscode

    $ sha256sum rime_ls.exe 86690591b81e657010e7c3bc1fc52f18e461dbc978aeb11625490e50cf44634e rime_ls.exe

    Source code(tar.gz)
    Source code(zip)
    rime-ls-0.1.1-win32.zip(1.28 MB)
  • v0.1.0(Jan 18, 2023)

Owner
zilch40
𝙃𝙤𝙬 ℑ Learned to 𝕊𝕥𝕠𝕡 Worrying and 𝓛𝓸𝓿𝓮 𝚌𝚘𝚍𝚎();
zilch40
A LSP (Language Server Protocol) server for OpenSCAD.

openscad-LSP A LSP (Language Server Protocol) server for OpenSCAD. inspired by dzhu/openscad-language-server Tested with VSCode on Mac and Windows. Te

Leathong 20 Dec 15, 2022
Language Server Protocol (LSP) support for vim and neovim.

For legacy python implementation, see branch master. LanguageClient-neovim Language Server Protocol support for vim and neovim. More recordings at Upd

Junfeng Li 3.5k Dec 29, 2022
Fennel language server protocol (LSP) support.

fennel-language-server Fennel language server protocol (LSP) support. fennel-language-server is currently in a very early stage and unreliable. Use it

null 68 Dec 27, 2022
LSP inline hints for Lua, intended for use with Neovim.

luahint LSP inline hints for Lua, intended for use with Neovim. Now that inline hints are working in Neovim nightly, I figured I'd attempt to build an

Will Hopkins 15 Jun 15, 2023
Kakoune Language Server Protocol Client

Kakoune Language Server Protocol Client kak-lsp is a Language Server Protocol client for Kakoune implemented in Rust. Installation Note kak-lsp.toml d

null 495 Dec 17, 2022
WIP: Asynchronous Language Server Protocol framework

async-lsp Asynchronous Language Server Protocol (LSP) framework based on tower. ⚠️ This project serves as a proof-of-concept for LSP with middlewares

null 9 Apr 11, 2023
IDE tools for writing pest grammars, using the Language Server Protocol for Visual Studio Code, Vim and other editors

Pest IDE Tools IDE support for Pest, via the LSP. This repository contains an implementation of the Language Server Protocol in Rust, for the Pest par

pest 20 Apr 8, 2023
Rust IDE support for Atom, powered by the Rust Language Server (RLS)

IDE-Rust Rust language support for Atom-IDE, powered by rust-analyzer. Features Auto-completion Diagnostics (errors and warnings from rustc) Document

The Rust Programming Language 239 Dec 14, 2022
An experimental proofreading and linting language server for markdown files ✍️

prosemd is an experimental proofreading and linting language server for markdown files. It aims to provide helpful and smart diagnostics when writing

Phil Pluckthun 132 Dec 14, 2022
Repository for the Rust Language Server (aka RLS)

Rust Language Server (RLS) The RLS provides a server that runs in the background, providing IDEs, editors, and other tools with information about Rust

The Rust Programming Language 3.6k Dec 30, 2022