From 5328c477a89706ac5f7184744cfb128ae27f4f1c Mon Sep 17 00:00:00 2001 From: jdhao Date: Thu, 19 Dec 2024 22:15:48 +0100 Subject: [PATCH] reformat with stylua --- init.lua | 2 +- lua/colorschemes.lua | 8 ++-- lua/config/dashboard-nvim.lua | 14 +++---- lua/config/git-linker.lua | 22 ++++++++--- lua/config/gitsigns.lua | 8 ++-- lua/config/hlslens.lua | 2 +- lua/config/lsp.lua | 73 ++++++++++++++++++----------------- lua/config/lualine.lua | 2 +- lua/config/nvim_hop.lua | 4 +- lua/config/treesitter.lua | 2 +- lua/config/which-key.lua | 4 +- lua/globals.lua | 24 ++++++------ 12 files changed, 89 insertions(+), 76 deletions(-) diff --git a/init.lua b/init.lua index f63e394..bd89782 100644 --- a/init.lua +++ b/init.lua @@ -28,6 +28,6 @@ require("custom-autocmd") -- all the user-defined mappings require("mappings") -- all the plugins installed and their configurations -vim.cmd("source ".. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) +vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim")) -- colorscheme settings require("colorschemes") diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua index 132e3c2..36b6659 100644 --- a/lua/colorschemes.lua +++ b/lua/colorschemes.lua @@ -50,18 +50,18 @@ M.colorscheme_conf = { end, onedarkpro = function() -- set colorscheme after options - vim.cmd('colorscheme onedark_vivid') + vim.cmd("colorscheme onedark_vivid") end, material = function() vim.g.material_style = "oceanic" - vim.cmd('colorscheme material') + vim.cmd("colorscheme material") end, - arctic = function () + arctic = function() vim.cmd("colorscheme arctic") end, kanagawa = function() vim.cmd("colorscheme kanagawa-wave") - end + end, } --- Use a random colorscheme from the pre-defined list of colorschemes. diff --git a/lua/config/dashboard-nvim.lua b/lua/config/dashboard-nvim.lua index 9017d96..562c124 100644 --- a/lua/config/dashboard-nvim.lua +++ b/lua/config/dashboard-nvim.lua @@ -59,17 +59,17 @@ conf.center = { }, } -dashboard.setup({ - theme = 'doom', - shortcut_type = 'number', - config = conf -}) +dashboard.setup { + theme = "doom", + shortcut_type = "number", + config = conf, +} api.nvim_create_autocmd("FileType", { pattern = "dashboard", group = api.nvim_create_augroup("dashboard_enter", { clear = true }), - callback = function () + callback = function() keymap.set("n", "q", ":qa", { buffer = true, silent = true }) keymap.set("n", "e", ":enew", { buffer = true, silent = true }) - end + end, }) diff --git a/lua/config/git-linker.lua b/lua/config/git-linker.lua index e3fb3e6..cbb4242 100644 --- a/lua/config/git-linker.lua +++ b/lua/config/git-linker.lua @@ -5,16 +5,26 @@ gitlinker.setup { callbacks = { ["dev.azure.com"] = function(url_data) vim.print(url_data) - local url = require"gitlinker.hosts".get_base_https_url(url_data) + local url = require("gitlinker.hosts").get_base_https_url(url_data) if url_data.lstart then if url_data.lend == nil then url_data.lend = url_data.lstart end - url = url .. "?path=/" .. url_data.file .. "&version=GC" .. url_data.rev .. "&line=" .. url_data.lstart .. "&lineEnd=" .. url_data.lend .. "&lineStartColumn=1" .. "&lineEndColumn=120" + url = url + .. "?path=/" + .. url_data.file + .. "&version=GC" + .. url_data.rev + .. "&line=" + .. url_data.lstart + .. "&lineEnd=" + .. url_data.lend + .. "&lineStartColumn=1" + .. "&lineEndColumn=120" end return url - end + end, }, mappings = nil, } @@ -28,9 +38,9 @@ end, { }) keymap.set("n", "gbr", function() - gitlinker.get_repo_url({ - action_callback = gitlinker.actions.open_in_browser - }) + gitlinker.get_repo_url { + action_callback = gitlinker.actions.open_in_browser, + } end, { silent = true, desc = "Git: browse repo in browser", diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua index f272dcc..8bad6b6 100644 --- a/lua/config/gitsigns.lua +++ b/lua/config/gitsigns.lua @@ -45,13 +45,13 @@ gs.setup { end, } -vim.api.nvim_create_autocmd('ColorScheme', { +vim.api.nvim_create_autocmd("ColorScheme", { pattern = "*", callback = function() - vim.cmd [[ + vim.cmd([[ hi GitSignsChangeInline gui=reverse hi GitSignsAddInline gui=reverse hi GitSignsDeleteInline gui=reverse - ]] - end + ]]) + end, }) diff --git a/lua/config/hlslens.lua b/lua/config/hlslens.lua index cbf540a..0f59bca 100644 --- a/lua/config/hlslens.lua +++ b/lua/config/hlslens.lua @@ -14,7 +14,7 @@ local activate_hlslens = function(direction) -- Deal with the case that there is no such pattern in current buffer. if not status then - local start_idx, _ = string.find(msg, 'E486', 1, true) + local start_idx, _ = string.find(msg, "E486", 1, true) local msg_part = string.sub(msg, start_idx) api.nvim_err_writeln(msg_part) return diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 2f61e91..87d88fc 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -13,10 +13,10 @@ local set_qflist = function(buf_num, severity) diagnostics = diagnostic.get(buf_num, { severity = severity }) local qf_items = diagnostic.toqflist(diagnostics) - vim.fn.setqflist({}, ' ', { title = 'Diagnostics', items = qf_items }) + vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items }) -- open quickfix by default - vim.cmd[[copen]] + vim.cmd([[copen]]) end local custom_attach = function(client, bufnr) @@ -39,7 +39,9 @@ local custom_attach = function(client, bufnr) -- this puts diagnostics from opened files to quickfix map("n", "qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) -- this puts diagnostics from current buffer to quickfix - map("n", "qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" }) + map("n", "qb", function() + set_qflist(bufnr) + end, { desc = "put buffer diagnostics to qf" }) map("n", "ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) map("n", "wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) map("n", "wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) @@ -49,7 +51,7 @@ local custom_attach = function(client, bufnr) -- Set some key bindings conditional on server capabilities if client.server_capabilities.documentFormattingProvider then - map({"n", "x"}, "f", vim.lsp.buf.format, { desc = "format code" }) + map({ "n", "x" }, "f", vim.lsp.buf.format, { desc = "format code" }) end -- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint, @@ -72,8 +74,9 @@ local custom_attach = function(client, bufnr) end local cursor_pos = api.nvim_win_get_cursor(0) - if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) - and #diagnostic.get() > 0 + if + (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) + and #diagnostic.get() > 0 then diagnostic.open_float(nil, float_opts) end @@ -91,20 +94,20 @@ local custom_attach = function(client, bufnr) ]]) local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true }) - api.nvim_create_autocmd("CursorHold" , { + api.nvim_create_autocmd("CursorHold", { group = gid, buffer = bufnr, - callback = function () + callback = function() lsp.buf.document_highlight() - end + end, }) - api.nvim_create_autocmd("CursorMoved" , { + api.nvim_create_autocmd("CursorMoved", { group = gid, buffer = bufnr, - callback = function () + callback = function() lsp.buf.clear_references() - end + end, }) end @@ -114,12 +117,12 @@ local custom_attach = function(client, bufnr) end end -local capabilities = require('cmp_nvim_lsp').default_capabilities() +local capabilities = require("cmp_nvim_lsp").default_capabilities() -- required by nvim-ufo capabilities.textDocument.foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true + dynamicRegistration = false, + lineFoldingOnly = true, } -- For what diagnostic is enabled in which type checking mode, check doc: @@ -127,21 +130,21 @@ capabilities.textDocument.foldingRange = { -- Currently, the pyright also has some issues displaying hover documentation: -- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/ -if utils.executable('pyright') then +if utils.executable("pyright") then local new_capability = { -- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from -- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482 textDocument = { publishDiagnostics = { tagSupport = { - valueSet = { 2 } - } + valueSet = { 2 }, + }, }, hover = { contentFormat = { "plaintext" }, dynamicRegistration = true, }, - } + }, } local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability) @@ -177,25 +180,25 @@ if utils.executable('pyright') then }, } else - vim.notify("pyright not found!", vim.log.levels.WARN, { title = 'Nvim-config' }) + vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end if utils.executable("ruff") then - require('lspconfig').ruff.setup({ + require("lspconfig").ruff.setup { on_attach = custom_attach, capabilities = capabilities, init_options = { -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/ settings = { organizeImports = true, - } - } - }) + }, + }, + } end -- Disable ruff hover feature in favor of Pyright vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }), + group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }), callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) -- vim.print(client.name, client.server_capabilities) @@ -203,11 +206,11 @@ vim.api.nvim_create_autocmd("LspAttach", { if client == nil then return end - if client.name == 'ruff' then + if client.name == "ruff" then client.server_capabilities.hoverProvider = false end end, - desc = 'LSP: Disable hover capability from Ruff', + desc = "LSP: Disable hover capability from Ruff", }) if utils.executable("ltex-ls") then @@ -217,11 +220,11 @@ if utils.executable("ltex-ls") then filetypes = { "text", "plaintex", "tex", "markdown" }, settings = { ltex = { - language = "en" + language = "en", }, }, flags = { debounce_text_changes = 300 }, -} + } end if utils.executable("clangd") then @@ -267,8 +270,8 @@ if utils.executable("lua-language-server") then version = "LuaJIT", }, hint = { - enable = true - } + enable = true, + }, }, }, capabilities = capabilities, @@ -276,10 +279,10 @@ if utils.executable("lua-language-server") then end -- Change diagnostic signs. -fn.sign_define("DiagnosticSignError", { text = '🆇', texthl = "DiagnosticSignError" }) -fn.sign_define("DiagnosticSignWarn", { text = 'âš ī¸', texthl = "DiagnosticSignWarn" }) -fn.sign_define("DiagnosticSignInfo", { text = 'â„šī¸', texthl = "DiagnosticSignInfo" }) -fn.sign_define("DiagnosticSignHint", { text = '', texthl = "DiagnosticSignHint" }) +fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" }) +fn.sign_define("DiagnosticSignWarn", { text = "âš ī¸", texthl = "DiagnosticSignWarn" }) +fn.sign_define("DiagnosticSignInfo", { text = "â„šī¸", texthl = "DiagnosticSignInfo" }) +fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) -- global config for diagnostic diagnostic.config { diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index dc99631..d41e2e6 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -140,7 +140,7 @@ require("lualine").setup { options = { icons_enabled = true, theme = "auto", - component_separators = { left = '⏐', right = '⏐' }, + component_separators = { left = "⏐", right = "⏐" }, section_separators = "", disabled_filetypes = {}, always_divide_middle = true, diff --git a/lua/config/nvim_hop.lua b/lua/config/nvim_hop.lua index 11aa60d..205543d 100644 --- a/lua/config/nvim_hop.lua +++ b/lua/config/nvim_hop.lua @@ -4,7 +4,7 @@ hop.setup { case_insensitive = true, char2_fallback_key = "", quit_key = "", - match_mappings = { "zh_sc" } + match_mappings = { "zh_sc" }, } keymap.set({ "n", "v", "o" }, "f", "", { @@ -24,5 +24,5 @@ vim.api.nvim_create_autocmd("ColorScheme", { hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff ]]) - end + end, }) diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 4111859..2b45553 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -3,6 +3,6 @@ require("nvim-treesitter.configs").setup { ignore_install = {}, -- List of parsers to ignore installing highlight = { enable = true, -- false will disable the whole extension - disable = { 'help' }, -- list of language that will be disabled + disable = { "help" }, -- list of language that will be disabled }, } diff --git a/lua/config/which-key.lua b/lua/config/which-key.lua index 13b736c..136895a 100644 --- a/lua/config/which-key.lua +++ b/lua/config/which-key.lua @@ -1,6 +1,6 @@ require("which-key").setup { preset = "modern", icons = { - mappings = false - } + mappings = false, + }, } diff --git a/lua/globals.lua b/lua/globals.lua index ee96427..7e65176 100644 --- a/lua/globals.lua +++ b/lua/globals.lua @@ -1,28 +1,28 @@ local fn = vim.fn local api = vim.api -local utils = require('utils') +local utils = require("utils") ------------------------------------------------------------------------ -- custom variables -- ------------------------------------------------------------------------ vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false -vim.g.is_mac = utils.has("macunix") and true or false +vim.g.is_mac = utils.has("macunix") and true or false vim.g.logging_level = "info" ------------------------------------------------------------------------ -- builtin variables -- ------------------------------------------------------------------------ -vim.g.loaded_perl_provider = 0 -- Disable perl provider -vim.g.loaded_ruby_provider = 0 -- Disable ruby provider -vim.g.loaded_node_provider = 0 -- Disable node provider -vim.g.did_install_default_menus = 1 -- do not load menu +vim.g.loaded_perl_provider = 0 -- Disable perl provider +vim.g.loaded_ruby_provider = 0 -- Disable ruby provider +vim.g.loaded_node_provider = 0 -- Disable node provider +vim.g.did_install_default_menus = 1 -- do not load menu -if utils.executable('python3') then +if utils.executable("python3") then if vim.g.is_win then - vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", '', 'g') + vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", "", "g") else vim.g.python3_host_prog = fn.exepath("python3") end @@ -32,18 +32,18 @@ else end -- Custom mapping (see `:h mapleader` for more info) -vim.g.mapleader = ',' +vim.g.mapleader = "," -- Enable highlighting for lua HERE doc inside vim script -vim.g.vimsyn_embed = 'l' +vim.g.vimsyn_embed = "l" -- Use English as main language -vim.cmd [[language en_US.UTF-8]] +vim.cmd([[language en_US.UTF-8]]) -- Disable loading certain plugins -- Whether to load netrw by default, see https://github.com/bling/dotvim/issues/4 -vim.g.loaded_netrw = 1 +vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 vim.g.netrw_liststyle = 3 if vim.g.is_win then