summaryrefslogtreecommitdiff
path: root/lua/mo/blink.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/mo/blink.lua')
-rw-r--r--lua/mo/blink.lua123
1 files changed, 123 insertions, 0 deletions
diff --git a/lua/mo/blink.lua b/lua/mo/blink.lua
new file mode 100644
index 0000000..ec68ec4
--- /dev/null
+++ b/lua/mo/blink.lua
@@ -0,0 +1,123 @@
+---@diagnostic disable: param-type-mismatch
+---@diagnostic disable: missing-fields
+
+local M = {}
+
+M.setup = function()
+ require("blink.cmp").setup({
+ keymap = {
+ preset = "default",
+ ["<Tab>"] = {},
+ ["<S-Tab>"] = {},
+ },
+ completion = {
+ list = { selection = { preselect = false, auto_insert = true } },
+ },
+ snippets = { preset = "mini_snippets" },
+ cmdline = { enabled = false },
+ appearance = {
+ nerd_font_variant = "normal",
+ },
+ sources = {
+ default = { "lsp", "path", "snippets", "buffer" },
+ providers = {
+ buffer = {
+ min_keyword_length = function(ctx)
+ return ctx.trigger.initial_kind == "manual" and 0 or 3
+ end,
+ opts = { get_bufnrs = vim.api.nvim_list_bufs },
+ },
+ snippets = {
+ should_show_items = function(ctx)
+ return ctx.trigger.initial_kind ~= "trigger_character"
+ end,
+ },
+ },
+ },
+ fuzzy = { implementation = "prefer_rust" },
+ signature = { enabled = true },
+ })
+end
+
+---@param data string
+---@param _opts { hl: string, status: "running"|"success"|"failed", id: (integer|string)?, fast: boolean }
+---@return integer|string|nil
+local function show_status(data, _opts)
+ local opts = vim.tbl_extend(
+ "keep",
+ _opts,
+ { hl = "Normal", status = "running", fast = false }
+ )
+ local fn = function()
+ return vim.api.nvim_echo({ { data, opts.hl } }, false, {
+ id = opts.id,
+ kind = "progress",
+ title = "Building blink-cmp",
+ status = opts.status,
+ })
+ end
+ if opts.fast then return fn() end
+ vim.schedule(fn)
+ return nil
+end
+
+M.build_rust = function()
+ local blink_pack = vim.pack.get({ "blink.cmp" })[1]
+ if blink_pack == nil then return end
+
+ local msg_id = show_status(
+ "Starting",
+ { hl = "Comment", status = "running", fast = true }
+ )
+
+ local uv = vim.uv
+ local stdout = uv.new_pipe()
+ local stderr = uv.new_pipe()
+
+ local on_exit = function(code, signal)
+ show_status(
+ ("Finished build (code=%s, signal=%s)"):format(code, signal),
+ {
+ hl = "Comment",
+ status = code == 0 and "success" or "failed",
+ id = msg_id,
+ fast = false,
+ }
+ )
+ end
+
+ local on_stdout = function(err, data)
+ assert(not err, err)
+ if data then
+ show_status(data, {
+ hl = "Normal",
+ status = "running",
+ id = msg_id,
+ fast = false,
+ })
+ end
+ end
+
+ local on_stderr = function(err, data)
+ assert(not err, err)
+ if data then
+ show_status(data, {
+ hl = "Comment",
+ status = "running",
+ id = msg_id,
+ fast = false,
+ })
+ end
+ end
+
+ uv.spawn("cargo", {
+ args = { "build", "--release" },
+ stdio = { nil, stdout, stderr },
+ cwd = blink_pack.path,
+ }, on_exit)
+
+ uv.read_start(stdout, on_stdout)
+ uv.read_start(stderr, on_stderr)
+end
+
+return M