aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRanjith Hegde <ranjithshegde@gmail.com>2022-08-23 16:03:20 +0200
committerGitHub <noreply@github.com>2022-08-23 07:03:20 -0700
commitfe7a6f41e59654db6bbc9eb2d084decc54b295e4 (patch)
treec7967bb5b649ad7f8f00c697bedc2f60db9e507a /test
parentRevert "docs: vim.lsp.buf.formatting() is deprecated #2077 (diff)
downloadnvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.gz
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.bz2
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.lz
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.xz
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.tar.zst
nvim-lspconfig-fe7a6f41e59654db6bbc9eb2d084decc54b295e4.zip
feat!: 0.7 API update (#1984)
* switch to lua api for autocommands * switch to nvim_create_user_command * move to lua plugin initialization NOTICE: Defining commands in server configurations will be deprecated in future releases. See `:help lspconfig.txt` to setup the same in an `on_attach` function. Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/lspconfig_spec.lua42
-rw-r--r--test/minimal_init.lua14
2 files changed, 47 insertions, 9 deletions
diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua
index 89effd47..f98568c1 100644
--- a/test/lspconfig_spec.lua
+++ b/test/lspconfig_spec.lua
@@ -32,7 +32,7 @@ describe('lspconfig', function()
ok(exec_lua [[
local lspconfig = require("lspconfig")
- local not_exist_dir = vim.fn.getcwd().."/not/exsts"
+ local not_exist_dir = vim.fn.getcwd().."/not/exists"
return lspconfig.util.path.exists(not_exist_dir) == false
]])
end)
@@ -76,7 +76,7 @@ describe('lspconfig', function()
ok(exec_lua [[
local lspconfig = require("lspconfig")
- local not_exist_dir = vim.fn.getcwd().."/not/exsts"
+ local not_exist_dir = vim.fn.getcwd().."/not/exists"
return not lspconfig.util.path.is_dir(not_exist_dir)
]])
end)
@@ -213,7 +213,43 @@ describe('lspconfig', function()
]])
end)
end)
+
+ describe('user commands', function()
+ it('should translate command definition to nvim_create_user_command options', function()
+ eq(
+ {
+ nargs = '*',
+ complete = 'custom,v:lua.some_global',
+ },
+ exec_lua [[
+ local util = require("lspconfig.util")
+ return util._parse_user_command_options({
+ function () end,
+ "-nargs=* -complete=custom,v:lua.some_global"
+ })
+ ]]
+ )
+
+ eq(
+ {
+ desc = 'My awesome description.',
+ nargs = '*',
+ complete = 'custom,v:lua.another_global',
+ },
+ exec_lua [[
+ local util = require("lspconfig.util")
+ return util._parse_user_command_options({
+ function () end,
+ ["-nargs"] = "*",
+ "-complete=custom,v:lua.another_global",
+ description = "My awesome description."
+ })
+ ]]
+ )
+ end)
+ end)
end)
+
describe('config', function()
it('normalizes user, server, and base default configs', function()
eq(
@@ -283,7 +319,7 @@ describe('lspconfig', function()
local _ = lspconfig.sumneko_lua
local _ = lspconfig.tsserver
lspconfig.rust_analyzer.setup {}
- return lspconfig.available_servers()
+ return require("lspconfig.util").available_servers()
]],
{ 'rust_analyzer' }
)
diff --git a/test/minimal_init.lua b/test/minimal_init.lua
index 8c7ad55a..ba2ae3fc 100644
--- a/test/minimal_init.lua
+++ b/test/minimal_init.lua
@@ -29,11 +29,9 @@ local function load_plugins()
}
end
-_G.load_config = function()
+local load_config = function()
vim.lsp.set_log_level 'trace'
- if vim.fn.has 'nvim-0.5.1' == 1 then
- require('vim.lsp.log').set_format_func(vim.inspect)
- end
+ require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
local function buf_set_option(...)
@@ -86,9 +84,13 @@ if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
load_plugins()
require('packer').sync()
- vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
+ local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true })
+ vim.api.nvim_create_autocmd(
+ 'User',
+ { pattern = 'PackerComplete', callback = load_config, group = packer_group, once = true }
+ )
else
load_plugins()
require('packer').sync()
- _G.load_config()
+ load_config()
end