Skip to content

Commit 3561ad3

Browse files
committed
refactor: simplify code with vim.F.if_nil
1 parent 671bec8 commit 3561ad3

File tree

3 files changed

+9
-18
lines changed
  • lua/astrocommunity

3 files changed

+9
-18
lines changed

lua/astrocommunity/completion/cmp-under-comparator/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ return {
1818
-- Find element in comparators we will position ourselves after.
1919
-- Position after recently_used, fallback to after score, fallback to 4th position.
2020
-- recently_used was not in nvim-cmp some time ago.
21-
local pos = list_index(opts.sorting.comparators, cmp.config.compare.recently_used)
22-
if pos == nil then pos = list_index(opts.sorting.comparators, cmp.config.compare.score) end
23-
if pos == nil then pos = 3 end
21+
local pos = vim.F.if_nil(
22+
list_index(opts.sorting.comparators, cmp.config.compare.recently_used),
23+
list_index(opts.sorting.comparators, cmp.config.compare.score),
24+
3
25+
)
2426
table.insert(opts.sorting.comparators, pos + 1, require("cmp-under-comparator").under)
2527
end,
2628
}

lua/astrocommunity/editing-support/conform-nvim/init.lua

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ return {
3636
["<Leader>lc"] = { function() vim.cmd.ConformInfo() end, desc = "Conform information" },
3737
["<Leader>uf"] = {
3838
function()
39-
if vim.b.autoformat == nil then
40-
if vim.g.autoformat == nil then vim.g.autoformat = true end
41-
vim.b.autoformat = vim.g.autoformat
42-
end
43-
vim.b.autoformat = not vim.b.autoformat
39+
vim.b.autoformat = not vim.F.if_nil(vim.b.autoformat, vim.g.autoformat, true)
4440
require("astrocore").notify(
4541
string.format("Buffer autoformatting %s", vim.b.autoformat and "on" or "off")
4642
)
@@ -49,9 +45,7 @@ return {
4945
},
5046
["<Leader>uF"] = {
5147
function()
52-
if vim.g.autoformat == nil then vim.g.autoformat = true end
53-
vim.g.autoformat = not vim.g.autoformat
54-
vim.b.autoformat = nil
48+
vim.g.autoformat, vim.b.autoformat = not vim.F.if_nil(vim.g.autoformat, true), nil
5549
require("astrocore").notify(
5650
string.format("Global autoformatting %s", vim.g.autoformat and "on" or "off")
5751
)
@@ -66,10 +60,7 @@ return {
6660
opts = {
6761
default_format_opts = { lsp_format = "fallback" },
6862
format_on_save = function(bufnr)
69-
if vim.g.autoformat == nil then vim.g.autoformat = true end
70-
local autoformat = vim.b[bufnr].autoformat
71-
if autoformat == nil then autoformat = vim.g.autoformat end
72-
if autoformat then return { timeout_ms = 500 } end
63+
if vim.F.if_nil(vim.b[bufnr].autoformat, vim.g.autoformat, true) then return { timeout_ms = 500 } end
7364
end,
7465
},
7566
}

lua/astrocommunity/lsp/nvim-lsp-file-operations/init.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ return {
1010
local operations = vim.tbl_get(require("astrocore").plugin_opts "nvim-lsp-file-operations", "operations") or {}
1111
local fileOperations = {}
1212
for _, operation in ipairs { "willRename", "didRename", "willCreate", "didCreate", "willDelete", "didDelete" } do
13-
local enabled = vim.tbl_get(operations, operation .. "Files")
14-
if enabled == nil then enabled = true end
15-
fileOperations[operation] = enabled
13+
fileOperations[operation] = vim.F.if_nil(vim.tbl_get(operations, operation .. "Files"), true)
1614
end
1715
opts.capabilities =
1816
vim.tbl_deep_extend("force", opts.capabilities or {}, { workspace = { fileOperations = fileOperations } })

0 commit comments

Comments
 (0)