Skip to content

Commit

Permalink
refactor(cmp): Moved checks before require() statements
Browse files Browse the repository at this point in the history
Ref: #281
  • Loading branch information
OXY2DEV committed Feb 5, 2025
1 parent 6fe784c commit ecfa2ef
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lua/cmp-markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ local source = {};
--- Is this source available?
---@return boolean
function source:is_available()
local fts = require("markview.spec").get({ "preview", "filetypes" }, { fallback = {}, ignore_enable = true });
if not package.loaded["markview.spec"] then
--- Plugin not available.
return false;
end

local fts = require("markview.spec").get({ "preview", "filetypes" }, {
fallback = {},
ignore_enable = true
});
return vim.list_contains(fts, vim.bo.ft);
end

Expand All @@ -17,25 +25,26 @@ end
--- Characters that trigger the completion.
---@return string[]
function source:get_trigger_characters()
return { "[", "!" }
return { "[", "!" };
end

--- Completion items.
---@param self table
---@param params table
---@param callback function
function source:complete(params, callback)
local spec = require("markview.spec");
if not package.loaded["markview.spec"] then
--- Plugin not available.
return;
end

local spec = package.loaded["markview.spec"];

local before = params.context.cursor_before_line or "";
local after = params.context.cursor_after_line or "";

local comp = {};

if vim.bo.ft ~= "markdown" then
goto not_md;
end

if before:match("^[ %>]+%s*%[%!%a*$") then
---+${func, Callout completion}
local items = spec.get({ "markdown", "block_quotes" }, { fallback = {} });
Expand Down Expand Up @@ -101,8 +110,6 @@ function source:complete(params, callback)
return;
end

::not_md::

callback(comp);
end

Expand Down

0 comments on commit ecfa2ef

Please sign in to comment.