|
| 1 | +local uv = vim.uv or vim.loop |
| 2 | + |
| 3 | +local function fail(message) |
| 4 | + local messages = vim.api.nvim_exec2("messages", { output = true }).output |
| 5 | + if messages ~= "" then |
| 6 | + vim.api.nvim_err_writeln(messages) |
| 7 | + end |
| 8 | + vim.api.nvim_err_writeln(message) |
| 9 | + vim.cmd("cquit") |
| 10 | +end |
| 11 | + |
| 12 | +local function assert_file(path, label) |
| 13 | + local stat = uv.fs_stat(path) |
| 14 | + if not stat or stat.type ~= "file" then |
| 15 | + fail(("Missing %s: %s"):format(label, path)) |
| 16 | + end |
| 17 | + print(("Found %s: %s"):format(label, path)) |
| 18 | +end |
| 19 | + |
| 20 | +local function wait_for(label, start) |
| 21 | + local done = false |
| 22 | + local err = nil |
| 23 | + local result = nil |
| 24 | + |
| 25 | + local ok, start_err = pcall(start, function(callback_err, callback_result) |
| 26 | + err = callback_err |
| 27 | + result = callback_result |
| 28 | + done = true |
| 29 | + end) |
| 30 | + |
| 31 | + if not ok then |
| 32 | + fail(("Failed to start %s: %s"):format(label, start_err)) |
| 33 | + end |
| 34 | + |
| 35 | + if not vim.wait(180000, function() |
| 36 | + return done |
| 37 | + end, 250, false) then |
| 38 | + fail(("Timed out waiting for %s"):format(label)) |
| 39 | + end |
| 40 | + |
| 41 | + if err then |
| 42 | + fail(("Failed to prepare %s: %s"):format(label, err)) |
| 43 | + end |
| 44 | + |
| 45 | + return result |
| 46 | +end |
| 47 | + |
| 48 | +local function native_extension() |
| 49 | + local sysname = uv.os_uname().sysname:lower() |
| 50 | + if sysname == "darwin" then |
| 51 | + return ".dylib" |
| 52 | + end |
| 53 | + if sysname:find("windows", 1, true) then |
| 54 | + return ".dll" |
| 55 | + end |
| 56 | + return ".so" |
| 57 | +end |
| 58 | + |
| 59 | +local function packadd(plugin) |
| 60 | + local ok, err = pcall(vim.cmd.packadd, plugin) |
| 61 | + if not ok then |
| 62 | + fail(("Failed to load %s: %s"):format(plugin, err)) |
| 63 | + end |
| 64 | +end |
| 65 | + |
| 66 | +packadd("blink.lib") |
| 67 | +packadd("blink.cmp") |
| 68 | +packadd("blink.pairs") |
| 69 | + |
| 70 | +if vim.v.errmsg ~= "" then |
| 71 | + fail(vim.v.errmsg) |
| 72 | +end |
| 73 | + |
| 74 | +local ok_cmp_config, cmp_config = pcall(require, "blink.cmp.config") |
| 75 | +if not ok_cmp_config then |
| 76 | + fail("blink.cmp config is not available: " .. tostring(cmp_config)) |
| 77 | +end |
| 78 | + |
| 79 | +cmp_config.fuzzy.implementation = "rust" |
| 80 | +cmp_config.fuzzy.prebuilt_binaries.force_version = cmp_config.fuzzy.prebuilt_binaries.force_version |
| 81 | + or "v*" |
| 82 | + |
| 83 | +local ok_cmp_download, cmp_download = pcall(require, "blink.cmp.fuzzy.download") |
| 84 | +if not ok_cmp_download then |
| 85 | + fail("blink.cmp fuzzy downloader is not available: " .. tostring(cmp_download)) |
| 86 | +end |
| 87 | + |
| 88 | +local cmp_implementation = wait_for("blink.cmp fuzzy native library", function(done) |
| 89 | + cmp_download.ensure_downloaded(done) |
| 90 | +end) |
| 91 | + |
| 92 | +if cmp_implementation ~= "rust" then |
| 93 | + fail( |
| 94 | + ("blink.cmp fuzzy matcher resolved to %s, expected rust"):format( |
| 95 | + tostring(cmp_implementation) |
| 96 | + ) |
| 97 | + ) |
| 98 | +end |
| 99 | + |
| 100 | +local cmp_files = require("blink.cmp.fuzzy.download.files") |
| 101 | +assert_file(cmp_files.lib_path, "blink.cmp fuzzy library") |
| 102 | +assert_file(cmp_files.checksum_path, "blink.cmp fuzzy checksum") |
| 103 | +assert_file(cmp_files.version_path, "blink.cmp fuzzy version") |
| 104 | + |
| 105 | +local ok_pairs, pairs = pcall(require, "blink.pairs") |
| 106 | +if not ok_pairs then |
| 107 | + fail("blink.pairs is not available: " .. tostring(pairs)) |
| 108 | +end |
| 109 | + |
| 110 | +wait_for("blink.pairs native library", function(done) |
| 111 | + pairs.download_if_available(function(err) |
| 112 | + done(err, true) |
| 113 | + end) |
| 114 | +end) |
| 115 | + |
| 116 | +local ok_pairs_rust, pairs_rust_err = pcall(require, "blink.pairs.rust") |
| 117 | +if not ok_pairs_rust then |
| 118 | + fail("blink.pairs native library is not loadable: " .. tostring(pairs_rust_err)) |
| 119 | +end |
| 120 | + |
| 121 | +local pairs_source = debug.getinfo(pairs.download_if_available, "S").source:gsub("^@", "") |
| 122 | +local pairs_root = pairs_source:gsub("/lua/blink/pairs/init%.lua$", "") |
| 123 | +if pairs_root == pairs_source then |
| 124 | + fail("Failed to resolve blink.pairs plugin root from " .. pairs_source) |
| 125 | +end |
| 126 | + |
| 127 | +assert_file( |
| 128 | + pairs_root .. "/target/release/libblink_pairs" .. native_extension(), |
| 129 | + "blink.pairs native library" |
| 130 | +) |
| 131 | +assert_file(pairs_root .. "/target/release/version", "blink.pairs native version") |
0 commit comments