lazydev.nvim is a plugin that properly configures LuaLS for editing your Neovim config by lazily updating your workspace libraries.
require
in open Neovim files will be loaded.require("nvim-treesitter")
---@module "nvim-treesitter"
require(...)
will only return loaded modules in your workspace.library
option.With lazy.nvim:
return { { "folke/lazydev.nvim", ft = "lua", -- only load on lua files opts = { library = { -- See the configuration section for more details -- Load luvit types when the `vim.uv` word is found { path = "${3rd}/luv/library", words = { "vim%.uv" } }, }, }, }, { -- optional cmp completion source for require statements and module annotations "hrsh7th/nvim-cmp", opts = function(_, opts) opts.sources = opts.sources or {} table.insert(opts.sources, { name = "lazydev", group_index = 0, -- set group index to 0 to skip loading LuaLS completions }) end, }, { -- optional blink completion source for require statements and module annotations "saghen/blink.cmp", opts = { sources = { -- add lazydev to your completion providers default = { "lazydev", "lsp", "path", "snippets", "buffer" }, providers = { lazydev = { name = "LazyDev", module = "lazydev.integrations.blink", -- make lazydev completions top priority (see `:h blink.cmp`) score_offset = 100, }, }, }, }, } -- { "folke/neodev.nvim", enabled = false }, -- make sure to uninstall or disable neodev.nvim }
Tip
You can force enable/disable lazydev in certain project folders using :h 'exrc' with vim.g.lazydev_enabled = true
or vim.g.lazydev_enabled = false
Examples:
{ "folke/lazydev.nvim", ft = "lua", -- only load on lua files opts = { library = { -- Library paths can be absolute "~/projects/my-awesome-lib", -- Or relative, which means they will be resolved from the plugin dir. "lazy.nvim", -- It can also be a table with trigger words / mods -- Only load luvit types when the `vim.uv` word is found { path = "${3rd}/luv/library", words = { "vim%.uv" } }, -- always load the LazyVim library "LazyVim", -- Only load the lazyvim library when the `LazyVim` global is found { path = "LazyVim", words = { "LazyVim" } }, -- Load the wezterm types when the `wezterm` module is required -- Needs `justinsgithub/wezterm-types` to be installed { path = "wezterm-types", mods = { "wezterm" } }, -- Load the xmake types when opening file named `xmake.lua` -- Needs `LelouchHe/xmake-luals-addon` to be installed { path = "xmake-luals-addon/library", files = { "xmake.lua" } }, }, -- always enable unless `vim.g.lazydev_enabled = false` -- This is the default enabled = function(root_dir) return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled end, -- disable when a .luarc.json file is found enabled = function(root_dir) return not vim.uv.fs_stat(root_dir .. "/.luarc.json") end, }, },
Default settings:
---@alias lazydev.Library {path:string, words:string[], mods:string[]} ---@alias lazydev.Library.spec string|{path:string, words?:string[], mods?:string[]} ---@class lazydev.Config local defaults = { runtime = vim.env.VIMRUNTIME --[[@as string]], library = {}, ---@type lazydev.Library.spec[] integrations = { -- Fixes lspconfig's workspace management for LuaLS -- Only create a new workspace if the buffer is not part -- of an existing workspace or one of its libraries lspconfig = true, -- add the cmp source for completion of: -- `require "modname"` -- `---@module "modname"` cmp = true, -- same, but for Coq coq = false, }, ---@type boolean|(fun(root:string):boolean?) enabled = function(root_dir) return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled end, }
Just install the plugin and start editing your Lua files.
If you don't use nvim-lspconfig, then you can use require('lazydev').find_workspace(buf?)
to check if the buffer is part of an existing workspace or its libraries.
The :LazyDev
command:
:LazyDev
or :LazyDev debug
will show a notification with the lazydev settings for the current buffer.:LazyDev lsp
: will show a notification with the settings for any attached LSP servers. Not limited to LuaLS.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4