aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/sumneko_lua.lua
blob: 3faca64486509820d88612620f43cf7ceb2171e4 (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'

local name = "sumneko_lua"
local bin_name = "lua-language-server"

local function make_installer()
  local P = util.path.join
  local install_dir = P{util.base_install_dir, name}
  local git_dir = P{install_dir, bin_name}
  local os, bin, ninja_zip, build_file

  if vim.fn.has('osx') == 1 then
    os = 'macOS'
    bin = P{git_dir, "bin", "macOS", bin_name}
    ninja_zip = "ninja-mac.zip"
    build_file = "macos.ninja"
  elseif vim.fn.has('unix') == 1 then
    os = 'Linux'
    bin = P{git_dir, "bin", "Linux", bin_name}
    ninja_zip = "ninja-linux.zip"
    build_file = "linux.ninja"
  end
  local main_file = P{git_dir, "main.lua"}
  local cmd = {bin, '-E', main_file}

  local X = {}
  function X.install()
    if os == nil then
      error("This installer supports Linux and macOS only")
      return
    end
    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", "clang") then
      error('Need the binaries "sh", "chmod", "unzip", "clang" to install this')
      return
    end
    local script = [=[
set -e
bin_name=]=]..bin_name..'\n'..[=[
ninja_zip=]=]..ninja_zip..'\n'..[=[
build_file=]=]..build_file..'\n'..[=[

# 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_zip
    unzip $ninja_zip
    chmod +x ninja
  }
  export PATH="$PWD:$PATH"
}

# clone project
git clone https://github.com/sumneko/$bin_name
cd $bin_name
git submodule update --init --recursive

# build
cd 3rd/luamake
ninja -f ninja/$build_file
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()

configs[name] = {
  default_config = {
    filetypes = {'lua'};
    root_dir = function(fname)
      return util.find_git_ancestor(fname) or vim.loop.os_homedir()
    end;
    log_level = vim.lsp.protocol.MessageType.Warning;
  };
  on_new_config = function(config)
    installer.configure(config)
  end;
  docs = {
    package_json = "https://raw.githubusercontent.com/sumneko/vscode-lua/master/package.json";
    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
and macOS using `:LspInstall`.  If you wish to install it yourself, [here is a
guide](https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)).
So you should set `cmd` yourself like this.

```lua
require'lspconfig'.sumneko_lua.setup{
  cmd = {"path", "to", "cmd"};
  ...
}
```

If you install via our installer, if you execute `:LspInstallInfo sumneko_lua`, you can know `cmd` value.
]];
    default_config = {
      root_dir = [[root_pattern(".git") or os_homedir]];
    };
  };
}

configs[name].install = installer.install
configs[name].install_info = installer.info
-- vim:et ts=2