nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.03k stars 134 forks source link

`utils/fs.lua` overwrites global M, breaking other extension #646

Closed zivarah closed 9 months ago

zivarah commented 9 months ago

Describe the bug

orgmode appears to be unconditionally setting M in lua/orgmode/utils/fs.lua:

M = {}

This results in benfowler/telescope-luasnip.nvim not working if orgmode is loaded after it:

:Telescope luasnip disable_ft=true

Error executing Lua callback: vim/shared.lua:305: after the second argument: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua:764: in function 'validate'
        vim/shared.lua:305: in function 'tbl_extend'
        ...scope-luasnip.nvim/lua/telescope/_extensions/luasnip.lua:74: in function <...scope-luasnip.nvim/lua/telescope/_extensions/luasnip.lua:73>
        .../nvim-data/lazy/telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
        .../nvim-data/lazy/telescope.nvim/lua/telescope/command.lua:259: in function 'load_command'
        ...Local/nvim-data/lazy/telescope.nvim/plugin/telescope.lua:108: in function <...Local/nvim-data/lazy/telescope.nvim/plugin/telescope.lua:107>

This issue does not occur if I swap the event= { "VeryLazy" } lines so that orgmode loads first. That said, it appears that telescope-luasnip also is doing an unconditional set of the global M (link, and it seems like that would break orgmode?

I am very new to nvim plugins and lua in general so I can't speak to whether this is an unexpected pattern or not. Should we be using a more distinct global name? Should we be doing M = M or {} instead? I did confirm that M = M or {} appears to address this.

Steps to reproduce

With the minimal config below:

Expected behavior

orgmode should not wipe out global state set from other extensions.

Emacs functionality

No response

Minimal init.lua

-- Ensure that Lazy is cloned
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable",
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "nvim-telescope/telescope.nvim",
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
        config = function()
            local telescope = require("telescope")

            telescope.setup({
                extensions = {
                    luasnip = {},
                },
            })

            telescope.load_extension('luasnip')
        end
    },
    {
        "benfowler/telescope-luasnip.nvim",
        --event = { "VeryLazy" },

    },
    {
        "L3MON4D3/LuaSnip",
        dependencies = {
            "benfowler/telescope-luasnip.nvim",
        },
    },
    {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        config = function()
            require("nvim-treesitter.configs").setup({})
        end
    },
    {
        'nvim-orgmode/orgmode',
        event = { "VeryLazy" },
        dependencies = {
            { "nvim-treesitter/nvim-treesitter" },
        },
        config = function()
            require('orgmode').setup_ts_grammar()
            require('orgmode').setup({})
        end,
    },
})

Screenshots and recordings

No response

OS / Distro

Windows 10

Neovim version/commit

0.9.2

Additional context

No response

kristijanhusak commented 9 months ago

Should be fixed now, thanks!