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: Neodev suggestions are unavailable from some places #109

Closed
3 tasks done
przepompownia opened this issue Jan 15, 2023 · 8 comments · Fixed by #111
Closed
3 tasks done

bug: Neodev suggestions are unavailable from some places #109

przepompownia opened this issue Jan 15, 2023 · 8 comments · Fixed by #111
Labels
bug Something isn't working

Comments

@przepompownia
Copy link

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 exsiting issues of plugins related to this issue

Neovim version (nvim -v)

v0.9.0-dev-687+g8b86cb8f5

Operating system/version

Debian Sid

Describe the bug

First, maybe it's the issue for https://github.com/folke/neodev.nvim/discussions but it does not exist 😁

I cannot get Neodev suggestions inside a Lua file from non-typical path (bundleConfig in this example).

Steps To Reproduce

  1. run /path/to/bin/nvim -u ~/tmp/neodev-min.lua where ~/tmp/neodev-min.lua contents is shown below
  2. try to complete vim.api.nvim_ using omnifunc (or uncomment cmp-specific pieces) in both open files
  3. for me, it works inside plugin, does not in bundleConfig
neodev.mp4

image

Expected Behavior

Suggestions are available from any lua file inside the project root.

Repro

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",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    -- "folke/noice.nvim",
    -- dependencies = {
    --   "MunifTanjim/nui.nvim",
    -- },
  },
  "folke/neodev.nvim",
  'neovim/nvim-lspconfig',
  -- 'hrsh7th/nvim-cmp',
  -- 'hrsh7th/cmp-nvim-lsp',
  {
    -- only to show repro
    'przepompownia/nvim-arctgx',
    cond = false,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here
vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])
-- require("noice").setup({
--   messages = {
--     view = 'mini',
--     view_search = false,
--     view_error = 'mini',
--     view_warn = 'mini',
--   },
--   notify = {
--     enabled = true,
--     view = 'mini',
--   },
--   lsp = {
--     signature = {
--       enabled = false,
--     },
--     hover = {
--       enabled = false,
--     }
--   },
--   views = {
--     mini = {
--       timeout = 5000,
--     },
--   },
-- })

-- vim.keymap.set('c', '<C-x>', function()
--   require('noice').redirect(vim.fn.getcmdline())
--   vim.api.nvim_input('<esc>')
-- end, { desc = 'Redirect Cmdline' })

vim.cmd([[
  set omnifunc=v:lua.vim.lsp.omnifunc
  set tagfunc=v:lua.vim.lsp.tagfunc
  set completeopt=menu
]])

local capabilities = vim.lsp.protocol.make_client_capabilities()
require'neodev'.setup({
  override = function (root_dir, options)
    vim.notify('Neodev with root dir ' .. root_dir, vim.log.levels.INFO)
  end
})
require('lspconfig').sumneko_lua.setup {
  capabilities = capabilities,
  settings = {
    Lua = {
      runtime = {
        version = 'LuaJIT',
      },
      completion = {
        -- showWord = 'Disable',
      },
      diagnostics = {
        globals = {'vim'},
      },
    },
  },
}
-- local cmp = require 'cmp'

-- local hasWordsBefore = function()
--   local line, col = unpack(vim.api.nvim_win_get_cursor(0))
--   return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
-- end

-- cmp.setup({
--   snippet = {
--     expand = function(args)
--     end,
--   },
--   mapping = cmp.mapping.preset.insert({
--     ['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
--     ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
--     ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), {'i', 'c'}),
--     ['<Tab>'] = cmp.mapping(function(fallback)
--       if cmp.visible() then
--         cmp.select_next_item()
--       elseif hasWordsBefore() then
--         cmp.complete()
--       else
--         fallback()
--       end
--     end, {'i', 's'}),

--     ['<A-CR>'] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}),
--     ['<S-Tab>'] = cmp.mapping(function(fallback)
--       if cmp.visible() then
--         cmp.select_prev_item()
--       else
--         fallback()
--       end
--     end, {'i', 's'}),
--     ['<C-y>'] = cmp.mapping.confirm({select = true}),
--     ['<C-e>'] = cmp.mapping({
--       i = cmp.mapping.abort(),
--     }),
--     ['<CR>'] = cmp.mapping.confirm({select = true}),
--   }),
--   sources = {
--     {name = 'nvim_lsp'},
--   },
--   confirmation = {
--     default_behavior = cmp.ConfirmBehavior.Replace,
--   },
--   sorting = {
--     comparators = {
--       cmp.config.compare.score,
--       cmp.config.compare.offset,
--       cmp.config.compare.sort_text,
--       cmp.config.compare.exact,
--       cmp.config.compare.recently_used,
--       cmp.config.compare.locals,
--     }
--   },
--   completion = {
--     completeopt = 'menu,menuone',
--   },
--   window = {
--     completion = cmp.config.window.bordered(),
--     documentation = cmp.config.window.bordered(),
--   },
-- })

vim.schedule(function ()
  vim.opt.number = true
  vim.cmd.edit '.repro/plugins/nvim-arctgx/plugin/lsp.lua'
  vim.cmd.split '.repro/plugins/nvim-arctgx/bundleConfig/nvim-lspconfig.lua'
end)
@przepompownia przepompownia added the bug Something isn't working label Jan 15, 2023
@folke
Copy link
Owner

folke commented Jan 15, 2023

That's on purpose. You don't want Neovim apis available in regular lua projects. Use the override() config option to make it available or set it up using neoconf

@folke folke closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2023
@przepompownia przepompownia changed the title bug: Neodecvc suggestions are unavailable from some places bug: Neodev suggestions are unavailable from some places Jan 15, 2023
@przepompownia
Copy link
Author

przepompownia commented Jan 16, 2023

@folke I don't understand your response.

It's a Neovim project. Yes, it's still a strange, legacy set of configurations started for Vim many years before Neovim began to exist, slowly evolving to rewrite it into Lua.

You can also try to complete vim.api. inside plenary/job.lua from Plenary. I found that such completion does not work if vim is a local variable (even if it it's value is global vim).

neodev2.mp4

@folke
Copy link
Owner

folke commented Jan 16, 2023

Ah now I get what you mean. That's not a neodev issue. Sumneko issue. Not sure why that doesnt work

@przepompownia
Copy link
Author

przepompownia commented Jan 17, 2023

Two side notes after digging into neodev.util.lua for an attempt to explain what to configure:

  • indeed, editing nvim project outside vim.fn.stdpath('config') requires setting options.plugins = true in override() to have suggestions from plugins.
  • if directory vim.fn.stdpath('config') does not exist, then neodev "crashes" with something like "ENOENT: no such file or directory: ~/.config/nvim" (in the sense that override() is not executed). As a side effect I updated my project to have nvim directory (the name seems to be hardcoded in Neovim project) and XDG_%s_HOME like in the mimimal Lua file above but in Neodev it would be good to prevent from this error.

@folke
Copy link
Owner

folke commented Jan 17, 2023

That error should have been fixed a couple of days ago. Can you check again with the latest version?

@przepompownia
Copy link
Author

przepompownia commented Jan 17, 2023

After adding two notification

    local config_root = vim.loop.fs_realpath(vim.fn.stdpath("config"))
    vim.notify('config root type: ' .. type(config_root))
    config_root = vim.fs.normalize(config_root)
    vim.notify('config root: ' .. config_root)

only the first gives the output (nil). In cmdline :lua =vim.fs.normalize(nil) causes type error

E5108: Error executing lua ...ctgx/tmp/nvim-from-src/share/nvim/runtime/lua/vim/fs.lua:298: path: expected string, got nil                                                                                                              
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        ...ctgx/tmp/nvim-from-src/share/nvim/runtime/lua/vim/fs.lua:298: in function 'normalize'
        [string ":lua"]:1: in main chunk

i.e. is pcall used somewhere?

@folke folke reopened this Jan 17, 2023
@folke folke closed this as completed in fc20483 Jan 17, 2023
@folke
Copy link
Owner

folke commented Jan 17, 2023

Fixed!

@przepompownia
Copy link
Author

przepompownia commented Jan 17, 2023

Thanks!

I also have some suggestions to make work on portable (non Lazy) environments more independent of the vim.o.packpath from the Neovim instance that running Neodev but I need some time to prepare new issue.

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

Successfully merging a pull request may close this issue.

2 participants