Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Inconsistent application of override function #167

Open
3 tasks done
jtledon opened this issue Oct 27, 2023 · 1 comment
Open
3 tasks done

bug: Inconsistent application of override function #167

jtledon opened this issue Oct 27, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jtledon
Copy link

jtledon commented Oct 27, 2023

Did you check docs and existing issues?

  • I have read all the neodev.nvim docs
  • I have searched the existing issues of neodev.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.1 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

Operating system/version

Windows 10 Version 22H2 OS Build 19045.3448 - WSL2 - Ubuntu 22.04.3 LTS

Describe the bug

neodev inconsistently calls optional override function. This occurs for all target directories that neodev would be expected to run in:

repro-neodev-inconsistencies.mp4

It is worth noting that my nvim config directory is symlinked to ~/.dotfiles/.nvim/
In every case where the override function is not called, checking :LspInfo shows that lua_ls did get attatched.
neodev still works in the standard /lua directories when the override function is not called, just not in my ~/.dotfiles/.nvim/, as one would expect.

lspconfig lua_ls settings:

lspconfig.lua_ls.setup({
            capabilities = capabilities,
            on_attach = on_attach,
            settings = { -- custom settings for lua
                Lua = {
                    -- make the language server recognize "vim" global
                    diagnostics = {
                        globals = { "vim" },
                    },
                    hint = { enable = true },
                    workspace = {
                        -- make language server aware of runtime files
                        library = {
                            [vim.fn.expand("$VIMRUNTIME/lua")] = true,
                            [vim.fn.stdpath("config") .. "/lua"] = true,
                        },
                        checkThirdParty = false,
                    },
                },
            },
        })

neodev config

return {
    "folke/neodev.nvim",
    opts = {
        override = function(root_dir, library)
            print(root_dir)
            if root_dir:find("dotfiles") then
                print("inside check")
                library.enabled = true
                library.plugins = true
            end
        end
    },
}

Just wanted to end by thanking you for making neodev! I really appreciate all the incredible plugins you've made; neodev is great too, and will be even better for me if I can fix these inconsistency issues!

Steps To Reproduce

  1. Open neovim in a directory and wait for neodev to call its override function.
  2. Test for snippet completion (vim.api.nvim_create...)

Expected Behavior

I assumed that once I had setup neodev, it would apply itself on every instance of nvim opening in the appropriate directories

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/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", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",

  'nvim-lua/plenary.nvim',
  {
      "folke/neodev.nvim",
      config = function()
          print("calling config fn")
          require("neodev").setup({
              override = function(root_dir, library)
                  print(root_dir)
                  if root_dir:find("dotfiles") then
                      print("inside check")
                      library.enabled = true
                      library.plugins = true
                  end
              end
          })
      end
  },
  {
    "neovim/nvim-lspconfig",
    event = { "BufReadPre", "BufNewFile" },

    dependencies = {
        "hrsh7th/cmp-nvim-lsp",
        { "antosha417/nvim-lsp-file-operations", config = true },
        "williamboman/mason.nvim",

        "folke/neodev.nvim",
    },


    config = function()
        local lspconfig = require("lspconfig")
        local cmp_nvim_lsp = require("cmp_nvim_lsp")

        -- used to enable autocompletion (assign to every lsp server config)
        local capabilities = cmp_nvim_lsp.default_capabilities()

        -- Change the Diagnostic symbols in the sign column (gutter)
        local signs = {
            Error = "E ",
            Warn = "W ",
            Hint = "H ",
            Info = "I "
        }

        for type, icon in pairs(signs) do
            local hl = "DiagnosticSign" .. type
            vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
        end

        -- configure lua server (with special settings)
        lspconfig.lua_ls.setup({
            capabilities = capabilities,
            on_attach = on_attach,
            settings = { -- custom settings for lua
                Lua = {
                    -- make the language server recognize "vim" global
                    diagnostics = {
                        globals = { "vim" },
                    },
                    hint = { enable = true },
                    workspace = {
                        -- make language server aware of runtime files
                        library = {
                            [vim.fn.expand("$VIMRUNTIME/lua")] = true,
                            [vim.fn.stdpath("config") .. "/lua"] = true,
                        },
                        checkThirdParty = false,
                    },
                },
            },
        })

        vim.diagnostic.config({
            virtual_text = true
        })
    end,
  },
  {
    "williamboman/mason.nvim",

    dependencies = {
        "williamboman/mason-lspconfig.nvim",
    },

    config = function ()
        local mason = require("mason")
        local mason_lspconfig = require("mason-lspconfig")

        mason.setup({})

        -- server names found here: https://github.com/williamboman/mason-lspconfig.nvim#available-lsp-servers
        mason_lspconfig.setup({
            ensure_installed = {
                'lua_ls',
            },

            automatic_installation = true,
        })
    end,
  },
  {
    "hrsh7th/nvim-cmp", -- completion plugin
    event = "InsertEnter",
    dependencies = {
            -- Autocompletion
            {'hrsh7th/cmp-nvim-lsp'},     -- Required
            {'hrsh7th/cmp-buffer'},       -- Optional
            {'hrsh7th/cmp-path'},         -- Optional
            {'saadparwaiz1/cmp_luasnip'}, -- Optional
            {'hrsh7th/cmp-nvim-lua'},     -- Optional

            -- Snippets
            {'L3MON4D3/LuaSnip'},             -- Required
            {'rafamadriz/friendly-snippets'}, -- Optional
    },

    config = function ()
        local cmp = require("cmp")
        local luasnip = require("luasnip")
        require("luasnip.loaders.from_vscode").lazy_load()

        local cmp_keymaps = {
                ["<Tab>"] = cmp.mapping(function(fallback)
                    -- This little snippet will confirm with tab, and if no entry is selected, will confirm the first item
                    if cmp.visible() then
                        local entry = cmp.get_selected_entry()
                        if not entry then
                            cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
                            cmp.confirm()
                        else
                            cmp.confirm()
                        end
                    else
                        fallback()
                    end
                end, {"i","s"}),

                ["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
                ["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
                ["<C-l>"] = cmp.mapping.complete(), -- [L]ist recommended
                ["<C-b>"] = cmp.mapping.scroll_docs(-4),
                ["<C-f>"] = cmp.mapping.scroll_docs(4),
                ["<C-n>"] = cmp.config.disable,
                ["<C-p>"] = cmp.config.disable,
            }

        cmp.setup({
            mapping = cmp.mapping.preset.insert(cmp_keymaps),
            completion = {
                completeopt="menu,menuone,preview,noselect",
            },
            snippet = {
                expand = function(args)
                    luasnip.lsp_expand(args.body)
                end,
            },
            sources = cmp.config.sources({
                { name = "nvim_lsp" },
                { name = "luasnip" },
                { name = "buffer" },
                { name = "path" }
            }),
        })
    end
  }
}



require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@jtledon jtledon added the bug Something isn't working label Oct 27, 2023
@wookayin
Copy link

See #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants