Skip to content

Commit

Permalink
fix: Integrated user.util.notify to many files.
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKJeff16 committed Jun 2, 2024
1 parent 3d4b318 commit 64a4d3c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 50 deletions.
21 changes: 7 additions & 14 deletions lua/lazy_cfg/cmp/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local User = require('user')
local Check = User.check
local Util = User.util
local types = User.types.cmp

local exists = Check.exists.module
Expand All @@ -17,18 +18,18 @@ local Types = require('cmp.types')
local CmpTypes = require('cmp.types.cmp')

local Sks = require('lazy_cfg.cmp.kinds')
local Util = require('lazy_cfg.cmp.util')
local CmpUtil = require('lazy_cfg.cmp.util')
local Sources = require('lazy_cfg.cmp.sources').new()

local Luasnip = exists('lazy_cfg.cmp.luasnip') and require('lazy_cfg.cmp.luasnip') or require('luasnip')
local cmp = require('cmp')
local Compare = require('cmp.config.compare')

local tab_map = Util.tab_map
local s_tab_map = Util.s_tab_map
local cr_map = Util.cr_map
local tab_map = CmpUtil.tab_map
local s_tab_map = CmpUtil.s_tab_map
local cr_map = CmpUtil.cr_map

local bs_map = Util.bs_map
local bs_map = CmpUtil.bs_map
local buffer = Sources.buffer

---@type table<string, cmp.MappingClass|fun(fallback: function):nil>
Expand Down Expand Up @@ -167,12 +168,4 @@ if is_fun(Sks.vscode) then
end

-- For debugging.
if not is_nil(Notify) then
Notify('cmp loaded.', 'info', { title = 'cmp' })
elseif exists('notify') then
local Notify = require('notify')

Notify('cmp loaded.', 'info', { title = 'cmp' })
else
vim.notify('cmp loaded.', vim.log.levels.INFO)
end
Util.notify.notify('cmp loaded.', vim.log.levels.INFO)
11 changes: 8 additions & 3 deletions lua/lazy_cfg/cmp/sources.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

local User = require('user')
local Check = User.check
local Util = User.util
local types = User.types.cmp

local exists = Check.exists.module
Expand Down Expand Up @@ -142,11 +143,14 @@ local cmdline = {
},
async_path(2),
}),

---@diagnostic disable-next-line:missing-fields
matching = { disallow_symbol_nonprefix_matching = false },
},
}

---@type Sources
---@diagnostic disable-next-line:missing-fields
local M = {
setup = function(T)
if is_tbl(T) and not empty(T) then
Expand All @@ -155,9 +159,10 @@ local M = {
table.insert(ft, v)
elseif is_str(k) and is_tbl(v) then
ft[k] = v
elseif exists('notify') then
require('notify')("Couldn't parse!", 'error', {
title = '(lazy_cfg.cmp.sources)',
else
Util.notify.notify("(lazy_cfg.cmp.sources): Couldn't parse the input table value", 'error', {
title = 'lazy_cfg.cmp.sources',
timeout = 2000,
})
end
end
Expand Down
3 changes: 2 additions & 1 deletion lua/lazy_cfg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
local User = require('user')
local Check = User.check
local types = User.types.lazy
local Util = User.util
local kmap = User.maps.kmap
local WK = User.maps.wk

Expand Down Expand Up @@ -914,7 +915,7 @@ for mode, maps in next, Keys do
for lhs, v in next, maps do
local msg = '(lazy_cfg): Could not set keymap `' .. lhs .. '`'
if not (is_str(v[1]) or is_fun(v[1])) then
vim.notify(msg)
Util.notify.notify(msg, 'error', { title = 'lazy_cfg' })
goto continue
end

Expand Down
11 changes: 3 additions & 8 deletions lua/lazy_cfg/lspconfig/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,13 @@ au('LspAttach', {
function()
local out = lsp_buf.list_workspace_folders()
local msg = ''

local notify = require('user.util.notify').notify
for _, v in next, out do
msg = msg .. '\n - ' .. v
end

-- Try doing it with `notify` plugin.
if exists('notify') then
local Notify = require('notify')

Notify(msg, 'info', { title = 'Workspace Folders' })
else
vim.notify(msg, vim.log.levels.INFO)
end
notify(msg, 'info', { title = 'Workspace Folders' })
end,
desc('List Workspace Folders', true, buf),
},
Expand Down
9 changes: 2 additions & 7 deletions lua/lazy_cfg/lspconfig/neoconf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local Lspconfig = require('lspconfig')

local User = require('user')
local Check = User.check
local Util = User.util
local types = User.types.lspconfig

local exists = Check.exists.module
Expand All @@ -18,13 +19,7 @@ end
if is_num(neoconf_configured) and neoconf_configured == 1 then
local msg = "Neoconf can't be re-sourced."

if not is_nil(Notify) then
Notify(msg, 'error', { title = 'NeoConf' })
elseif exists('notify') then
require('notify')(msg, 'error', { title = 'NeoConf' })
else
vim.notify(msg, vim.log.levels.ERROR)
end
Util.notify.notify(msg, 'error', { title = 'NeoConf' })

return
else
Expand Down
9 changes: 2 additions & 7 deletions lua/lazy_cfg/lspconfig/neodev.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

local User = require('user')
local Check = User.check
local Util = User.util
local types = User.types.lspconfig

local executable = Check.exists.executable
Expand All @@ -20,13 +21,7 @@ then
- `vscode-json-language-server`
]]

if not is_nil(Notify) then
Notify(msg, 'error', { title = 'LSPCONFIG' })
elseif exists('notify') then
require('notify')(msg, 'error', { title = 'LSPCONFIG' })
else
vim.notify(msg, vim.log.levels.ERROR)
end
Util.notify.notify(msg, 'error', { title = 'LSPCONFIG' })
return
end

Expand Down
14 changes: 4 additions & 10 deletions lua/lazy_cfg/project/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

local User = require('user')
local Check = User.check
local Util = User.util
local maps_t = User.types.user.maps
local kmap = User.maps.kmap
local WK = User.maps.wk
local UNotify = Util.notify

local exists = Check.exists.module
local is_tbl = Check.value.is_tbl
Expand Down Expand Up @@ -92,11 +94,7 @@ local Keys = {
for _, v in next, recent_proj() do
msg = msg .. '\n- ' .. v
end
if exists('notify') then
require('notify')(msg, 'info', { title = 'Recent Projects' })
else
vim.notify(msg, vim.log.levels.INFO)
end
UNotify.notify(msg, 'info', { title = 'Recent Projects' })
end,
desc('Print Recent Projects'),
},
Expand All @@ -109,11 +107,7 @@ local Keys = {
for _, v in next, recent_proj() do
msg = msg .. '\n- ' .. v
end
if exists('notify') then
require('notify')(msg, 'info', { title = 'Recent Projects' })
else
vim.notify(msg, vim.log.levels.INFO)
end
UNotify.notify(msg, 'info', { title = 'Recent Projects' })
end,
desc('Print Recent Projects'),
},
Expand Down

0 comments on commit 64a4d3c

Please sign in to comment.