diff options
| author | William Boman <william@redwill.se> | 2021-09-01 10:29:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-01 10:29:23 +0200 |
| commit | bfbf5fbd39fa75847bf23da2c46d12fe2728fb78 (patch) | |
| tree | f05d2f041f895ff639684c10f57d19f1d4a433e0 | |
| parent | README: simplify example a bit, add clarifying comment (diff) | |
| download | mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.gz mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.bz2 mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.lz mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.xz mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.tar.zst mason-bfbf5fbd39fa75847bf23da2c46d12fe2728fb78.zip | |
add Windows support (#70)
40 files changed, 343 insertions, 197 deletions
@@ -17,9 +17,7 @@ On top of just providing commands for installing & uninstalling LSP servers, it: - provides Lua APIs for non-standard LSP functionalities, for example `_typescript.applyRenameFile` - has support for a variety of different install methods (e.g., [google/zx](https://github.com/google/zx)) - common install tasks are abstracted behind Lua APIs -- provides adapters that offer out-of-the-box integrations with other plugins - -Inspired by [nvim-lspinstall](https://github.com/kabouzeid/nvim-lspinstall). +- <img src="https://user-images.githubusercontent.com/6705160/131256603-cacf7f66-dfa9-4515-8ae4-0e42d08cfc6a.png" height="20"> supports Windows for a majority of server installations ## Installation diff --git a/lua/nvim-lsp-installer/dispatcher.lua b/lua/nvim-lsp-installer/dispatcher.lua index c8ec34a7..036c6d91 100644 --- a/lua/nvim-lsp-installer/dispatcher.lua +++ b/lua/nvim-lsp-installer/dispatcher.lua @@ -12,10 +12,9 @@ local idx = 0 function M.register_server_ready_callback(callback) local key = idx + 1 registered_callbacks[("%d"):format(key)] = callback - return function () + return function() table.remove(registered_callbacks, key) end end - return M diff --git a/lua/nvim-lsp-installer/installers/go.lua b/lua/nvim-lsp-installer/installers/go.lua index 1f1b730f..9c9a1ad5 100644 --- a/lua/nvim-lsp-installer/installers/go.lua +++ b/lua/nvim-lsp-installer/installers/go.lua @@ -5,13 +5,16 @@ local M = {} function M.packages(packages) return function(server, callback) - local shell_installer = shell.raw(("go get -v %s; go clean -modcache;"):format(table.concat(packages, " ")), { - env = { - GO111MODULE = "on", - GOBIN = server._root_dir, - GOPATH = server._root_dir, - }, - }) + local shell_installer = shell.polyshell( + ("go get -v %s && go clean -modcache"):format(table.concat(packages, " ")), + { + env = { + GO111MODULE = "on", + GOBIN = server._root_dir, + GOPATH = server._root_dir, + }, + } + ) shell_installer(server, callback) end diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua index e9d99138..f394a33d 100644 --- a/lua/nvim-lsp-installer/installers/init.lua +++ b/lua/nvim-lsp-installer/installers/init.lua @@ -1,3 +1,5 @@ +local platform = require "nvim-lsp-installer.platform" + local M = {} function M.compose(installers) @@ -25,4 +27,24 @@ function M.compose(installers) end end +function M.when(platform_table) + return function(server, callback) + if platform.is_unix() then + if platform_table.unix then + platform_table.unix(server, callback) + else + callback(false, ("Unix is not yet supported for server %q."):format(server.name)) + end + elseif platform.is_win() then + if platform_table.win then + platform_table.win(server, callback) + else + callback(false, ("Windows is not yet supported for server %q."):format(server.name)) + end + else + callback(false, "installers.when: Could not find installer for current platform.") + end + end +end + return M diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua index 02c2f533..6b6b820e 100644 --- a/lua/nvim-lsp-installer/installers/npm.lua +++ b/lua/nvim-lsp-installer/installers/npm.lua @@ -1,14 +1,20 @@ local path = require "nvim-lsp-installer.path" +local platform = require "nvim-lsp-installer.platform" local shell = require "nvim-lsp-installer.installers.shell" local M = {} function M.packages(packages) - return shell.raw(("npm install %s"):format(table.concat(packages, " "))) + return shell.polyshell(("npm install %s"):format(table.concat(packages, " "))) end function M.executable(root_dir, executable) - return path.concat { root_dir, "node_modules", ".bin", executable } + return path.concat { + root_dir, + "node_modules", + ".bin", + platform.is_win() and ("%s.cmd"):format(executable) or executable, + } end return M diff --git a/lua/nvim-lsp-installer/installers/pip3.lua b/lua/nvim-lsp-installer/installers/pip3.lua index 62996196..79fbb0f7 100644 --- a/lua/nvim-lsp-installer/installers/pip3.lua +++ b/lua/nvim-lsp-installer/installers/pip3.lua @@ -1,4 +1,5 @@ local path = require "nvim-lsp-installer.path" +local platform = require "nvim-lsp-installer.platform" local shell = require "nvim-lsp-installer.installers.shell" local M = {} @@ -6,13 +7,20 @@ local M = {} local REL_INSTALL_DIR = "venv" function M.packages(packages) - return shell.raw(("./%s/bin/pip3 install -U %s"):format(REL_INSTALL_DIR, table.concat(packages, " ")), { - prefix = ("set -euo pipefail; python3 -m venv %q;"):format(REL_INSTALL_DIR), - }) + local venv_activate_cmd = platform.is_win() and (".\\%s\\Scripts\\activate"):format(REL_INSTALL_DIR) + or ("source ./%s/bin/activate"):format(REL_INSTALL_DIR) + + return shell.polyshell( + ("python3 -m venv %q && %s && pip3 install -U %s"):format( + REL_INSTALL_DIR, + venv_activate_cmd, + table.concat(packages, " ") + ) + ) end function M.executable(root_dir, executable) - return path.concat { root_dir, REL_INSTALL_DIR, "bin", executable } + return path.concat { root_dir, REL_INSTALL_DIR, platform.is_win() and "Scripts" or "bin", executable } end return M diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua index bfdb5dea..98f12103 100644 --- a/lua/nvim-lsp-installer/installers/shell.lua +++ b/lua/nvim-lsp-installer/installers/shell.lua @@ -1,11 +1,8 @@ -local M = {} +local installers = require "nvim-lsp-installer.installers" -local default_opts = { - prefix = "set -euo pipefail;", -} +local M = {} -function M.raw(raw_script, opts) - opts = opts or {} +local function termopen(opts) return function(server, callback) local jobstart_opts = { cwd = server._root_dir, @@ -18,22 +15,61 @@ function M.raw(raw_script, opts) end, } - if type(opts.env) == "table" and vim.tbl_count(opts.env) then + if type(opts.env) == "table" and vim.tbl_count(opts.env) > 0 then -- passing an empty Lua table causes E475, for whatever reason jobstart_opts.env = opts.env end - local shell = vim.o.shell - vim.o.shell = "/bin/bash" + local orig_shell = vim.o.shell + vim.o.shell = opts.shell vim.cmd [[new]] - vim.fn.termopen((opts.prefix or default_opts.prefix) .. raw_script, jobstart_opts) - vim.o.shell = shell + vim.fn.termopen(opts.cmd, jobstart_opts) + vim.o.shell = orig_shell vim.cmd [[startinsert]] -- so that we tail the term log nicely ¯\_(ツ)_/¯ end end -function M.remote(url, opts) - return M.raw(("wget -nv -O - %q | bash"):format(url), opts) +function M.bash(raw_script, opts) + local default_opts = { + prefix = "set -euo pipefail;", + env = {}, + } + opts = vim.tbl_deep_extend("force", default_opts, opts or {}) + + return termopen { + shell = "/bin/bash", + cmd = (opts.prefix or "") .. raw_script, + env = opts.env, + } +end + +function M.remote_bash(url, opts) + return M.bash(("wget -nv -O - %q | bash"):format(url), opts) +end + +function M.cmd(raw_script, opts) + local default_opts = { + env = {}, + } + opts = vim.tbl_deep_extend("force", default_opts, opts or {}) + + return termopen { + shell = "cmd.exe", + cmd = raw_script, + env = opts.env, + } +end + +function M.polyshell(raw_script, opts) + local default_opts = { + env = {}, + } + opts = vim.tbl_deep_extend("force", default_opts, opts or {}) + + return installers.when { + unix = M.bash(raw_script, { env = opts.env }), + win = M.cmd(raw_script, { env = opts.env }), + } end return M diff --git a/lua/nvim-lsp-installer/installers/zx.lua b/lua/nvim-lsp-installer/installers/zx.lua index 5308ac66..b713b4ec 100644 --- a/lua/nvim-lsp-installer/installers/zx.lua +++ b/lua/nvim-lsp-installer/installers/zx.lua @@ -2,6 +2,7 @@ local fs = require "nvim-lsp-installer.fs" local path = require "nvim-lsp-installer.path" local notify = require "nvim-lsp-installer.notify" local installers = require "nvim-lsp-installer.installers" +local platform = require "nvim-lsp-installer.platform" local shell = require "nvim-lsp-installer.installers.shell" local npm = require "nvim-lsp-installer.installers.npm" @@ -37,8 +38,8 @@ local function zx_installer(force) fs.mkdirp(INSTALL_DIR) - uv.spawn( - "npm", + local handle, pid = uv.spawn( + platform.is_win() and "npm.cmd" or "npm", { args = { npm_command, "zx@1" }, cwd = INSTALL_DIR, @@ -53,13 +54,17 @@ local function zx_installer(force) callback(true, nil) end) ) + + if handle == nil then + callback(false, ("Failed to install/update zx. %s"):format(pid)) + end end end function M.file(relpath) local script_path = path.realpath(relpath, 3) return installers.compose { - shell.raw(("%q %q"):format(ZX_EXECUTABLE, script_path)), + shell.polyshell(("%q %q"):format(ZX_EXECUTABLE, ("file:///%s"):format(script_path))), zx_installer(false), } end diff --git a/lua/nvim-lsp-installer/path.lua b/lua/nvim-lsp-installer/path.lua index 25498beb..4ed3d563 100644 --- a/lua/nvim-lsp-installer/path.lua +++ b/lua/nvim-lsp-installer/path.lua @@ -32,11 +32,12 @@ end -- @return The realpath (absolute path). Note that this will currently produce results such as /Users/zuck/./script.js which may not be compatible with some tools. function M.realpath(relpath, depth) local callsite_abs_path = debug.getinfo(depth or 2, "S").source:sub(2) - return M.concat { vim.fn.fnamemodify(callsite_abs_path, ":h"), relpath } + local normalized_relpath = relpath:gsub("./", "") + return M.concat { vim.fn.fnamemodify(callsite_abs_path, ":h"), normalized_relpath } end function M.is_subdirectory(root_path, path) - return path:find(root_path) == 1 + return path:sub(1, #root_path) == root_path end M.SERVERS_ROOT_DIR = M.concat { vim.fn.stdpath "data", "lsp_servers" } diff --git a/lua/nvim-lsp-installer/platform.lua b/lua/nvim-lsp-installer/platform.lua new file mode 100644 index 00000000..0b327cf2 --- /dev/null +++ b/lua/nvim-lsp-installer/platform.lua @@ -0,0 +1,11 @@ +local M = {} + +function M.is_win() + return vim.fn.has "win32" == 1 +end + +function M.is_unix() + return vim.fn.has "unix" == 1 +end + +return M diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index 5aa75825..d760f643 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -53,7 +53,7 @@ function M.Server:setup(opts) -- We require the lspconfig server here in order to do it as late as possible. -- The reason for this is because once a lspconfig server has been imported, it's -- automatically registered with lspconfig and causes it to show up in :LspInfo and whatnot. - require("lspconfig")[self.name].setup(vim.tbl_deep_extend("force", self._default_options, opts)) + require("lspconfig")[self.name].setup(vim.tbl_deep_extend("force", self._default_options, opts or {})) if self._post_setup then self._post_setup() end diff --git a/lua/nvim-lsp-installer/servers/ansiblels/init.lua b/lua/nvim-lsp-installer/servers/ansiblels/init.lua index 430d55b8..b6899b70 100644 --- a/lua/nvim-lsp-installer/servers/ansiblels/init.lua +++ b/lua/nvim-lsp-installer/servers/ansiblels/init.lua @@ -1,5 +1,6 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" local shell = require "nvim-lsp-installer.installers.shell" local root_dir = server.get_server_root_path "ansiblels" @@ -7,12 +8,14 @@ local root_dir = server.get_server_root_path "ansiblels" return server.Server:new { name = "ansiblels", root_dir = root_dir, - installer = shell.raw [[ - git clone --depth 1 https://github.com/ansible/ansible-language-server .; - npm install; - npm run build; - npm install --production; - ]], + installer = installers.when { + unix = shell.bash [[ + git clone --depth 1 https://github.com/ansible/ansible-language-server .; + npm install; + npm run build; + npm install --production; + ]], + }, default_options = { filetypes = { "yaml", "yaml.ansible" }, cmd = { "node", path.concat { root_dir, "out", "server", "src", "server.js" }, "--stdio" }, diff --git a/lua/nvim-lsp-installer/servers/clangd/init.lua b/lua/nvim-lsp-installer/servers/clangd/init.lua index f5a163f6..6028af24 100644 --- a/lua/nvim-lsp-installer/servers/clangd/init.lua +++ b/lua/nvim-lsp-installer/servers/clangd/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "c-family" return server.Server:new { name = "clangd", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, default_options = { cmd = { path.concat { root_dir, "clangd", "bin", "clangd" } }, }, diff --git a/lua/nvim-lsp-installer/servers/clangd/install.mjs b/lua/nvim-lsp-installer/servers/clangd/install.mjs index 36a7a69d..048a33c2 100644 --- a/lua/nvim-lsp-installer/servers/clangd/install.mjs +++ b/lua/nvim-lsp-installer/servers/clangd/install.mjs @@ -3,10 +3,6 @@ const VERSION = "12.0.0"; const target = (() => { const platform = os.platform(); switch (platform) { - case "win32": { - console.error(chalk.red(`${platform} is not yet supported.`)); - process.exit(1); - } case "darwin": return `clangd-mac-${VERSION}.zip`; default: diff --git a/lua/nvim-lsp-installer/servers/clojure_lsp/init.lua b/lua/nvim-lsp-installer/servers/clojure_lsp/init.lua index 6f54129e..8f22b676 100644 --- a/lua/nvim-lsp-installer/servers/clojure_lsp/init.lua +++ b/lua/nvim-lsp-installer/servers/clojure_lsp/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "clojure_lsp" return server.Server:new { name = "clojure_lsp", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, default_options = { cmd = { path.concat { root_dir, "clojure-lsp" } }, }, diff --git a/lua/nvim-lsp-installer/servers/clojure_lsp/install.mjs b/lua/nvim-lsp-installer/servers/clojure_lsp/install.mjs index 29cbb77b..049e983c 100644 --- a/lua/nvim-lsp-installer/servers/clojure_lsp/install.mjs +++ b/lua/nvim-lsp-installer/servers/clojure_lsp/install.mjs @@ -1,20 +1,9 @@ const VERSION = "2021.07.01-19.49.02"; -const exitNotSupported = () => { - console.error( - chalk.red(`${os.platform()} ${os.arch()} is currently not supported.`) - ); - process.exit(1); -}; - const target = (() => { switch (os.platform()) { case "darwin": return "clojure-lsp-native-macos-amd64.zip"; - case "win32": { - exitNotSupported(); - break; - } default: return "clojure-lsp-native-linux-amd64.zip"; } diff --git a/lua/nvim-lsp-installer/servers/denols/init.lua b/lua/nvim-lsp-installer/servers/denols/init.lua index 3ab7a8e2..94588564 100644 --- a/lua/nvim-lsp-installer/servers/denols/init.lua +++ b/lua/nvim-lsp-installer/servers/denols/init.lua @@ -1,5 +1,6 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" local shell = require "nvim-lsp-installer.installers.shell" local root_dir = server.get_server_root_path "denols" @@ -7,11 +8,13 @@ local root_dir = server.get_server_root_path "denols" return server.Server:new { name = "denols", root_dir = root_dir, - installer = shell.remote("https://deno.land/x/install/install.sh", { - env = { - DENO_INSTALL = root_dir, - }, - }), + installer = installers.when { + unix = shell.remote_bash("https://deno.land/x/install/install.sh", { + env = { + DENO_INSTALL = root_dir, + }, + }), + }, default_options = { cmd = { path.concat { root_dir, "bin", "deno" }, "lsp" }, }, diff --git a/lua/nvim-lsp-installer/servers/elixirls/init.lua b/lua/nvim-lsp-installer/servers/elixirls/init.lua index 5fa5e408..d84f4f38 100644 --- a/lua/nvim-lsp-installer/servers/elixirls/init.lua +++ b/lua/nvim-lsp-installer/servers/elixirls/init.lua @@ -1,5 +1,6 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" local shell = require "nvim-lsp-installer.installers.shell" local root_dir = server.get_server_root_path "elixir" @@ -7,12 +8,14 @@ local root_dir = server.get_server_root_path "elixir" return server.Server:new { name = "elixirls", root_dir = root_dir, - installer = shell.raw [[ - wget -O elixir-ls.zip https://github.com/elixir-lsp/elixir-ls/releases/download/v0.7.0/elixir-ls.zip; - unzip elixir-ls.zip -d elixir-ls; - rm elixir-ls.zip; - chmod +x elixir-ls/language_server.sh; - ]], + installer = installers.when { + unix = shell.bash [[ + wget -O elixir-ls.zip https://github.com/elixir-lsp/elixir-ls/releases/download/v0.7.0/elixir-ls.zip; + unzip elixir-ls.zip -d elixir-ls; + rm elixir-ls.zip; + chmod +x elixir-ls/language_server.sh; + ]], + }, default_options = { cmd = { path.concat { root_dir, "elixir-ls", "language_server.sh" } }, }, diff --git a/lua/nvim-lsp-installer/servers/eslintls/init.lua b/lua/nvim-lsp-installer/servers/eslintls/init.lua index 91f91012..1d0c874b 100644 --- a/lua/nvim-lsp-installer/servers/eslintls/init.lua +++ b/lua/nvim-lsp-installer/servers/eslintls/init.lua @@ -11,18 +11,11 @@ local ConfirmExecutionResult = { } local root_dir = server.get_server_root_path "eslint" -local install_cmd = [[ -git clone --depth 1 https://github.com/microsoft/vscode-eslint .; -npm install; -cd server; -npm install; -../node_modules/.bin/tsc; -]] return server.Server:new { name = "eslintls", root_dir = root_dir, - installer = shell.raw(install_cmd), + installer = shell.polyshell [[ git clone --depth 1 https://github.com/microsoft/vscode-eslint . && npm install && npm run compile:server ]], pre_setup = function() local lspconfig = require "lspconfig" local configs = require "lspconfig/configs" diff --git a/lua/nvim-lsp-installer/servers/groovyls/init.lua b/lua/nvim-lsp-installer/servers/groovyls/init.lua index 357992a1..f885d933 100644 --- a/lua/nvim-lsp-installer/servers/groovyls/init.lua +++ b/lua/nvim-lsp-installer/servers/groovyls/init.lua @@ -1,5 +1,6 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" local shell = require "nvim-lsp-installer.installers.shell" local root_dir = server.get_server_root_path "groovyls" @@ -12,11 +13,11 @@ return server.Server:new { error "Missing a Javac installation." end end, - installer = shell.raw [[ - git clone --depth 1 https://github.com/GroovyLanguageServer/groovy-language-server .; - ./gradlew build; - ]], + installer = installers.when { + unix = shell.bash [[ git clone --depth 1 https://github.com/GroovyLanguageServer/groovy-language-server . && ./gradlew build ]], + win = shell.cmd [[ git clone --depth 1 https://github.com/GroovyLanguageServer/groovy-language-server . && .\gradlew build ]], + }, default_options = { - cmd = { "java", "-jar", path.concat { root_dir, "groovy-language-server-all.jar" } }, + cmd = { "java", "-jar", path.concat { root_dir, "build", "libs", "groovyls-all.jar" } }, }, } diff --git a/lua/nvim-lsp-installer/servers/hls/init.lua b/lua/nvim-lsp-installer/servers/hls/init.lua index b19d4a39..2ce227f9 100644 --- a/lua/nvim-lsp-installer/servers/hls/init.lua +++ b/lua/nvim-lsp-installer/servers/hls/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "haskell" return server.Server:new { name = "hls", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, default_options = { cmd = { path.concat { root_dir, "hls" } }, }, diff --git a/lua/nvim-lsp-installer/servers/hls/install.mjs b/lua/nvim-lsp-installer/servers/hls/install.mjs index d711fdec..c9460e7c 100644 --- a/lua/nvim-lsp-installer/servers/hls/install.mjs +++ b/lua/nvim-lsp-installer/servers/hls/install.mjs @@ -3,10 +3,6 @@ const VERSION = "1.3.0"; const target = (() => { const platform = os.platform(); switch (platform) { - case "win32": { - console.error(chalk.red(`${platform} is not yet supported.`)); - process.exit(1); - } case "darwin": return `haskell-language-server-macOS-${VERSION}.tar.gz`; default: diff --git a/lua/nvim-lsp-installer/servers/kotlin_language_server/init.lua b/lua/nvim-lsp-installer/servers/kotlin_language_server/init.lua index 8aaf77de..b402fa8e 100644 --- a/lua/nvim-lsp-installer/servers/kotlin_language_server/init.lua +++ b/lua/nvim-lsp-installer/servers/kotlin_language_server/init.lua @@ -1,5 +1,7 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" +local platform = require "nvim-lsp-installer.platform" local shell = require "nvim-lsp-installer.installers.shell" local root_dir = server.get_server_root_path "kotlin" @@ -7,12 +9,22 @@ local root_dir = server.get_server_root_path "kotlin" return server.Server:new { name = "kotlin_language_server", root_dir = root_dir, - installer = shell.raw [[ - wget -O server.zip https://github.com/fwcd/kotlin-language-server/releases/latest/download/server.zip; - unzip server.zip; - rm server.zip; - ]], + installer = installers.when { + unix = shell.bash [[ + wget -O server.zip https://github.com/fwcd/kotlin-language-server/releases/latest/download/server.zip; + unzip server.zip; + rm server.zip; + ]], + win = shell.cmd [[ curl -fLo server.zip https://github.com/fwcd/kotlin-language-server/releases/latest/download/server.zip && tar -xvf server.zip && del /f server.zip ]], + }, default_options = { - cmd = { path.concat { root_dir, "server", "bin", "kotlin-language-server" } }, + cmd = { + path.concat { + root_dir, + "server", + "bin", + platform.is_win() and "kotlin-language-server.bat" or "kotlin-language-server", + }, + }, }, } diff --git a/lua/nvim-lsp-installer/servers/omnisharp/common.mjs b/lua/nvim-lsp-installer/servers/omnisharp/common.mjs new file mode 100644 index 00000000..cd41b089 --- /dev/null +++ b/lua/nvim-lsp-installer/servers/omnisharp/common.mjs @@ -0,0 +1,35 @@ +const VERSION = "v1.37.11"; + +const exitNotSupported = () => { + console.error(chalk.red(`${os.platform()} ${os.arch()} is currently not supported.`)); + process.exit(1); +}; + +export const getDownloadUrl = () => { + const target = (() => { + switch (os.platform()) { + case "darwin": + return "omnisharp-osx.zip"; + case "win32": + switch (os.arch()) { + case "arm64": + return "omnisharp-win-arm64.zip"; + case "x64": + return "omnisharp-win-x64.zip"; + default: + return exitNotSupported(); + } + default: + switch (os.arch()) { + case "arm64": + return exitNotSupported(); + case "x64": + return "omnisharp-linux-x64.zip"; + default: + return exitNotSupported(); + } + } + })(); + + return `https://github.com/OmniSharp/omnisharp-roslyn/releases/download/${VERSION}/${target}`; +}; diff --git a/lua/nvim-lsp-installer/servers/omnisharp/init.lua b/lua/nvim-lsp-installer/servers/omnisharp/init.lua index 5b108a58..b9bafa50 100644 --- a/lua/nvim-lsp-installer/servers/omnisharp/init.lua +++ b/lua/nvim-lsp-installer/servers/omnisharp/init.lua @@ -1,4 +1,6 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" +local platform = require "nvim-lsp-installer.platform" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,10 +9,14 @@ local root_dir = server.get_server_root_path "omnisharp" return server.Server:new { name = "omnisharp", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + win = zx.file "./install.win.mjs", + }, default_options = { cmd = { - path.concat { root_dir, "omnisharp", "run" }, + platform.is_win() and path.concat { root_dir, "OmniSharp.exe" } + or path.concat { root_dir, "omnisharp", "run" }, "--languageserver", "--hostPID", tostring(vim.fn.getpid()), diff --git a/lua/nvim-lsp-installer/servers/omnisharp/install.mjs b/lua/nvim-lsp-installer/servers/omnisharp/install.mjs index eba881f0..14d705b3 100644 --- a/lua/nvim-lsp-installer/servers/omnisharp/install.mjs +++ b/lua/nvim-lsp-installer/servers/omnisharp/install.mjs @@ -1,28 +1,6 @@ -const VERSION = "v1.37.11"; +import { getDownloadUrl } from "./common.mjs"; -const exitNotSupported = () => { - console.error( - chalk.red(`${os.platform()} ${os.arch()} is currently not supported.`) - ); - process.exit(1); -}; - -const target = (() => { - switch (os.platform()) { - case "win32": { - exitNotSupported(); - break; - } - case "darwin": - return "omnisharp-osx.zip"; - default: - return "omnisharp-linux-x64.zip"; - } -})(); - -const downloadUrl = `https://github.com/OmniSharp/omnisharp-roslyn/releases/download/${VERSION}/${target}`; - -await $`wget -O omnisharp.zip ${downloadUrl}`; +await $`wget -O omnisharp.zip ${getDownloadUrl()}`; await $`unzip omnisharp.zip -d omnisharp`; await $`chmod +x omnisharp/run`; await $`rm omnisharp.zip`; diff --git a/lua/nvim-lsp-installer/servers/omnisharp/install.win.mjs b/lua/nvim-lsp-installer/servers/omnisharp/install.win.mjs new file mode 100644 index 00000000..286c60f5 --- /dev/null +++ b/lua/nvim-lsp-installer/servers/omnisharp/install.win.mjs @@ -0,0 +1,10 @@ +import { getDownloadUrl } from "./common.mjs"; + +// TODO: can this be... less hacky? +$.shell = "powershell.exe"; +$.prefix = ""; +$.quote = (a) => a; + +await $`wget -O omnisharp.zip ${getDownloadUrl()}`; +await $`tar -xvf omnisharp.zip`; +await $`rm omnisharp.zip`; diff --git a/lua/nvim-lsp-installer/servers/rust_analyzer/common.mjs b/lua/nvim-lsp-installer/servers/rust_analyzer/common.mjs new file mode 100644 index 00000000..0f54a71e --- /dev/null +++ b/lua/nvim-lsp-installer/servers/rust_analyzer/common.mjs @@ -0,0 +1,41 @@ +export const VERSION = "2021-06-28"; + +const exitNotSupported = () => { + console.error(chalk.red(`${os.platform()} ${os.arch()} is currently not supported.`)); + process.exit(1); +}; + +export const getDownloadUrl = () => { + const target = (() => { + switch (os.platform()) { + case "win32": { + switch (os.arch()) { + case "arm64": + return "rust-analyzer-aarch64-pc-windows-msvc.gz"; + case "x64": + return "rust-analyzer-x86_64-pc-windows-msvc.gz"; + default: + return exitNotSupported(); + } + } + case "darwin": + switch (os.arch()) { + case "arm64": + return "rust-analyzer-aarch64-apple-darwin.gz"; + case "x64": + return "rust-analyzer-x86_64-apple-darwin.gz"; + default: + return exitNotSupported(); + } + default: + switch (os.arch()) { + case "arm64": + return "rust-analyzer-aarch64-unknown-linux-gnu.gz"; + default: + return "rust-analyzer-x86_64-unknown-linux-gnu.gz"; + } + } + })(); + + return `https://github.com/rust-analyzer/rust-analyzer/releases/download/${VERSION}/${target}`; +}; diff --git a/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua b/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua index 6502ee07..58cb53e2 100644 --- a/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua +++ b/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,10 @@ local root_dir = server.get_server_root_path "rust" return server.Server:new { name = "rust_analyzer", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + win = zx.file "./install.win.mjs", + }, default_options = { cmd = { path.concat { root_dir, "rust-analyzer" } }, }, diff --git a/lua/nvim-lsp-installer/servers/rust_analyzer/install.mjs b/lua/nvim-lsp-installer/servers/rust_analyzer/install.mjs index 7e976850..4d3fec85 100644 --- a/lua/nvim-lsp-installer/servers/rust_analyzer/install.mjs +++ b/lua/nvim-lsp-installer/servers/rust_analyzer/install.mjs @@ -1,41 +1,5 @@ -const VERSION = "2021-06-28"; +import { getDownloadUrl } from "./common.mjs"; -const exitNotSupported = () => { - console.error( - chalk.red(`${os.platform()} ${os.arch()} is currently not supported.`) - ); - process.exit(1); -}; - -const target = (() => { - switch (os.platform()) { - case "win32": { - exitNotSupported(); - break; - } - case "darwin": - switch (os.arch()) { - case "arm64": - return "rust-analyzer-aarch64-apple-darwin.gz"; - case "x64": - return "rust-analyzer-x86_64-apple-darwin.gz"; - default: { - exitNotSupported(); - break; - } - } - default: - switch (os.arch()) { - case "arm64": - return "rust-analyzer-aarch64-unknown-linux-gnu.gz"; - default: - return "rust-analyzer-x86_64-unknown-linux-gnu.gz"; - } - } -})(); - -const downloadUrl = `https://github.com/rust-analyzer/rust-analyzer/releases/download/${VERSION}/${target}`; - -await $`wget -O rust-analyzer.gz ${downloadUrl}`; -await $`gunzip rust-analyzer.gz`; +await $`wget -O rust-analyzer.gz ${getDownloadUrl()}`; +await $`gzip -fd rust-analyzer.gz`; await $`chmod +x rust-analyzer`; diff --git a/lua/nvim-lsp-installer/servers/rust_analyzer/install.win.mjs b/lua/nvim-lsp-installer/servers/rust_analyzer/install.win.mjs new file mode 100644 index 00000000..22ad75f7 --- /dev/null +++ b/lua/nvim-lsp-installer/servers/rust_analyzer/install.win.mjs @@ -0,0 +1,9 @@ +import { getDownloadUrl } from "./common.mjs"; + +// TODO: can this be... less hacky? +$.shell = "powershell.exe"; +$.prefix = ""; +$.quote = (a) => a; + +await $`wget -O rust-analyzer.exe.gz ${getDownloadUrl()}`; +await $`gzip -fd rust-analyzer.exe.gz`; diff --git a/lua/nvim-lsp-installer/servers/solargraph/init.lua b/lua/nvim-lsp-installer/servers/solargraph/init.lua index fdad4861..d23b029e 100644 --- a/lua/nvim-lsp-installer/servers/solargraph/init.lua +++ b/lua/nvim-lsp-installer/servers/solargraph/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "ruby" return server.Server:new { name = "solargraph", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, pre_install_check = function() if vim.fn.executable "bundle" ~= 1 then error "bundle not installed" diff --git a/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua b/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua index bda3718c..7ad00ebe 100644 --- a/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua +++ b/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -13,7 +14,9 @@ local bin_dir = uname_alias[uname] or uname return server.Server:new { name = "sumneko_lua", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, pre_install_check = function() if vim.fn.executable "ninja" ~= 1 then error "ninja not installed (see https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)" diff --git a/lua/nvim-lsp-installer/servers/sumneko_lua/install.mjs b/lua/nvim-lsp-installer/servers/sumneko_lua/install.mjs index 0673e6f2..3f2d20e0 100644 --- a/lua/nvim-lsp-installer/servers/sumneko_lua/install.mjs +++ b/lua/nvim-lsp-installer/servers/sumneko_lua/install.mjs @@ -3,18 +3,14 @@ await $`git submodule update --init --recursive`; cd("3rd/luamake"); switch (os.platform()) { - case "darwin": { - await $`ninja -f compile/ninja/macos.ninja`; - break; - } - case "win32": { - console.error(chalk.red("Windows is currently not supported.")); - process.exit(1); - } - default: { - await $`ninja -f compile/ninja/linux.ninja`; - break; - } + case "darwin": { + await $`ninja -f compile/ninja/macos.ninja`; + break; + } + default: { + await $`ninja -f compile/ninja/linux.ninja`; + break; + } } cd("."); diff --git a/lua/nvim-lsp-installer/servers/tailwindcss/init.lua b/lua/nvim-lsp-installer/servers/tailwindcss/init.lua index e4056771..cf76d0b0 100644 --- a/lua/nvim-lsp-installer/servers/tailwindcss/init.lua +++ b/lua/nvim-lsp-installer/servers/tailwindcss/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "tailwindcss" return server.Server:new { name = "tailwindcss", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, default_options = { cmd = { "node", diff --git a/lua/nvim-lsp-installer/servers/terraformls/init.lua b/lua/nvim-lsp-installer/servers/terraformls/init.lua index 1fce1669..5df3cecc 100644 --- a/lua/nvim-lsp-installer/servers/terraformls/init.lua +++ b/lua/nvim-lsp-installer/servers/terraformls/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "terraform" return server.Server:new { name = "terraformls", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, default_options = { cmd = { path.concat { root_dir, "terraform-ls", "terraform-ls" }, "serve" }, }, diff --git a/lua/nvim-lsp-installer/servers/terraformls/install.mjs b/lua/nvim-lsp-installer/servers/terraformls/install.mjs index 7e642757..04efc288 100644 --- a/lua/nvim-lsp-installer/servers/terraformls/install.mjs +++ b/lua/nvim-lsp-installer/servers/terraformls/install.mjs @@ -7,10 +7,6 @@ const exitNotSupported = () => { const target = (() => { switch (os.platform()) { - case "win32": { - exitNotSupported(); - break; - } case "darwin": switch (os.arch()) { case "arm64": diff --git a/lua/nvim-lsp-installer/servers/texlab/init.lua b/lua/nvim-lsp-installer/servers/texlab/init.lua index 2e3eeea3..c669806b 100644 --- a/lua/nvim-lsp-installer/servers/texlab/init.lua +++ b/lua/nvim-lsp-installer/servers/texlab/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local zx = require "nvim-lsp-installer.installers.zx" @@ -7,7 +8,9 @@ local root_dir = server.get_server_root_path "latex" return server.Server:new { name = "texlab", root_dir = root_dir, - installer = zx.file "./install.mjs", + installer = installers.when { + unix = zx.file "./install.mjs", + }, pre_install_check = function() if vim.fn.executable "wget" ~= 1 then error "Missing wget. Please, refer to https://www.gnu.org/software/wget/ to install it." diff --git a/lua/nvim-lsp-installer/servers/texlab/install.mjs b/lua/nvim-lsp-installer/servers/texlab/install.mjs index dbf77e11..bc7fefe1 100644 --- a/lua/nvim-lsp-installer/servers/texlab/install.mjs +++ b/lua/nvim-lsp-installer/servers/texlab/install.mjs @@ -1,4 +1,4 @@ -const VERSION = "v3.2.0" +const VERSION = "v3.2.0"; const platform = os.platform(); @@ -6,16 +6,11 @@ const target = (() => { switch (platform) { case "darwin": return `https://github.com/latex-lsp/texlab/releases/download/${VERSION}/texlab-x86_64-macos.tar.gz`; - case "win32": { - console.error(chalk.red("Windows is currently not supported.")); - process.exit(1); - break; - } default: return `https://github.com/latex-lsp/texlab/releases/download/${VERSION}/texlab-x86_64-linux.tar.gz`; } })(); -await $`wget -O texlab.tar.gz ${target}` -await $`tar xf texlab.tar.gz` -await $`rm texlab.tar.gz` +await $`wget -O texlab.tar.gz ${target}`; +await $`tar xf texlab.tar.gz`; +await $`rm texlab.tar.gz`; diff --git a/lua/nvim-lsp-installer/servers/tflint/init.lua b/lua/nvim-lsp-installer/servers/tflint/init.lua index 396f1cf9..51de105e 100644 --- a/lua/nvim-lsp-installer/servers/tflint/init.lua +++ b/lua/nvim-lsp-installer/servers/tflint/init.lua @@ -1,6 +1,7 @@ local server = require "nvim-lsp-installer.server" local notify = require "nvim-lsp-installer.notify" local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" local shell = require "nvim-lsp-installer.installers.shell" local root_dir = server.get_server_root_path "tflint" @@ -10,12 +11,14 @@ local bin_path = path.concat { root_dir, "tflint" } return server.Server:new { name = "tflint", root_dir = root_dir, - installer = shell.remote("https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh", { - env = { - TFLINT_INSTALL_PATH = root_dir, - TFLINT_INSTALL_NO_ROOT = 1, - }, - }), + installer = installers.when { + unix = shell.remote_bash("https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh", { + env = { + TFLINT_INSTALL_PATH = root_dir, + TFLINT_INSTALL_NO_ROOT = 1, + }, + }), + }, default_options = { cmd = { bin_path, "--langserver" }, }, |
