notebook.nvim icon indicating copy to clipboard operation
notebook.nvim copied to clipboard

Incompatibility with Treesitter Plugin

Open YusufBerki opened this issue 1 year ago • 2 comments

I have magma and treesitter plugins and they are run smoothly. After I install notebook.nvim, I get the following error with every time I open an .ipynb file:

Error detected while processing BufReadPost Autocommands for "*.ipynb":
Error executing lua callback: .../pack/packer/start/notebook.nvim/lua/notebook/render.lua:95: Vim(append):Error executing lua callback: ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: que
ry: invalid node type at position 186 for language python
stack traceback:
        [C]: in function '_ts_parse_query'
        ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: in function 'get_query'
        ...1/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:52: in function 'new'
        ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/treesitter.lua:45: in function '_create_parser'
        ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/treesitter.lua:96: in function 'get_parser'
        ...r/neovim/0.8.1/share/nvim/runtime/lua/vim/treesitter.lua:330: in function 'start'
        .../start/nvim-treesitter/lua/nvim-treesitter/highlight.lua:19: in function 'attach'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:505: in function 'attach_module'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:528: in function 'reattach_module'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:131: in function <...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:130>
        [C]: in function 'nvim_buf_set_option'
        .../pack/packer/start/notebook.nvim/lua/notebook/render.lua:95: in function 'notebook'
        ...im/site/pack/packer/start/notebook.nvim/lua/notebook.lua:60: in function <...im/site/pack/packer/start/notebook.nvim/lua/notebook.lua:33>
stack traceback:
        [C]: in function 'nvim_buf_set_option'
        .../pack/packer/start/notebook.nvim/lua/notebook/render.lua:95: in function 'notebook'
        ...im/site/pack/packer/start/notebook.nvim/lua/notebook.lua:60: in function <...im/site/pack/packer/start/notebook.nvim/lua/notebook.lua:33>

My notebook config is same as your docs:

require("notebook")
local api = require("notebook.api")
local settings = require("notebook.settings")

function _G.define_cell(extmark)
    if extmark == nil then
        local line = vim.fn.line(".")
        extmark, _ = api.current_extmark(line)
    end
    local start_line = extmark[1] + 1
    local end_line = extmark[3].end_row
    pcall(function() vim.fn.MagmaDefineCell(start_line, end_line) end)
end

function _G.define_all_cells()
    local buffer = vim.api.nvim_get_current_buf()
    local extmarks = settings.extmarks[buffer]
    for id, cell in pairs(extmarks) do
        local extmark = vim.api.nvim_buf_get_extmark_by_id(
            0, settings.plugin_namespace, id, { details = true }
        )
        if cell.cell_type == "code" then
            define_cell(extmark)
        end
    end
end

vim.api.nvim_create_autocmd(
    { "BufRead", },
    { pattern = { "*.ipynb" }, command = "MagmaInit" }
)
vim.api.nvim_create_autocmd(
     "User",
    { pattern = { "MagmaInitPost", "NBPostRender" }, callback = _G.define_all_cells }
)

YusufBerki avatar Jun 15 '23 20:06 YusufBerki