Skip to content

Commit

Permalink
feat: use globs based config
Browse files Browse the repository at this point in the history
  • Loading branch information
pigoz committed Feb 9, 2024
1 parent e336cba commit b83a0ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
33 changes: 5 additions & 28 deletions lua/html-css/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,21 @@ local rootDir = scan.scan_dir(".", {
end,
})

local function mrgtbls(t1, t2)
for _, v in ipairs(t2) do
table.insert(t1, v)
end
return t1
end

function Source:setup()
require("cmp").register_source(self.source_name, Source)
end

function Source:new()
self.source_name = "html-css"
self.isRemote = "^https?:https://"
self.remote_classes = {}
self.source_name = "html_css"
self.isRemote = false
self.items = {}
self.ids = {}
self.href_links = {}

-- reading user config
self.user_config = config.get_source_config(self.source_name) or {}
self.option = self.user_config.option or {}
self.file_extensions = self.option.file_extensions or {}
self.globs = self.option.globs or {}
self.style_sheets = self.option.style_sheets or {}
self.enable_on = self.option.enable_on or {}

Expand All @@ -55,7 +47,7 @@ function Source:new()
if vim.tbl_count(rootDir) ~= 0 then
-- read all local files on start
a.run(function()
l.read_local_files(self.file_extensions, function(classes, ids)
l.read_local_files(self.globs, function(classes, ids)
for _, class in ipairs(classes) do
table.insert(self.items, class)
end
Expand All @@ -81,31 +73,16 @@ function Source:complete(_, callback)
self.items = {}
self.ids = {}

-- handle embedded styles
a.run(function()
e.read_html_files(function(classes, ids)
for _, class in ipairs(classes) do
table.insert(self.items, class)
end
for _, id in ipairs(ids) do
table.insert(self.ids, id)
end
end)
end)

-- read all local files on start
a.run(function()
l.read_local_files(self.file_extensions, function(classes, ids)
l.read_local_files(self.globs, function(classes, ids)
for _, class in ipairs(classes) do
table.insert(self.items, class)
end
for _, id in ipairs(ids) do
table.insert(self.ids, id)
end
end)
for _, class in ipairs(self.remote_classes) do
table.insert(self.items, class)
end
end)

if self.current_selector == "class" then
Expand Down
7 changes: 3 additions & 4 deletions lua/html-css/local.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ local qs = [[
]]

---@async
M.read_local_files = a.wrap(function(file_extensions, cb)
M.read_local_files = a.wrap(function(globs, cb)
local files = {}

-- WARNING need to check for performance in larger projects
for _, extension in ipairs(file_extensions) do
for _, glb in ipairs(globs) do
j:new({
command = "fd",
args = { "-a", "-e", "" .. extension .. "", "--exclude", "node_modules", "--exclude", "vendor" },
args = { "-a", "--exclude", "node_modules", "--exclude", "vendor", "-g", glb },
on_stdout = function(_, data)
table.insert(files, data)
end,
Expand Down

0 comments on commit b83a0ec

Please sign in to comment.