diff options
| author | William Boman <william@redwill.se> | 2021-12-05 18:57:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-05 18:57:02 +0100 |
| commit | c82abb3117d83a36b58f07d341fd56a00bdfd360 (patch) | |
| tree | c6efa60621a8ab8eb9d128e4a6c75f89aea82a62 | |
| parent | sumneko_lua: don't provide -E argument as it's not needed (#309) (diff) | |
| download | mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.gz mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.bz2 mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.lz mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.xz mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.tar.zst mason-c82abb3117d83a36b58f07d341fd56a00bdfd360.zip | |
add ccls (#299)
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/_generated/filetype_map.lua | 8 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/_generated/language_autocomplete_map.lua | 4 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/_generated/metadata.lua | 3 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/context.lua | 27 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/init.lua | 33 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/std.lua | 11 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/server.lua | 7 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/bicep/init.lua | 4 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/ccls/init.lua | 96 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/init.lua | 1 |
11 files changed, 179 insertions, 19 deletions
@@ -149,8 +149,11 @@ lsp_installer.settings({ | Ansible | `ansiblels` | | Bash | `bashls` | | Bicep | `bicep` | +| C | `ccls` | +| C | `clangd` | | C# | `csharpls` | | C# | `omnisharp` | +| C++ | `ccls` | | C++ | `clangd` | | CMake | `cmake` | | CSS | `cssls` | @@ -184,6 +187,7 @@ lsp_installer.settings({ | LaTeX | `texlab` | | Lua | `sumneko_lua` | | OCaml | `ocamlls` | +| Objective C | `ccls` | | PHP | `intelephense` | | PHP | `phpactor` | | Powershell | `powershell_es` | diff --git a/lua/nvim-lsp-installer/_generated/filetype_map.lua b/lua/nvim-lsp-installer/_generated/filetype_map.lua index 75da25fb..3ca0be4a 100644 --- a/lua/nvim-lsp-installer/_generated/filetype_map.lua +++ b/lua/nvim-lsp-installer/_generated/filetype_map.lua @@ -7,10 +7,10 @@ return { bib = { "ltex", "texlab" }, bicep = { "bicep" }, blade = { "tailwindcss" }, - c = { "clangd" }, + c = { "ccls", "clangd" }, clojure = { "clojure_lsp" }, cmake = { "cmake" }, - cpp = { "clangd" }, + cpp = { "ccls", "clangd" }, cs = { "csharp_ls", "omnisharp" }, css = { "cssls", "emmet_ls", "stylelint_lsp", "tailwindcss" }, d = { "serve_d" }, @@ -61,8 +61,8 @@ return { mysql = { "sqlls", "sqls" }, njk = { "tailwindcss" }, nunjucks = { "tailwindcss" }, - objc = { "clangd" }, - objcpp = { "clangd" }, + objc = { "ccls", "clangd" }, + objcpp = { "ccls", "clangd" }, ocaml = { "ocamlls" }, org = { "ltex" }, php = { "intelephense", "phpactor", "tailwindcss" }, diff --git a/lua/nvim-lsp-installer/_generated/language_autocomplete_map.lua b/lua/nvim-lsp-installer/_generated/language_autocomplete_map.lua index ab5cdfbb..4bf055a3 100644 --- a/lua/nvim-lsp-installer/_generated/language_autocomplete_map.lua +++ b/lua/nvim-lsp-installer/_generated/language_autocomplete_map.lua @@ -1,8 +1,9 @@ -- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY. -- stylua: ignore start return { + c = { "ccls", "clangd" }, ["c#"] = { "csharp_ls", "omnisharp" }, - ["c++"] = { "clangd" }, + ["c++"] = { "ccls", "clangd" }, d = { "serve_d" }, ["f#"] = { "fsautocomplete" }, fortran = { "fortls" }, @@ -11,6 +12,7 @@ return { javascript = { "rome", "tsserver" }, latex = { "ltex", "texlab" }, lua = { "sumneko_lua" }, + ["objective-c"] = { "ccls" }, php = { "intelephense", "phpactor" }, python = { "jedi_language_server", "pylsp", "pyright" }, ruby = { "solargraph", "sorbet" }, diff --git a/lua/nvim-lsp-installer/_generated/metadata.lua b/lua/nvim-lsp-installer/_generated/metadata.lua index d409fa5b..f239ad52 100644 --- a/lua/nvim-lsp-installer/_generated/metadata.lua +++ b/lua/nvim-lsp-installer/_generated/metadata.lua @@ -13,6 +13,9 @@ return { bicep = { filetypes = { "bicep" } }, + ccls = { + filetypes = { "c", "cpp", "objc", "objcpp" } + }, clangd = { filetypes = { "c", "cpp", "objc", "objcpp" } }, diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua index bdb993a5..e80485a4 100644 --- a/lua/nvim-lsp-installer/installers/context.lua +++ b/lua/nvim-lsp-installer/installers/context.lua @@ -3,6 +3,8 @@ local log = require "nvim-lsp-installer.log" local process = require "nvim-lsp-installer.process" local installers = require "nvim-lsp-installer.installers" local platform = require "nvim-lsp-installer.platform" +local fs = require "nvim-lsp-installer.fs" +local path = require "nvim-lsp-installer.path" local M = {} @@ -96,7 +98,12 @@ function M.use_github_release_file(repo, file) M.use_github_release(repo), function(server, callback, context) local function get_download_url(version) - local target_file = type(file) == "function" and file(version) or file + local target_file + if type(file) == "function" then + target_file = file(version) + else + target_file = file + end if not target_file then log.fmt_error( "Unable to find which release file to download. server_name=%s, repo=%s", @@ -160,4 +167,22 @@ function M.set(fn) end end +---@param rel_path string @The relative path from the current installation working directory. +function M.set_working_dir(rel_path) + ---@type ServerInstallerFunction + return vim.schedule_wrap(function(server, callback, context) + log.fmt_debug("Changing installation working directory for %s", server.name) + local new_dir = path.concat { context.install_dir, rel_path } + if not fs.dir_exists(new_dir) then + local ok = pcall(fs.mkdirp, new_dir) + if not ok then + context.stdio_sink.stderr(("Failed to create directory %s.\n"):format(new_dir)) + return callback(false) + end + end + context.install_dir = new_dir + callback(true) + end) +end + return M diff --git a/lua/nvim-lsp-installer/installers/init.lua b/lua/nvim-lsp-installer/installers/init.lua index fdf3b0f4..a04eeafb 100644 --- a/lua/nvim-lsp-installer/installers/init.lua +++ b/lua/nvim-lsp-installer/installers/init.lua @@ -1,9 +1,21 @@ local platform = require "nvim-lsp-installer.platform" local log = require "nvim-lsp-installer.log" local Data = require "nvim-lsp-installer.data" +local fs = require "nvim-lsp-installer.fs" +local path = require "nvim-lsp-installer.path" local M = {} +---@param installer ServerInstallerFunction[]|ServerInstallerFunction +---@return ServerInstallerFunction +local function normalize_installer(installer) + if type(installer) == "table" then + return M.pipe(installer) + else + return installer + end +end + ---@alias ServerInstallCallback fun(success: boolean) ---@class ServerInstallContext @@ -120,11 +132,7 @@ function M.on(platform_table) return function(server, callback, context) local installer = get_by_platform(platform_table) if installer then - if type(installer) == "function" then - installer(server, callback, context) - else - M.pipe(installer)(server, callback, context) - end + normalize_installer(installer)(server, callback, context) else callback(true) end @@ -139,11 +147,7 @@ function M.when(platform_table) return function(server, callback, context) local installer = get_by_platform(platform_table) if installer then - if type(installer) == "function" then - installer(server, callback, context) - else - M.pipe(installer)(server, callback, context) - end + normalize_installer(installer)(server, callback, context) else context.stdio_sink.stderr( ("Current operating system is not yet supported for server %q.\n"):format(server.name) @@ -153,4 +157,13 @@ function M.when(platform_table) end end +---@param installer ServerInstallerFunction|ServerInstallerFunction[] @The installer to execute in a new installer context. +function M.branch_context(installer) + ---@type ServerInstallerFunction + return function(server, callback, context) + local new_context = vim.deepcopy(context) + normalize_installer(installer)(server, callback, new_context) + end +end + return M diff --git a/lua/nvim-lsp-installer/installers/std.lua b/lua/nvim-lsp-installer/installers/std.lua index 4a95e9c8..f123b3ae 100644 --- a/lua/nvim-lsp-installer/installers/std.lua +++ b/lua/nvim-lsp-installer/installers/std.lua @@ -248,6 +248,17 @@ function M.git_clone(repo_url) end end +function M.git_submodule_update() + ---@type ServerInstallerFunction + return function(_, callback, context) + process.spawn("git", { + args = { "submodule", "update", "--init", "--recursive" }, + cwd = context.install_dir, + stdio_sink = context.stdio_sink, + }, callback) + end +end + ---@param opts {args: string[]} function M.gradlew(opts) ---@type ServerInstallerFunction diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index 56ae77b5..b736e2cf 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -187,10 +187,16 @@ function M.Server:install_attached(context, callback) ("Failed to promote the temporary installation directory %q.\n"):format(context.install_dir) ) pcall(fs.rmrf, self:get_tmp_install_dir()) + pcall(fs.rmrf, context.install_dir) callback(false) return end + -- The tmp dir should in most cases have been "promoted" and already renamed to its final destination, + -- but we make sure to delete it should the installer modify the installation working directory during + -- installation. + pcall(fs.rmrf, self:get_tmp_install_dir()) + -- Dispatch the server is ready vim.schedule(function() dispatcher.dispatch_server_ready(self) @@ -201,6 +207,7 @@ function M.Server:install_attached(context, callback) callback(true) else pcall(fs.rmrf, self:get_tmp_install_dir()) + pcall(fs.rmrf, context.install_dir) callback(false) end end), diff --git a/lua/nvim-lsp-installer/servers/bicep/init.lua b/lua/nvim-lsp-installer/servers/bicep/init.lua index 7fb92f1c..1ebc6b1f 100644 --- a/lua/nvim-lsp-installer/servers/bicep/init.lua +++ b/lua/nvim-lsp-installer/servers/bicep/init.lua @@ -21,9 +21,7 @@ return function(name, root_dir) end), std.rename(path.concat { "vscode", "extension", "bicepLanguageServer" }, "langserver"), std.rmrf "vscode", - context.set(function(ctx) - ctx.install_dir = path.concat { ctx.install_dir, "langserver" } - end), + context.set_working_dir "langserver", }, default_options = { cmd = { "dotnet", path.concat { root_dir, "Bicep.LangServer.dll" } }, diff --git a/lua/nvim-lsp-installer/servers/ccls/init.lua b/lua/nvim-lsp-installer/servers/ccls/init.lua new file mode 100644 index 00000000..f8545c38 --- /dev/null +++ b/lua/nvim-lsp-installer/servers/ccls/init.lua @@ -0,0 +1,96 @@ +local server = require "nvim-lsp-installer.server" +local path = require "nvim-lsp-installer.path" +local installers = require "nvim-lsp-installer.installers" +local Data = require "nvim-lsp-installer.data" +local std = require "nvim-lsp-installer.installers.std" +local platform = require "nvim-lsp-installer.platform" +local context = require "nvim-lsp-installer.installers.context" +local process = require "nvim-lsp-installer.process" + +local coalesce, when = Data.coalesce, Data.when + +return function(name, root_dir) + local llvm_installer + + do + ---@param version string + ---@return string|nil + local function get_archive_name(version) + local name_template = coalesce( + when(platform.is_mac, "clang+llvm-%s-x86_64-apple-darwin"), + when( + platform.is_linux, + coalesce( + when(platform.arch == "x64", "clang+llvm-%s-amd64-unknown-freebsd13"), + when(platform.arch == "arm64", "clang+llvm-%s-aarch64-linux-gnu") + ) + ) + ) + return name_template and name_template:format(version) + end + + ---@param version string + local function normalize_version(version) + return version:gsub("^llvmorg%-", "") + end + + llvm_installer = installers.branch_context { + context.set(function(ctx) + -- We unset the requested version for llvm because it's not the primary target - the user's requested version should only apply to ccls. + ctx.requested_server_version = nil + end), + context.use_github_release_file("llvm/llvm-project", function(version) + -- Strip the "llvmorg-" prefix from tags (llvm releases tags like llvmorg-13.0.0) + local archive_name = get_archive_name(normalize_version(version)) + return archive_name and ("%s.tar.xz"):format(archive_name) + end), + context.capture(function(ctx) + return installers.pipe { + std.untarxz_remote(ctx.github_release_file), + std.rename(get_archive_name(normalize_version(ctx.requested_server_version)), "llvm"), + } + end), + } + end + + local ccls_installer = installers.branch_context { + context.set(function(ctx) + ctx.llvm_install_dir = path.concat { ctx.install_dir, "llvm" } + end), + context.set_working_dir "ccls", + std.git_clone "https://github.com/MaskRay/ccls", + std.git_submodule_update(), + function(_, callback, ctx) + local c = process.chain { + cwd = ctx.install_dir, + stdio_sink = ctx.stdio_sink, + } + + c.run("cmake", { + "-H.", + "-BRelease", + "-DCMAKE_BUILD_TYPE=Release", + ("-DCMAKE_PREFIX_PATH=%s"):format(path.concat { ctx.llvm_install_dir, "lib", "cmake" }), + }) + c.run("cmake", { "--build", "Release" }) + c.spawn(callback) + end, + } + + return server.Server:new { + name = name, + root_dir = root_dir, + homepage = "https://github.com/MaskRay/ccls", + languages = { "c", "c++", "objective-c" }, + installer = installers.when { + unix = { + context.promote_install_dir(), -- ccls hardcodes the path to llvm at compile time, so we need to compile everything in the final directory + llvm_installer, + ccls_installer, + }, + }, + default_options = { + cmd = { path.concat { root_dir, "ccls", "Release", "ccls" } }, + }, + } +end diff --git a/lua/nvim-lsp-installer/servers/init.lua b/lua/nvim-lsp-installer/servers/init.lua index cb217573..0f66d64c 100644 --- a/lua/nvim-lsp-installer/servers/init.lua +++ b/lua/nvim-lsp-installer/servers/init.lua @@ -35,6 +35,7 @@ local CORE_SERVERS = Data.set_of { "ansiblels", "bashls", "bicep", + "ccls", "clangd", "clojure_lsp", "cmake", |
