folke / neodev.nvim Goto Github PK
View Code? Open in Web Editor NEW๐ป Neovim setup for init.lua and plugin development with full signature help, docs and completion for the nvim lua API.
License: Apache License 2.0
๐ป Neovim setup for init.lua and plugin development with full signature help, docs and completion for the nvim lua API.
License: Apache License 2.0
Hi @folke
May I know if this is an error when suffixed library path with /lua
? As I notice that we have already looking for files using lua/?.lua
https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua#L14
Currently, I got no suggestions from installed plugins. Tried to remove this /lua
suffix then everything works as expected.
I've been using this for about a week now and it's been a great experience.
However, global lua functions defined in nvim/lua/... are no longer 'visible' to lsp if they are referenced in another file.
The diagnostics reports "undefined global <func>
" and I've confirmed this only happens when lua-dev is loaded.
I took a look at your dotfiles to see if I had setup my environment incorrectly, and found that you have two globals defined in util.lua (dump() and profile()) but they aren't used in any other file.
AFAICT it should be reproducable for you if you did dump("hello world")
in another .lua file.
Totally fine if you consider something like this a non-issue, btw.
After opening a file that configures nvim-cmp
, the server shows the following message:
Go to definition of cmp.setup
opens nvim-autopairs/completion/cmp.lua
Server Setup config:
local sumneko_lua = require('lua-dev').setup {
library = { runtime = true, plugins = true, types = true },
runtime_path = true,
}
M.sumneko_lua = sumneko_lua
Hi @folke,
I've been using this plugin and quite enjoying it for developing my plugins. Recently though, i.e. the last good commit that is working for me cf3b028, I have not been getting diagnostics or other lsp functionality inside my lua plugins. I see some changes around a workspace plugin in 681c0fc, which is the commit that broke things for me, though I've not dug in enough to know what happened. My config for the plugins is
lspconfig = {
settings = {
Lua = {
diagnostics = {
globals = {
'vim',
'describe',
'it',
'before_each',
'after_each',
'pending',
'teardown',
'packer_plugins',
},
},
completion = { keywordSnippet = 'Replace', callSnippet = 'Replace' },
},
},
}
This settings doesn't work:
local lsp_settings = {
lua = require("lua-dev").setup({
plugins = true,
lspconfig = {
diagnostics = {
globals = {"use"},
},
},
})
}
local lspconfig = require('lspconfig')
lspconfig[lua].setup( lsp_settings[lua] )
I get errors Undefined global 'use'
for packer use
statements.
But raw settings given directly to lspconfig works:
local lsp_settings = {
lua = {
settings = {
Lua = {
diagnostics = {
globals = {"use"},
},
},
},
}
}
local lspconfig = require('lspconfig')
lspconfig[lua].setup( lsp_settings[lua] )
from which I can make a conclusion that problem is in the plugin.
Hi thank you for this plugin. I want to try this out but it gives me client exit with code 1 when I start a lua file after I have installed by following the documentation. What can I do to further debug and find out the issue?
There are always some new functions appearing
one examples I know right out of my head would be vim.keymap.*
I don't know how you create the database with the functions.
But would it be possible to automatically do this with a github action so it's always up to date? @folke
Thanks for the great plugin! It works amazingly well out-of-the-box.
I see that the plugin depends on a "full" completion plugin to work properly, since the built-in vim.lsp.omnifunc
seems to simply return a gigantic list of all available completion options, regardless of the current context. I'm curious whether this is a fundamental limitation or whether there's any chance of getting omnifunc support. If it's the latter, I'd be happy to contribute towards getting it to work.
Hello, thanks for this plugin, very helpful. There's a minor inconvenience - without this plugin, I only get loading status
with this plugin, I get "Diagnosing <file>" status too:
This spams my statusline every time I make an edit, how do I disable this? (Setting settings.Lua.window.progressBar
in lspconfig to false disables loading status too, although I've done this for now)
I use https://github.com/tjdevries/express_line.nvim with https://github.com/nvim-lua/lsp-status.nvim
I am new to this plugin.
In past I have had lua sumneko server install using lspinstall and configured using the standard config found at the lspinstall site.
local lua_settings = `{`
Lua = {
runtime = {
-- LuaJIT in the case of Neovim
version = "LuaJIT",
path = vim.split(package.path, ";"),
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
},
It was kind of working and then I came upon on this plugin of yours and wanted to give it a try. I commented out the above settings and installed your setup with the default settings . I didn't deinstall the lua completion server installed through lspinstall
Now its though its running using the configs from this plugin I am getting the following message in Lspinfo. Is there something I am missing in my setup. Also does this plugin give any additional benefit over the setup I had initially
Thanks for the great plugin!
Personally, I don't like this feature and would like to disable it.
I've been spending quite a few hours scratching my head as to how I would integrate this with nvim-lspinstall.
I don't want to have lua-language-server in my $PATH
but there is no good documentation on nvim-lspinstall that allows me to use this properly. Any idea as to how I would do this?
require("lua-dev").setup { ... }
produces the following opts for lspconfig.sumneko_lua
:
Lua = {
...
completion = { callSnippet = "Replace" },
workspace = {
-- Make the server aware of Neovim runtime files
library = M.library(opts),
maxPreload = 1000,
preloadFileSize = 150,
},
...
},
Reference: https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua#L82-L93
Personally I don't like the completion.callSnippet
and workspace.maxPreload
behavior. The reasons are: (i) functions will show up as snippet entries in the completion engine (rather than kind of function); (ii) When analyzing some lua files greater than the maxPreload
size, an input prompt will be asked. With the default value of workspace.maxPreload
nil
, it won't.
I think these values are very opinionated values and should not a part of this plugin (people can have them rather in their own lsp config files). At least these could be customizable through options for lua_dev.setup { ...}
.
Hello, I like the type definitions this plugin provides and it works well, much better than any cmp-nvim-lua.
However, it necessitates the turning on of snippets. This means when I open completion I see snippets for if, for, ipairs, etc... all of which are useless for me because I made my own snippets.
Is there anything I can do about this (e.g. any way of filtering out snippets sent by sumneko_lua
while keeping those from lua-dev)?
Completion of require paths slows down the lsp server a lot. (see 274f72b)
Will add a config setting to enable this. (default is disabled)
In case of working on only a few plugins, it seems unnecessary to load all of the user's plugins which could be dozens of them and that could mean that the server will have to index a lot of files.
We could extend library.plugins
key to accept a table of opt
or start
plugin names which should be added. So, the type for library.plugins
would become boolean|table<string, string[]>
:
true
: add all the opt and start pluginsfalse
: do not add any of the pluginstable
: containing two keywords opt
and start
each with a list of plugin names to be addednvim_create_autocmd was added in neovim version 0.7.
I saw a previous commit (6063731) with the title 'feat: updated docs to 0.7' which is why I thought the lua-dev does support the entire 0.7 neovim api.
However I dont see it in the docs (I checked types/api.lua and types/api1.lua). Is there anyway this could be added ?
Could you add a callback for on attach
i'd like to have custom mappings for LSP applied but only if the LSP is loaded
This might be the noobest question in git issues history, but I cant for the life of me figure out how to add libraries apart from the default.
For example, before using lua-dev I had something like this in "regular" sumneko, and it worked correctly.
settings = {
Lua = {
runtime = {version = "LuaJIT", path = vim.split(package.path, ";")},
diagnostics = {globals = {"vim", "pd"}},
workspace = {
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
["/usr/lib/pd/extra/pdlua"] = true,
["/some/other/libraries"] = true,
}
}
}
}
I have tried adding the same in libraries = {}
section like this
local luadev =
require("lua-dev").setup(
{
libraries = {
["/usr/lib/pd/extra/pdlua"] = true,
},
lspconfig = {
on_attach = custom_attach,
and I have also tried in the same's lspconfig like this
settings = {
Lua = {
runtime = {version = "LuaJIT", path = vim.split(package.path, ";")},
diagnostics = {globals = {"vim", "pd"}},
workspace = {
library = {
["/usr/lib/pd/extra/pdlua"] = true
}
}
}
}
But with either setup, the libraries wont get picked up. I dont get any lsp features like hover, autocompletion, nothing at all.
I am sure there is a an exceedingly simple answer to this, which once you point out I will feel too stupid to show my face on github again.
Can you please help?
My configuration can be seen here
For some reason, when editing a lua file inside a plugin, the server can't quite keep up. I have several minutes delay on diagnostics and completion is unusable (running nvim-compe).
Is there something I can do to debug this or fix this? Before I was running plain sumneko and it was fine (but without all the nice info for nvim functions)
At the moments quite some functions are missing:
vim.keymap. ...
the autocommand functions
the user_command functions
vim.loop. ...
could you add this @folke ?
Hello, thank you for this plugin, it really helps with vim plugin development.
I think it will be great if you make more use of generics, so the types will not be lost when using built-in vim functions.
For example, tbl_filter could be generic and take a function that takes a type of T. Same for values, etc.
For example:
-- Filter a table using a predicate function
---@generic T
--- @param func fun(arg: T): boolean
--- @param t T[]
--- @return T[]
function vim.tbl_filter(func, t) end
This plugin changes the default of Lua.runtime.path
from { "?.lua", "?/init.lua", "?/?.lua" }
to { "lua/?.lua", "lua/?/init.lua
.
This caused me almost a day of frustration, as I could not get my lua completion to work correctly: LuaLS/lua-language-server#657
Looking back the readme mentions it, but understates what is being done:
properly configures the require path with lua/?.lua and lua/?/init.
I would like it to be more explicit so no one else has to struggle a day for no reason. Something like:
ATTENTION: This Plugin changes the default runtime path, if you would like to use the sumneko lua-language-server for other lua projects add the following to your config:
local luadev = require("lua-dev").setup({
lspconfig = {
-- cmd = {"lua-language-server"},
settings = {
Lua = {
runtime = {
path = {
"?.lua",
"?/?.lua",
"?/init.lua",
}
},
},
},
})
I see that the readme specifies I get completion for plugins in opt and start directories, I'm not sure whether that includes auto-completions for, say, require('telescope.builtins').|
so completion on the |
character.
how can I get completions for plugin modules
PS: Not sure if this is a luadev issue or a sumneko issue
This is from a plugin I wrote using plenary
Even though hover shows the correct doc/signature for these methods, I get "Undefined field" warnings
Hi,
it would be neat if we could provide additional globals to the configuration. Currently I'm doing this:
luadev.settings.Lua.diagnostics.globals = {'vim', 'describe', 'it', 'before_each', 'after_each'}
nvim_lsp.sumneko_lua.setup(luadev)
Having top level globals that would merge into existing one would be great.
Or even making all of these a default globals value.
I understand this is dependent on nvim compe. Was wondering if you be updating this to be compatible with nvim cmp
the readme states that:
properly configures the require path with lua/?.lua and lua/?/init.lua.
i'd like to have a setup overwrite for this because some of my code isn't indexed
my folder structure looks like this for instance
lua/plugins/*/*.lua
would this be possible
Hi! I commented on the latest commit, but I guess you didn't notice it. Therefore I'll open an issue as well with just pasting what I also commented on the latest commit:
This commit broke something for me. I also have something specified in settings.workspace.library
for sumneko, and now it is not able to merge those two together.
This is because you changed from having a table where the key (path) mapped to true. This way, tbl_deep_extend
are able to merge the two together, since the keys are the paths. Now, it is only a list instead, and the indexes are the keys, and the value is the path.
Since tbl_deep_extend
looks at the keys for merging together, it will not work since we will both have a key of 1
, and then one entry you specify for that setting in the plugin is dropped. I think we should either revert to mapping to true
, or find another way to merge together the tables
As mentioned here, this breaks the LSP renaming.
Minimal repro:
~/.config/nvim
points to ~/dotfiles/config/nvim
minimal.vim
in ~/dotfiles/config/nvim/minimal.vim
~/dotfiles
directory nvim --noplugin -n -u config/nvim/minimal.vim
:e test.lua
with the following contents:local test = "is this working?"
print(test)
:lua print(vim.inspect(vim.lsp.buf_get_clients()))
test
and run :lua vim.lsp.buf.rename()
set nocompatible hidden laststatus=2
map Q <nop>
" Download the plugin manager
if !filereadable('/tmp/plug.vim')
silent !curl -fsSLo /tmp/plug.vim
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif
source /tmp/plug.vim
call plug#begin('/tmp/plugged')
" LSP plugin
Plug 'neovim/nvim-lspconfig'
" Plugins to test
Plug 'folke/lua-dev.nvim'
call plug#end()
autocmd VimEnter * PlugClean! | PlugUpdate --sync | close
" Load the plugins (packadd <plugin_name>)
packadd nvim-lspconfig
packadd lua-dev.nvim
" For lua only plugins
lua << EOF
local luadev = require("lua-dev").setup()
local lspconfig = require('lspconfig')
local home = vim.loop.os_homedir()
-- Place the actual path to the binary for your machine
luadev.cmd = {
home .. "/git/lua-language-server/bin/macOS/lua-language-server",
"-E",
home .. "/git/lua-language-server/main.lua",
}
lspconfig.sumneko_lua.setup(luadev)
EOF
nvim --version
โฏ nvim --version
NVIM v0.5.0-dev+e0a01bd-dirty
Build type: Debug
LuaJIT 2.1.0-beta3
Compilation: /Library/Developer/CommandLineTools/usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=1 -I/Users/dhruvmanilawala/git/neovim/build/config -I/Users/dhruvmanilawala/git/neovim/src -I/Users/dhruvmanilawala/git/neovim/.deps/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include -I/usr/local/opt/gettext/include -I/Users/dhruvmanilawala/git/neovim/build/src/nvim/auto -I/Users/dhruvmanilawala/git/neovim/build/include
Compiled by dhruvmanilawala@mbp
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/share/nvim"
Run :checkhealth for more info
Context:
delete root from workspace to make sure we don't trigger duplicate warnings
What I think is happening and I could be wrong, but as you mentioned the above, there are now these two paths which could be creating some clashes:
~/dotfiles/config/nvim
for the library
key which is from vimconfig = true
~/dotfiles
current working directoryNeovim version: V0.6 nightly
OS: Windows 10 x64 Pro
:LspInfo
:
Configured servers: ahk_lsp, sumneko_lua, ghdl_ls, vhdl_ls, vhdl_tool, hdl_checker
Neovim logs at: C:\Users\MyUsername\AppData\Local\Temp\nvim/lsp.log
0 client(s) attached to this buffer:
0 active client(s):
Clients that match the filetype lua:
Config: sumneko_lua
cmd: lua-language-server
cmd is executable: True
identified root: C:\Work\MEGA\Portable\Neovim\config
custom handlers:
lsp.log
:
[ START ] 2021-07-25T00:10:23+0200 ] LSP logging initiated
[ ERROR ] 2021-07-25T00:10:26+0200 ] ...A\Portable\Neovim\share\nvim\runtime\lua\vim\lsp\rpc.lua:462 ] "rpc" "lua-language-server" "stderr" "lua-language-server:\0stdin:1: syntax error near '-'\0"
lua-dev
setup file:
local luadev = require("lua-dev").setup({
lspconfig = {
filetypes = {"lua"},
cmd = {"lua-language-server"},
sumneko_root_path = "C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server",
sumneko_binary = "C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server/bin/Windows/lua-language-server",
},
})
local lspconfig = require('lspconfig')
lspconfig.sumneko_lua.setup(luadev)
Hi, thanks for this project. What about making its interface/docs more approachable to non nvim-lsp clients? After analyzing the source code I realized how to hack a fairly simple coc-lua configuration:
local lua_settings = require('lua-dev').setup().settings.Lua
lua_settings.workspace.library = require('lua-dev.sumneko').library()
lua_settings.workspace.library['/usr/share/nvim/runtime'] = nil
vim.fn['coc#config']('Lua', lua_settings)
Hello and thanks you for the plugin. It makes neovim
configuration experience much better but I have one small question.
All the user configurations and plugins I saw had their .lua
files in subdirectory called lua
, like .config/nvim/lua/mappings.lua
. But I always preferred to have fewer directory levels so I put my files into just .config/nvim
and it worked as long as I set package.path
to config/nvim/?.lua
. But it seems like your plugin doesn't support this: sumneko
"go to definition" doesn't work until I put file with definition in lua
subdirectory. Do I really have to do that to have "go to definition" working? Or is it possible to configure something?
Also I've found this commented out line and tried to uncomment it, but it didn't help
https://github.com/folke/lua-dev.nvim/blob/4331626b02f636433b504b9ab6a8c11fb9de4a24/lua/lua-dev/sumneko.lua#L44
Hi @folke ,
First of all, thank you for the plugin. It really helps me to get started with lua dev quickly. Just curious if you plan to support for additional workspaces, e.g. hammerspoon?
Something like this https://www.reddit.com/r/neovim/comments/pla7bv/since_everyone_is_getting_more_familiar_with_lua/
Cheers
Two workspaces are loaded in the newest Sumneko lua server when using lua-dev. I can confirm this does not occur when not using lua-dev in lspconfig.
The effect of loading two workspaces is super slow startup for the lsp, and super slow autocompletes and goto definitions.
The proof of two workspaces loaded can be seen in the screenshot by using lsp_status
indicator in the status line (the bottom row).
This is most likely caused by the new workspaces feature. Can be seen from this compare tag commits.
#30 solves it for me
when i add the local nvim folder .config/nvim
to the workspace
The README says:
full signature, docs and completion of vim.api, vim.treesitter, vim.lsp and others
However, it seems like vim.treesitter
annotations are very spotty. I can't tell if they just haven't been done, or this is a bug. I'm inclined to think bug because the annotations look wrong, find below a screenshot of the popup for vim.treesitter.parse_query
:
The nil.parse_query
part is clearly a bug, perhaps the same bug is interfering with getting the annotation info?
Can we add an option not to use nvim-lspconfig in #39 ?
Or at least we need to note that this plugin requires nvim-lspconfig in README.
I'm using this plugin with coc.nvim. And lspconfig is not installed.
Update: Apparently, I may be the only person in Neovimland who was perfectly happy with the completions from this plugin alone. But, if you do have the lua-language-server
set up then the below will not impact you.
For those who find this later, this is my proper working configuration for using this plugin with lua-language-server
:
local lspconfig = require "lspconfig"
local luadev = require("lua-dev").setup {
lspconfig = {
cmd = {
"/Users/joel/vim-dev/sources/lua-language-server/bin/macOS/lua-language-server",
"-E",
"/Users/joel/vim-dev/sources/lua-language-server/main.lua",
},
},
}
lspconfig.sumneko_lua.setup(luadev)
Original "issue" when I was happily using this plugin without lua-language-server
:
I'm not sure if this is an issue per se. But, when neovim/nvim-lspconfig#1171 landed on 2021-08-24, I began to get the message: cmd not defined for "sumneko_lua". You must manually set cmd in the setup{} call according to CONFIG.md
when opening any Lua file. This makes perfect sense since the PR "unsilenced" the message. I'm using the default lua-dev
setup as shown here: https://github.com/folke/lua-dev.nvim#-setup. Everything still worked perfectly fine. But, the message is distracting.
So, Instead of adding an extra conditional branch to nvim-lspconfig
(locally) that ignored sumneko_lua
, I decided to just set enabled
to false
as shown below in order to fall into this conditional branch: https://github.com/neovim/nvim-lspconfig/blob/62b9e1a27dd0c9556964b5c7a7bc144091cf9709/lua/lspconfig/util.lua#L230. This gets rid of the message and everything still works just fine.
This may not be the best solution. So, please let me know if I should be doing something different. Otherwise, I hope it helps others that may run into this.
local luadev = require("lua-dev").setup {
-- was either this or keep local nvim-lspconfig & suppress error
-- for sumneko_lua here:
-- https://github.com/neovim/nvim-lspconfig/blob/62b9e1a27dd0c9556964b5c7a7bc144091cf9709/lua/lspconfig/util.lua#L233
-- @TODOUA: watch for related changes in lua-dev and nvim-lspconfig
lspconfig = {
enabled = false,
},
}
local lspconfig = require "lspconfig"
lspconfig.sumneko_lua.setup(luadev)
As the title says:
~/.config/nvim/init.lua
(or any other Lua file in the config directory), then I'd like the LSP started with the additional configuration parameters that makes it awesome~/.config/awesome/rc.lua
or any other Lua file outside of neovim, then these settings don't apply and I'd like to use a different set.I'm not sure how to achieve this, do you have an idea?
First off thanks for making this plugin, even though I prefer to roll my own config your generated EmmyLua annotations are very, very, very useful. Looking around I couldn't seem to find an similar set of annotations for the LuaJIT's stdlib and was wondering if it is possible to also generate those as well.
Thanks for making this - from the screenshots, it looks super useful!
I'm wondering if there are any possible conflicts between this and other LSP plugins (e.g. lspsaga, lspkind, lsp-status, etc.). I have (I think) followed the setup instructions correctly, but the "documentation" I get (with nvim-compe) does not match the screenshots on this repo, so something is clearly wrong.
What I get looks something like:
So: do you know of any "gotchas" that might override or prevent lua-dev
from providing its documentation as expected?
I am trying to make this work with coc.nvim with no luck so far.
I have setup coc.nvim to use sumneko's LSP.
Do I have to use mentioned completions plugins (nvim-compe or completion-nvim) and nvim-lspconfig
to make this work? or it's possible to feed this plugins completions to coc.nvim?
I don't have any problems with it, but I noticed it when I was looking at the code.
You are handling $VIMRUNTIME separately in M.library in sumneko.lua, but $VIMRUNTIME is also included in vim.o.packpath. Is this the intended behavior?
Hello!
Recently every time I open up a .lua file I always get this error
LSP[sumneko_lua] Your workspace is set to '/home/zhifan'. Lua language server refused to load this directory. Please check your configura tion.[learn more here](https://github.com/sumneko/lua-language-server/wiki/Why-scanning-home-folder)
but I don't know how should I fix it.
The Language Server itself still works even if the message shows up
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.