-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
sumneko_lua.lua
102 lines (92 loc) · 2.7 KB
/
sumneko_lua.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
local skeleton = require 'nvim_lsp/skeleton'
local util = require 'nvim_lsp/util'
local vim = vim
local name = "sumneko_lua"
local function make_installer()
local P = util.path.join
local install_dir = P{util.base_install_dir, name}
local git_dir = P{install_dir, "lua-language-server"}
local bin = P{git_dir, "bin", "Linux", "lua-language-server"}
local main_file = P{git_dir, "main.lua"}
local cmd = {bin, '-E', main_file}
local X = {}
function X.install()
local install_info = X.info()
if install_info.is_installed then
print(name, "is already installed")
return
end
if not (util.has_bins("ninja") or util.has_bins("curl")) then
error('Need either "ninja" or "curl" (to download ninja) to install this.')
return
end
if not util.has_bins("sh", "chmod", "unzip") then
error('Need the binaries "sh", "chmod", "unzip" to install this')
return
end
local script = [=[
set -e
# Install ninja if not available.
which ninja >/dev/null || {
test -x ninja || {
curl -LO https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip
unzip ninja-linux.zip
chmod +x ninja
}
export PATH=$PWD:$PATH
}
# clone project
git clone https://github.com/sumneko/lua-language-server
cd lua-language-server
git submodule update --init --recursive
# build
cd 3rd/luamake
ninja -f ninja/linux.ninja
cd ../..
./3rd/luamake/luamake rebuild
]=]
vim.fn.mkdir(install_info.install_dir, "p")
util.sh(script, install_info.install_dir)
end
function X.info()
return {
is_installed = util.has_bins(bin);
install_dir = install_dir;
cmd = cmd;
}
end
function X.configure(config)
local install_info = X.info()
if install_info.is_installed then
config.cmd = cmd
end
end
return X
end
local installer = make_installer()
skeleton[name] = {
default_config = {
-- cmd = {'/home/ashkan/works/3rd/lua-language-server/run.sh'};
filetypes = {'lua'};
root_dir = function(fname)
return util.find_git_ancestor(fname) or vim.loop.os_homedir()
end;
on_new_config = function(config)
installer.configure(config)
end;
log_level = vim.lsp.protocol.MessageType.Warning;
settings = {};
};
docs = {
vspackage = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/sumneko/vsextensions/lua/latest/vspackage";
description = [[
https://github.com/sumneko/lua-language-server
Lua language server. **By default, this doesn't have a `cmd` set.** This is
because it doesn't provide a global binary. We provide an installer for Linux
using `:LspInstall`. If you wish to install it yourself, [here is a
guide](https://github.com/sumneko/lua-language-server/wiki/Build-and-Run).
]]
};
}
skeleton[name].install = installer.install
skeleton[name].install_info = installer.info