typst-lsp icon indicating copy to clipboard operation
typst-lsp copied to clipboard

LSP Exits On Editing CJK Characters

Open lace-wing opened this issue 2 years ago • 7 comments

  • editor: neovim
  • LSP Plugins: nvim-cmp, lspconfig, mason, mason-lspconfig
  • LSP version: 0.9.5
  • OS version and name: macOS 13.5.1
  • I am on the latest stable version of the extension/LSP.
  • I have searched the issues of this repo and believe that this is not a duplicate.

Issue

LSP exits on editing Chinese/Japanese/Korean characters.

Reproduction

  1. open a .typ file with typst_lsp attached to the buffer
  2. do nothing, lsp stays calm
  3. enter some English, lsp works fine
  4. enter, delete a CJK character, or enter insert mode on it, lsp exists

Note that this error may need a few attempts of step 4 to reproduce, but it would be very common in a context of editing CJK contents. Restarting lsp or neovim did not help.

I have not tested other languages, they might be bugged as well.

Logs

Logs are the same for errors on C, J and K chars.

[START][2023-08-30 23:03:10] LSP logging initiated
[WARN][2023-08-30 23:03:10] ...lsp/handlers.lua:137	"The language server typst_lsp triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2023-08-30 23:03:21] .../vim/lsp/rpc.lua:734	"rpc"	"/Users/steve/.local/share/nvim/mason/bin/typst-lsp"	"stderr"	"thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/lsp_typst_boundary.rs:97:58\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"

This bug completely defeats CJK editing in typst, so help or fix is needed ASAP.

lace-wing avatar Aug 30 '23 15:08 lace-wing

Current workaround using vscode built-in workspace task and typst watch file.typ:

"tasks": {
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Typst - 编译当前文件",
        "type": "shell",
        "command": "typst",
        "args": [
          "compile",
          "${fileBasename}",
          "${fileBasenameNoExtension}.pdf"
        ],
        "group": "build",
        "presentation": {
          "reveal": "always"
        },
        "options": {
          "cwd": "${fileDirname}"
        },
        "problemMatcher":{
          "owner": "typst",
          "fileLocation":"absolute",
          "pattern":[
            {
              "regexp": "^(error|info|hint|warning):\\s(.*:\\s.*)",
              "message": 2,
              "severity": 1,
            },
            {
              "regexp": "(?:\\s+┌─\\s\\\\+\\?\\\\)(\\w:.*):(\\d+):(\\d+)",
              "file": 1,
              "line": 2,
              "column": 3
            }
          ]
        }
      },
      {
        "label": "Typst - 实时增量编译当前文件",
        "type": "shell",
        "command": "typst",
        "isBackground": true,
        "args": [
          "watch",
          "${fileBasename}"
        ],
        "group": {
          "kind": "test",
          "isDefault": true
        },
        "presentation": {
          "reveal": "silent"
        },
        "options": {
          "cwd": "${fileDirname}"
        },
        "problemMatcher": {
          "owner": "typst",
          "fileLocation": "absolute",
          "pattern": [
            {
              "regexp": "^(error|info|hint|warning):\\s(.*:\\s.*)",
              "message": 2,
              "severity": 1,
            },
            {
              "regexp": "(?:\\s+┌─\\s\\\\+\\?\\\\)(\\w:.*):(\\d+):(\\d+)",
              "file": 1,
              "line": 2,
              "column": 3
            }
          ],
          "background": {
            "activeOnStart": true,
            "beginsPattern": "^\\[\\d+:\\d+:\\d+\\]\\scompiled.*",
            "endsPattern": "\\s+│.*\\^+$"
          }
        }
      }
    ]
  }

KagaJiankui avatar Aug 31 '23 00:08 KagaJiankui

@lyc-Lacewing are there any more LSP logs, particularly logs from when the language server was initializing? This is likely an encoding issue, and the encoding is decided at initialization.

nvarner avatar Aug 31 '23 02:08 nvarner

@lyc-Lacewing are there any more LSP logs, particularly logs from when the language server was initializing? This is likely an encoding issue, and the encoding is decided at initialization.

The log was obtained by :LspLog, which opens ~/.local/state/nvim/lsp.log. At the first line you can see [START], which is when I executed :LspStart, and lsp logging started from there. Please tell me if you know other locations.

lace-wing avatar Aug 31 '23 04:08 lace-wing

And thanks, KagaJiankui, but I'm using neovim.

lace-wing avatar Aug 31 '23 04:08 lace-wing

And thanks, KagaJiankui, but I'm using neovim.

Typst supports typst watch file.typ out.pdf, and the CLI output can be configured via CLI options(you may use typst watch --help). You can use LuaSnip to make an workaround.

KagaJiankui avatar Aug 31 '23 23:08 KagaJiankui

Typst supports typst watch file.typ out.pdf, and the CLI output can be configured via CLI options(you may use typst watch --help). You can use LuaSnip to make an workaround.

Didn't know LuaSnip can do that, thanks again! However this approach does not enable LSP features, so a fix is still needed.

lace-wing avatar Sep 01 '23 09:09 lace-wing

Update: the bug can be triggered by placing cursor on a CJK char, not even editing.

lace-wing avatar Sep 04 '23 12:09 lace-wing