Skip to content

Commit

Permalink
bump version to v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wlh320 committed Jan 23, 2023
1 parent cdb0253 commit 40a8303
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rime_ls"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["ZilcH40 <wlh233@live.com>"]
rust-version = "1.63"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ index a53dd2c..e51a63e 100644
添加`sync_dir: "/<existing user data dir>/sync"` 配置项,
每次 rime-ls 启动时会触发 rime 的同步.

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

## TODO

Expand All @@ -91,6 +91,7 @@ index a53dd2c..e51a63e 100644
- [x] 与 rime API 同步翻页
- [ ] 与 rime API 同步提交
- [x] 输入标点符号
- [ ] 输入方案选择
- [x] 实现更友好的触发条件
- [x] ~~计划实现光标前面有汉字就开启, 但发现不同编辑器行为不一致, 搁置~~ 多加了一次正则匹配解决了, 不知道性能如何
- [ ] 读 LSP 文档, 继续提升补全的使用体验
Expand All @@ -107,6 +108,7 @@ index a53dd2c..e51a63e 100644
- [ ] 沒有完全實現 rime 功能, 只是读取了候选项, 沒有把选到的字真正提交
(因为还没获取到补全的反馈, 计划自己处理用户输入再与 rime 交互, 感觉有点麻烦, 可能搁置)
- [ ] 第一次嘗試從 Rust 調用 C 接口,寫的非常不專業且 unsafe
- [ ] 同时开启多个共用同一个用户目录的程序时,会因为用户数据库的锁导致不工作

## Credits

Expand Down
10 changes: 5 additions & 5 deletions doc/nvim.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ local start_rime = function()
shared_data_dir = "/usr/share/rime-data", -- rime 公共目录
user_data_dir = "/home/wlh/.local/share/rime-ls", -- 指定用户目录, 最好新建一个
log_dir = "/home/wlh/.local/share/rime-ls", -- 日志目录
max_candidates = 10,
trigger_characters = {},
max_candidates = 10, -- 与 rime 的候选数量配置最好保持一致
trigger_characters = {}, -- 为空表示全局开启
},
});
vim.lsp.buf_attach_client(0, client_id)
if client_id then
vim.lsp.buf_attach_client(0, client_id)
-- 快捷键手动开启
-- old
-- before v0.1.2
-- vim.keymap.set('n', '<leader><space>', function() vim.lsp.buf.execute_command({ command = "toggle-rime" }) end)
-- new since latest git commit
-- since v0.1.2
vim.keymap.set('n', '<leader><space>', function() vim.lsp.buf.execute_command({ command = "rime-ls.toggle-rime" }) end)
vim.keymap.set('n', '<leader>rs', function() vim.lsp.buf.execute_command({ command = "rime-ls.sync-user-data" }) end)
end
end

-- 对每个文件都默认开启
vim.api.nvim_create_autocmd('BufReadPost', {
callback = function()
start_rime()
Expand Down
6 changes: 3 additions & 3 deletions doc/vim.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"shared_data_dir": "/usr/share/rime-data", // rime 公共目录
"user_data_dir": "/home/wlh/.local/share/rime-ls", // 指定用户目录,最好新建一个
"log_dir": "/home/wlh/.local/share/rime-ls", // 日志目录
"max_candidates": 10,
"trigger_characters": [],
"max_candidates": 10, // 与 rime 的候选数量配置最好保持一致
"trigger_characters": [], // 为空表示全局开启
}
},

Expand All @@ -32,7 +32,7 @@

没有完全测试过, 理论上其他 LSP 能怎么用就可以怎么用

补充: 通过 `:call CocRequest('rime-ls', 'workspace/executeCommand', { 'command': 'toggle-rime' })`
补充: 通过 `:call CocRequest('rime-ls', 'workspace/executeCommand', { 'command': 'rime-ls.toggle-rime' })`
可以手动控制开启和关闭

# TODO
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fn default_log_dir() -> PathBuf {
#[test]
fn test_default_config() {
let config: Config = Default::default();
assert_eq!(config.enabled, default_enabled());
assert_eq!(config.shared_data_dir, default_shared_data_dir());
assert_eq!(config.user_data_dir, default_user_data_dir());
assert_eq!(config.log_dir, default_log_dir());
Expand Down
2 changes: 1 addition & 1 deletion src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl InputState {
// TODO: need to parse last input again
let last_input = match self.kind {
InputKind::NoTrigger => Input::from_str(&NT_RE, &self.raw_text).unwrap(),
InputKind::Trigger => Input::from_str(&re, &self.raw_text).unwrap(),
InputKind::Trigger => Input::from_str(re, &self.raw_text).unwrap(),
};
// new typing
if self.offset != new_offset {
Expand Down
47 changes: 32 additions & 15 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,25 @@ impl Backend {
}
}

async fn notify_work_begin(&self, token: &str, message: &str) {
// register
let token = NumberOrString::String(String::from(token));
self.client
async fn create_work_done_progress(&self, token: NumberOrString) -> Result<NumberOrString> {
if let Err(e) = self
.client
.send_request::<request::WorkDoneProgressCreate>(WorkDoneProgressCreateParams {
token: token.clone(),
})
.await
.unwrap();
{
self.client.show_message(MessageType::WARNING, e).await;
return Err(tower_lsp::jsonrpc::Error::internal_error());
}
Ok(token)
}

async fn notify_work_begin(&self, token: NumberOrString, message: &str) {
// begin
self.client
.send_notification::<notification::Progress>(ProgressParams {
token: token.clone(),
token,
value: ProgressParamsValue::WorkDone(WorkDoneProgress::Begin(
WorkDoneProgressBegin {
title: message.to_string(),
Expand All @@ -108,8 +114,7 @@ impl Backend {
.await;
}

async fn notify_work_done(&self, token: &str, message: &str) {
let token = NumberOrString::String(String::from(token));
async fn notify_work_done(&self, token: NumberOrString, message: &str) {
self.client
.send_notification::<notification::Progress>(ProgressParams {
token,
Expand Down Expand Up @@ -208,7 +213,7 @@ impl Backend {
impl LanguageServer for Backend {
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
self.client
.log_message(MessageType::INFO, "Server initialized")
.log_message(MessageType::INFO, "Rime-ls Language Server initialized")
.await;

// read user configuration
Expand Down Expand Up @@ -254,7 +259,10 @@ impl LanguageServer for Backend {
all_commit_characters: None,
}),
execute_command_provider: Some(ExecuteCommandOptions {
commands: vec!["toggle-rime".to_string()],
commands: vec![
"rime-ls.toggle-rime".to_string(),
"rime-ls.sync-user-data".to_string(),
],
work_done_progress_options: WorkDoneProgressOptions {
work_done_progress: Some(true),
},
Expand Down Expand Up @@ -340,22 +348,31 @@ impl LanguageServer for Backend {
}

async fn execute_command(&self, params: ExecuteCommandParams) -> Result<Option<Value>> {
let command = params.command.as_ref();
let command: &str = params.command.as_ref();
let token = {
match params.work_done_progress_params.work_done_token {
Some(token) => token,
None => {
let token = NumberOrString::String(command.to_string());
self.create_work_done_progress(token).await?
}
}
};
match command {
"rime-ls.toggle-rime" => {
self.notify_work_begin(command, command).await;
self.notify_work_begin(token.clone(), command).await;
let mut config = self.config.write().await;
config.enabled = !config.enabled;
let status = format!("Rime is {}", if config.enabled { "ON" } else { "OFF" });
self.notify_work_done(command, &status).await;
self.notify_work_done(token.clone(), &status).await;
// return a bool representing if rime-ls is enabled
return Ok(Some(Value::from(config.enabled)));
}
"rime-ls.sync-user-data" => {
self.notify_work_begin(command, command).await;
self.notify_work_begin(token.clone(), command).await;
// TODO: do it in async way.
self.rime.sync_user_data();
self.notify_work_done(command, "Rime is Ready.").await;
self.notify_work_done(token.clone(), "Rime is Ready.").await;
}
_ => {
self.client
Expand Down

0 comments on commit 40a8303

Please sign in to comment.