chomosuke / typst-preview.nvim

Low latency typst preview for Neovim
GNU General Public License v3.0
255 stars 16 forks source link

Error in TypstPreview when writing in non-latin script #38

Open pacaunt opened 3 months ago

pacaunt commented 3 months ago

After running the command TypstPreview the system said:

Error executing vim.schedule lua callback: ...typst-preview.nvim/lua/typst-preview/servers/factory.
lua:166: attempt to perform arithmetic on local 's' (a nil value)
stack traceback:
        ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

with a multiple stack of

Error executing vim.schedule lua callback: Vim:E474: Unidentified byte: <9a>การเกิดปฏิกิริยาเคมี","span"
:"1a00000018","position":{"page_no":165,"x":75.0,"y":70.0},"children":[]}]},{"title":"กลไกการเกิดปฏิกิ
ริยา","span":"1a00000018","position":{"page_no":166,"x":0.0,"y":0.0},"children":[{"title":"ปฏิกิริยาอาจ
มีขั้นตอน","span":"1a00000018","position":{"page_no":167,"x":75.0,"y":70.0},"children":[]},{"title":"ตั
วอย่างปฏิกิริยา","span":"1a00000018","position":{"page_no":174,"x":75.0,"y":70.0},"children":[]},{"titl
e":"ตัวอย่างปฏิกิริยา","span":"1a00000018","position":{"page_no":177,"x":75.0,"y":70.0},"children":[]},{
"title":"ตัวอย่างปฏิกิริยา","span":"1a00000018","position":{"page_no":178,"x":75.0,"y":70.0},"children":
[]},{"title":"พลังงานกับกลไกการเกิดปฏิกิริยาเคมี","span":"1
stack traceback:
        [C]: in function 'json_decode'
        ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

How I can solve this ?

pacaunt commented 3 months ago

Here is my source code

ChemicalKinetics.zip

chomosuke commented 3 months ago

Hmmm, interestingly I did not manage to reproduce your issue but it looked like it is a vim.fn.json_decode. I've switched to the lua version vim.json.decode and I'd appreciate it if you can test this out to see if it fixed your problem.

pacaunt commented 3 months ago

I tried changing the function according to your git commit and the following error messages appeared:

Error executing vim.schedule lua callback: ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: attempt to perfo
rm arithmetic on local 's' (a nil value)
stack traceback:
        ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue
Error executing vim.schedule lua callback: ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: Expected value b
ut found invalid token at character 1
stack traceback:
        [C]: in function 'decode'
        ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue
Error executing vim.schedule lua callback: ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: attempt to perfo
rm arithmetic on local 's' (a nil value)
stack traceback:
        ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
Press ENTER or type command to continue
Error executing vim.schedule lua callback: ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: Expected value b
ut found invalid token at character 1
stack traceback:
        [C]: in function 'decode'
        ...typst-preview.nvim/lua/typst-preview/servers/factory.lua:166: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

May be the error was in my editor? Because I separate the configuration file and the plugins as

-- lua/core
    -- plugins.lua
    -- plugin_config
         -- init.lua
         -- typst-preview.lua
-- init.lua
pacaunt commented 3 months ago

This is my plugins.lua file:

local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
    vim.cmd [[packadd packer.nvim]]
    return true
  end
  return false
end

local packer_bootstrap = ensure_packer()

return require('packer').startup(function(use)
  use 'wbthomason/packer.nvim'
  use 'ellisonleao/gruvbox.nvim'
  use 'nvim-tree/nvim-tree.lua'
  use 'nvim-tree/nvim-web-devicons'
  use 'nvim-lualine/lualine.nvim'
  use {
    'nvim-treesitter/nvim-treesitter',
    run = ':TSUpdate'
  }
  use {
    'nvim-telescope/telescope.nvim', tag = '0.1.6',
    requires = { {'nvim-lua/plenary.nvim'} }
  }
  use {
    'chomosuke/typst-preview.nvim',
    tag = 'v0.3.*',
    run = function() require 'typst-preview'.update() end,
  }
  use {
    "windwp/nvim-autopairs",
    event = "InsertEnter",
    run = vim.cmd[[packadd! nvim-autopairs]],
    config = function()
        require("nvim-autopairs").setup {}
    end,
  } 
  use {
    "williamboman/mason.nvim",
    "williamboman/mason-lspconfig.nvim",
    "neovim/nvim-lspconfig",
  }
  use 'hrsh7th/cmp-nvim-lsp'
  use 'hrsh7th/cmp-buffer'
  use 'hrsh7th/cmp-path'
  use 'hrsh7th/cmp-cmdline'
  use 'hrsh7th/nvim-cmp'
  use 'hrsh7th/cmp-vsnip'
  use 'hrsh7th/vim-vsnip'
  use {'kaarmu/typst.vim', ft = {'typst'},opt = false }
  if packer_bootstrap then
    require('packer').sync()
  end
end)
B-Ricey763 commented 3 months ago

The same thing happens to me despite not having non-latin script. @pacaunt how did you get the full stack trace out, without the ..? I want to see what characters are causing me issues.