-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
86 lines (73 loc) · 2.05 KB
/
Copy pathinit.lua
File metadata and controls
86 lines (73 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local Source = {}
local config = require("cmp.config")
local a = require("plenary.async")
local l = require("angular-selectors.local")
local ts = vim.treesitter
local tsu = require("nvim-treesitter.ts_utils")
local parsers = require("nvim-treesitter.parsers")
local scan = require("plenary.scandir")
local rootDir = scan.scan_dir(".", {
hidden = true,
add_dirs = true,
depth = 1,
respect_gitignore = true,
search_pattern = function(entry)
local subEntry = entry:sub(3) -- remove ./
return subEntry:match(".git$") or subEntry:match("package.json") -- if project contains .git folder or package.json its gonna work
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 = "angular-selectors"
self.isRemote = "^https?://"
self.items = {}
self.ids = {}
-- 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.style_sheets = self.option.style_sheets or {}
self.enable_on = self.option.enable_on or {}
return self
end
function Source:complete(_, callback)
if vim.tbl_count(rootDir) ~= 0 then
self.items = {}
self.ids = {}
-- read all local files on start
a.run(function()
l.read_local_files(self.file_extensions, function(classes, ids)
for _, id in ipairs(ids) do
table.insert(self.ids, id)
end
end)
end)
if self.current_selector == "element" then
callback({ items = self.ids, isComplete = false })
end
end
end
function Source:is_available()
if not next(self.user_config) then
return false
end
local bufnr = vim.api.nvim_get_current_buf()
local parser = parsers.get_parser(bufnr)
if parser then
local lang = parser:lang()
if lang == "html" or lang == "svelte" or lang == "vue" or lang == "angular" then
self.current_selector = "element"
return true
end
end
return false
end
return Source:new()