wlh320 / rime-ls

A language server for Rime input method engine 通过 LSP 代码补全使用 Rime 输入法
BSD 3-Clause "New" or "Revised" License
182 stars 11 forks source link

输入标点符号和左括号后 rime_ls 失效 #31

Open liubianshi opened 1 month ago

liubianshi commented 1 month ago

输入标点符号,如 *! 后,rime_ls 能正常提供候选词,输入 [{ 后 rime_ls 也正常,但先输入标点符号再输入括号后,rime_ls 不再能提供候选词。表现如下面这段录屏:

https://github.com/user-attachments/assets/1b4afc51-8e95-41f9-a2a2-7288895ab99d

这对日常使用不会带来困扰,只是可能会影响 markdown 的图片插入语法 ![]()

使用配置只是对示例配置做了些许修改:

_shared_data_dir = "/usr/share/rime-data"
local rime_user_dir = "~/.local/share/rime-ls"

local M = {}

function M.setup_rime()
  -- global status
  vim.g.rime_enabled = false

  local lspconfig = require('lspconfig')
  local configs = require('lspconfig.configs')
  if not configs.rime_ls then
    configs.rime_ls = {
      default_config = {
        name = "rime_ls",
        cmd = vim.lsp.rpc.connect('127.0.0.1', 9257),
        filetypes = { '*' },
        single_file_support = true,
      },
      settings = {},
      docs = {
        description = [[
https://www.github.com/wlh320/rime-ls

A language server for librime
]],
      }
    }
  end

  local rime_on_attach = function(client, _)
    local toggle_rime = function()
      client.request('workspace/executeCommand',
        { command = "rime-ls.toggle-rime" },
        function(_, result, ctx, _)
          if ctx.client_id == client.id then
            vim.g.rime_enabled = result
          end
        end
      )
    end
    -- keymaps for executing command
    vim.keymap.set('i', ';f', function() toggle_rime() end)
    vim.keymap.set('i', '<C-x>', function() toggle_rime() end)
    vim.keymap.set('n', '<leader>rs', function() vim.lsp.buf.execute_command({ command = "rime-ls.sync-user-data" }) end)
  end

  -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
  local capabilities = vim.lsp.protocol.make_client_capabilities()
  capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)

  lspconfig.rime_ls.setup {
    init_options = {
      enabled = vim.g.rime_enabled,
      shared_data_dir = rime_shared_data_dir,
      user_data_dir = rime_user_dir,
      log_dir = rime_user_dir,
      max_candidates = 9,
      trigger_characters = {},
      schema_trigger_character = "&" -- [since v0.2.0] 当输入此字符串时请求补全会触发 “方案选单”
    },
    on_attach = rime_on_attach,
    capabilities = capabilities,
  }
end

return M
liubianshi commented 1 month ago

rime_ls 版本是最新版(bd728eeb) 系统环境是 arch linux

wlh320 commented 1 month ago

印象中确实有这个问题。最近有事,过段时间我再仔细查一下

wlh320 commented 4 weeks ago

初步测试是当第二个符号不能直接上屏的时候会出这个问题。 似乎是跟我判断补全的开始位置的那部分代码有关。如果在 rime 配置里让所有符号都直接上屏,就没这个问题。

等我有空再从头捋一下补全的逻辑,看看有没有更好的判断方案。