From b350b62260872cae90c93b6ac9b8816164d1c4ba Mon Sep 17 00:00:00 2001 From: kevinm6 <72861758+kevinm6@users.noreply.github.com> Date: Sun, 5 Jan 2025 16:03:36 +0100 Subject: [PATCH] chore: QOL fixes & improvements --- lazy-lock.json | 20 +- lua/lib/env.lua | 29 +- lua/lib/notes.lua | 3 +- lua/lib/session.lua | 9 +- lua/lib/terminal.lua | 2 +- lua/lib/ui/statusline.lua | 14 +- lua/plugins/editor/completion.lua | 18 +- lua/plugins/init.lua | 4 +- lua/plugins/lsp/init.lua | 16 +- .../ui/{noice.lua => notifications.lua} | 8 +- plugin/autocommands.lua | 17 +- plugin/keymaps.lua | 4 +- snippets/general/all.json | 2 +- snippets/general/java/java.json | 320 ++++++++------- snippets/general/java/java_tests.json | 368 +++++++++--------- snippets/general/java/javadoc.json | 224 +++++------ 16 files changed, 521 insertions(+), 537 deletions(-) rename lua/plugins/ui/{noice.lua => notifications.lua} (89%) diff --git a/lazy-lock.json b/lazy-lock.json index 0704d45..d7c3e64 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -10,12 +10,12 @@ "hererocks": { "branch": "master", "commit": "c9c5444dea1e07e005484014a8231aa667be30b6" }, "image.nvim": { "branch": "master", "commit": "b991fc7f845bc6ab40c6ec00b39750dcd5190010" }, "jupytext.nvim": { "branch": "main", "commit": "c8baf3ad344c59b3abd461ecc17fc16ec44d0f7b" }, - "lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" }, + "lazy.nvim": { "branch": "main", "commit": "72aa3a2624be5dc240646084f7b6a38eb99eb2ce" }, "lazydev.nvim": { "branch": "main", "commit": "8620f82ee3f59ff2187647167b6b47387a13a018" }, - "markdown.nvim": { "branch": "main", "commit": "1faa6568eb61467d64c3d0aad8ac4c9c0e45514e" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "c6c686781f9841d855bf1b926e10aa5e19430a38" }, + "markdown.nvim": { "branch": "main", "commit": "16369540a005ad0cf267498162aedca6dfca1b9c" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "97d9f1d3ad205dece6bcafd1d71cf1507608f3c7" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, - "mini.icons": { "branch": "main", "commit": "6787321f70d674a481776b7cc2c781fb7002c644" }, + "mini.icons": { "branch": "main", "commit": "1c79feb7478ca773fa3dac5cadf43ced9180e861" }, "mini.pairs": { "branch": "main", "commit": "7e834c5937d95364cc1740e20d673afe2d034cdb" }, "mini.surround": { "branch": "main", "commit": "aa5e245829dd12d8ff0c96ef11da28681d6049aa" }, "molten-nvim": { "branch": "main", "commit": "c621baf53459a6c45dfd98dcc11cbba7a7ae9470" }, @@ -25,15 +25,15 @@ "nvim-dap-ui": { "branch": "master", "commit": "e94d98649dccb6a3884b66aabc2e07beb279e535" }, "nvim-dbee": { "branch": "master", "commit": "21d2cc0844a16262bb6ea93ab3d0a0f20bd87853" }, "nvim-jdtls": { "branch": "master", "commit": "266d0cb912bbe61d66b43c5e73db19a364380360" }, - "nvim-lint": { "branch": "master", "commit": "1fea92f1d9908eaa5eb8bafe08b4293d7aadaa55" }, - "nvim-lspconfig": { "branch": "master", "commit": "a8ef5e6e497b3ebeaaf35b939c07c211563b2e05" }, + "nvim-lint": { "branch": "master", "commit": "139cd3ccefdc92644746168dd95a15f36aec5458" }, + "nvim-lspconfig": { "branch": "master", "commit": "8121483b8132b7053120fafd83728178fb3febf6" }, "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, "nvim-notify": { "branch": "master", "commit": "bd9cd51f9ef2f6326fc2bc9931d0718c1794e247" }, - "nvim-treesitter": { "branch": "master", "commit": "fae21737be2846a04ae06a41d70b7fc8ad4bf9eb" }, + "nvim-treesitter": { "branch": "master", "commit": "958af94dd8d74071c72c9d6840b41d06ea436b2f" }, "nvim-treesitter-refactor": { "branch": "master", "commit": "d8b74fa87afc6a1e97b18da23e762efb032dc270" }, "nvim-ufo": { "branch": "main", "commit": "32cb247b893a384f1888b9cd737264159ecf183c" }, "obsidian.nvim": { "branch": "main", "commit": "ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b" }, - "oil.nvim": { "branch": "master", "commit": "c6a39a69b2df7c10466f150dde0bd23e49c1fba3" }, + "oil.nvim": { "branch": "master", "commit": "c12fad2d225d8f81fadd48521d253607fe25465c" }, "otter.nvim": { "branch": "main", "commit": "e8c662e1aefa8b483cfba6e00729a39a363dcecc" }, "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" }, @@ -42,6 +42,6 @@ "telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "2eca9ba22002184ac05eddbe47a7fe2d5a384dfc" }, - "vimtex": { "branch": "master", "commit": "56def42c4f3007979c38001518ebb92ea8fb5f72" }, - "which-key.nvim": { "branch": "main", "commit": "8ab96b38a2530eacba5be717f52e04601eb59326" } + "vimtex": { "branch": "master", "commit": "99c56940cefe6adead7500f7657cd6721ff38d05" }, + "which-key.nvim": { "branch": "main", "commit": "1f8d414f61e0b05958c342df9b6a4c89ce268766" } } diff --git a/lua/lib/env.lua b/lua/lib/env.lua index e47c4b5..1eca237 100644 --- a/lua/lib/env.lua +++ b/lua/lib/env.lua @@ -7,8 +7,6 @@ local env = {} -local has_tele, pickers = pcall(require, "telescope.pickers") - local function prepare_environment_variables() local items = {} for key, value in pairs(vim.fn.environ()) do @@ -17,18 +15,12 @@ local function prepare_environment_variables() return items end -if not has_tele then - vim.print(prepare_environment_variables()) - return -end - -local finders = require "telescope.finders" -local actions = require "telescope.actions" -local action_state = require "telescope.actions.state" -local entry_display = require "telescope.pickers.entry_display" local conf = require("telescope.config").values local function append_environment_name(prompt_bufnr) + local actions = require "telescope.actions" + local action_state = require "telescope.actions.state" + local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) if selection.value == "" then @@ -40,6 +32,9 @@ local function append_environment_name(prompt_bufnr) end local function append_environment_value(prompt_bufnr) + local actions = require "telescope.actions" + local action_state = require "telescope.actions.state" + local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) if selection.value == "" then @@ -51,6 +46,8 @@ local function append_environment_value(prompt_bufnr) end local function edit_environment_value(prompt_bufnr) + local actions = require "telescope.actions" + local action_state = require "telescope.actions.state" local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) @@ -68,6 +65,15 @@ local function edit_environment_value(prompt_bufnr) end local function show_environment_variables(opts) + local has_tele, pickers = pcall(require, "telescope.pickers") + if not has_tele then + vim.print(prepare_environment_variables()) + return + end + + local finders = require "telescope.finders" + local actions = require "telescope.actions" + opts = opts or {} pickers .new(opts, { @@ -89,6 +95,7 @@ local function show_environment_variables(opts) local env_name_width = math.floor(columns * 0.05) local env_value_width = 22 + local entry_display = require "telescope.pickers.entry_display" -- NOTE: the width calculating logic is not exact, but approx enough local displayer = entry_display.create { separator = " ▏", diff --git a/lua/lib/notes.lua b/lua/lib/notes.lua index 0aba4b1..6bfcfb3 100644 --- a/lua/lib/notes.lua +++ b/lua/lib/notes.lua @@ -8,7 +8,6 @@ local note = {} ---Get available notes ----@private ---@return table local function get_notes() local notes = {} @@ -75,4 +74,4 @@ function note.open_note() end end -return note \ No newline at end of file +return note diff --git a/lua/lib/session.lua b/lua/lib/session.lua index 9887ba2..e52925f 100644 --- a/lua/lib/session.lua +++ b/lua/lib/session.lua @@ -10,7 +10,6 @@ local session = { } ---Get available sessions ----@private ---@return table local function get_sessions() local sessions = {} @@ -28,7 +27,7 @@ local function delete_session() local sessions = get_sessions() if #sessions >= 1 then - require "telescope" + pcall(require, "telescope") vim.ui.select(sessions, { prompt = "Select session to delete:", default = nil, @@ -53,7 +52,7 @@ local function restore_session() local sessions = get_sessions() if #sessions >= 1 then - require "telescope" + pcall(require, "telescope") vim.ui.select(sessions, { prompt = " > Select session to restore", format_item = function(item) @@ -78,7 +77,7 @@ end --- The session is saved into 'data' stdpath of nvim ---@see mksession |:mksession| local function save_session() - require "telescope" + pcall(require, "telescope") vim.ui.input({ prompt = "Enter session name: ", default = nil, @@ -113,4 +112,4 @@ function session.select(arg) end end -return session \ No newline at end of file +return session diff --git a/lua/lib/terminal.lua b/lua/lib/terminal.lua index 643c7a6..ebed9f1 100644 --- a/lua/lib/terminal.lua +++ b/lua/lib/terminal.lua @@ -55,7 +55,7 @@ function M.new_terminal_win(cmd, autoclose, opts) if opts.preset then opts = M.presets[opts.preset] end - local buf = vim.api.nvim_create_buf(false, false) + local buf = vim.api.nvim_create_buf(not autoclose, false) -- if autoclose -> buf = not listed local width = opts.width or nil local height = opts.height or nil local rows = opts.relative and math.ceil(vim.o.lines - height) * 0.5 - 1 or nil diff --git a/lua/lib/ui/statusline.lua b/lua/lib/ui/statusline.lua index 575bcc7..a9397c3 100644 --- a/lua/lib/ui/statusline.lua +++ b/lua/lib/ui/statusline.lua @@ -268,10 +268,12 @@ end local function get_lsp_progress() local lsp = vim.lsp.status() if lsp then - lsp = lsp:gsub(":", " ") - lsp = lsp:gsub("(%d+%%)", "%1%%") -- sanitize percentage - lsp = lsp:gsub("%s+", " ") - return lsp + vim.print(lsp) + -- sanitize percentage + lsp = vim.fn.fnameescape(lsp) + -- lsp = lsp:gsub(":", " "):gsub("(%d+%%)", "%1%%"):gsub("%s+", " ") + + return (#lsp > 40) and string.sub(lsp, 1, 38) .. "…" or lsp end return "" @@ -433,7 +435,7 @@ local function enable_statusline() "", sl.colors.empty, session_name(), - get_lsp_progress(), + -- get_lsp_progress(), get_python_env(), -- Middle @@ -486,7 +488,7 @@ function sl.toggle() "FileType", "FileChangedShellPost", "DiagnosticChanged", - "LspProgress", + -- "LspProgress", }, { group = vim.api.nvim_create_augroup("_statusline", { clear = true }), callback = function(cb) diff --git a/lua/plugins/editor/completion.lua b/lua/plugins/editor/completion.lua index 9557f33..6ff2621 100644 --- a/lua/plugins/editor/completion.lua +++ b/lua/plugins/editor/completion.lua @@ -34,13 +34,8 @@ return { }, sources = { - default = { "snippets", "lsp", "path", "buffer", "lazydev" }, + default = { "snippets", "lsp", "path", "buffer", "markdown", "lazydev" }, providers = { - lazydev = { - name = "LazyDev", - module = "lazydev.integrations.blink", - score_offset = 100, - }, snippets = { opts = { extended_filetypes = { @@ -50,6 +45,15 @@ return { }, }, }, + markdown = { + name = "RenderMarkdown", + module = "render-markdown.integ.blink", + }, + lazydev = { + name = "LazyDev", + module = "lazydev.integrations.blink", + score_offset = 100, + }, }, min_keyword_length = function(ctx) return ctx.mode == "cmdline" and 2 or 0 @@ -111,4 +115,4 @@ return { ghost_text = { enabled = true }, }, }, -} \ No newline at end of file +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index ea94d9e..eba5361 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -176,7 +176,7 @@ local M = { ---LaTeX { "lervag/vimtex", - ft = { "tex", "plaintex" }, + ft = { "tex", "plaintex", "bib" }, config = function() vim.g.vimtex_view_method = "sioyek" vim.g.vimtex_quickfix_mode = 0 -- don't open qflist on compile errors @@ -406,4 +406,4 @@ local M = { }, } -return M +return M \ No newline at end of file diff --git a/lua/plugins/lsp/init.lua b/lua/plugins/lsp/init.lua index 3c1546f..89fda68 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/plugins/lsp/init.lua @@ -529,6 +529,20 @@ return { }, })) end, + + texlab = function() + lspconfig.texlab.setup(vim.tbl_deep_extend("force", default_lsp_config, { + settings = { + texlab = { + auxDirectory = string.format( + "%s/vimtex/aux_dir/%s", + vim.fn.stdpath "cache", + vim.fs.basename(vim.api.nvim_buf_get_name(0)) + ), + }, + }, + })) + end, } end, }, @@ -695,4 +709,4 @@ return { capabilities = init_capabilities, on_init = custom_init, on_attach = custom_attach, -} \ No newline at end of file +} diff --git a/lua/plugins/ui/noice.lua b/lua/plugins/ui/notifications.lua similarity index 89% rename from lua/plugins/ui/noice.lua rename to lua/plugins/ui/notifications.lua index b2e8c28..b91d364 100644 --- a/lua/plugins/ui/noice.lua +++ b/lua/plugins/ui/notifications.lua @@ -1,8 +1,8 @@ ---------------------------------------- --- File : noice.lua --- Description : noice plugin configuration +-- File : notifications.lua +-- Description : notifications plugins config -- Author : Kevin --- Last Modified: 26 Dec 2024, 11:05 +-- Last Modified: 06/01/2025 - 10:19 ---------------------------------------- return { @@ -44,4 +44,4 @@ return { vim.notify = notify end, }, -} +} \ No newline at end of file diff --git a/plugin/autocommands.lua b/plugin/autocommands.lua index b01e226..33f46fd 100644 --- a/plugin/autocommands.lua +++ b/plugin/autocommands.lua @@ -294,16 +294,16 @@ autocmd("FileType", { ---Templates autocmd("BufNewFile", { - group = vim.api.nvim_create_augroup("templates", { clear = true }), + group = augroup("templates", { clear = true }), desc = "Load template file", - pattern = "*", + pattern = { "pom.xml", "*.md", "*.sh" }, callback = function(args) local path = vim.fn.stdpath "config" local fname = vim.fn.fnamemodify(args.file, ":t") local ext = vim.fn.fnamemodify(args.file, ":e") local candidates = { fname, ext } local uv = vim.uv - vim.print(candidates) + -- vim.print(candidates) for _, candidate in ipairs(candidates) do local tmpl = table.concat { path, "/templates/", candidate, ".tpl" } if uv.fs_stat(tmpl) then @@ -325,3 +325,14 @@ autocmd("BufNewFile", { end end, }) + +---Lsp progress +autocmd("LspProgress", { + group = augroup("_lsp_progress", { clear = true }), + callback = function() + local lsp = vim.lsp.status() + if lsp then + print(lsp) + end + end, +}) diff --git a/plugin/keymaps.lua b/plugin/keymaps.lua index c7c41b2..9b1062d 100644 --- a/plugin/keymaps.lua +++ b/plugin/keymaps.lua @@ -241,6 +241,7 @@ nmap { function() local height = math.floor(vim.o.lines * 0.25) require("lib.terminal").new_terminal_win("", true, { + listed = true, height = height, win = -1, split = "below", @@ -254,6 +255,7 @@ nmap { function() local width = math.floor(vim.o.columns * 0.4) require("lib.terminal").new_terminal_win("", true, { + listed = true, width = width, win = -1, split = "right", @@ -498,4 +500,4 @@ vim.cmd.cnoreabbrev("XA", "xa") -- end -- end, -- { desc = "Snippet jump backwards" }, --- } \ No newline at end of file +-- } diff --git a/snippets/general/all.json b/snippets/general/all.json index 0750cec..4de94a3 100644 --- a/snippets/general/all.json +++ b/snippets/general/all.json @@ -16,4 +16,4 @@ "body": ["${CURRENT_HOUR}:${CURRENT_MINUTE}"], "description": "Timestamp" } -} +} \ No newline at end of file diff --git a/snippets/general/java/java.json b/snippets/general/java/java.json index 4fab715..4fceb33 100644 --- a/snippets/general/java/java.json +++ b/snippets/general/java/java.json @@ -1,165 +1,157 @@ { - "main": { - "prefix": "main", - "body": ["public static void main(String[] args) {", "\t$0", "}"], - "description": "Public static main method" - }, - "class": { - "prefix": "class", - "body": ["public class ${TM_FILENAME_BASE} {", "\t$0", "}"], - "description": "Public class" - }, - "sysout": { - "prefix": "sysout", - "body": ["System.out.println($0);"], - "description": "Print to standard out" - }, - "syserr": { - "prefix": "syserr", - "body": ["System.err.println($0);"], - "description": "Print to standard err" - }, - "fori": { - "prefix": "fori", - "body": [ - "for (${1:int} ${2:i} = ${3:0}; $2 < ${4:max}; $2++) {", - "\t$0", - "}" - ], - "description": "Indexed for loop" - }, - "foreach": { - "prefix": "foreach", - "body": ["for (${1:type} ${2:var} : ${3:iterable}) {", "\t$0", "}"], - "description": "Enhanced for loop" - }, - "Public constructor": { - "prefix": "ctor", - "body": [ - "public ${1:${TM_FILENAME_BASE}}($2) {", - "\t${0:super();}", - "}" - ], - "description": "Public constructor" - }, - "if": { - "prefix": "if", - "body": ["if (${1:condition}) {", "\t$0", "}"], - "description": "if statement" - }, - "ifelse": { - "prefix": "ifelse", - "body": ["if (${1:condition}) {", "\t$2", "} else {", "\t$0", "}"], - "description": "if/else statement" - }, - "ifnull": { - "prefix": "ifnull", - "body": ["if (${1:condition} == null) {", "\t$0", "}"], - "description": "if statement checking for null" - }, - "ifnotnull": { - "prefix": "ifnotnull", - "body": ["if (${1:condition} != null) {", "\t$0", "}"], - "description": "if statement checking for not null" - }, - "trycatch": { - "prefix": "try_catch", - "body": [ - "try {", - "\t$1", - "} catch (${2:Exception} ${3:e}) {", - "\t$4//${0:TODO}: handle exception", - "}" - ], - "description": "try/catch block" - }, - "tryresources": { - "prefix": "try_resources", - "body": [ - "try ($1) {", - "\t$2", - "} catch (${3:Exception} ${4:e}) {", - "\t$5//${0:TODO}: handle exception", - "}" - ] - }, - "private_method": { - "prefix": "private_method", - "body": ["private ${1:void} ${2:name}($3) {", "\t$0", "}"], - "description": "private method" - }, - "Public method": { - "prefix": "public_method", - "body": ["public ${1:void} ${2:name}(${3}) {", "\t$0", "}"], - "description": "public method" - }, - "Private static method": { - "prefix": "private_static_method", - "body": ["private static ${1:Type} ${2:name}(${3}) {", "\t$0", "}"], - "description": "private static method" - }, - "Public static method": { - "prefix": "public_static_method", - "body": ["public static ${1:void} ${2:name}(${3}) {", "\t$0", "}"], - "description": "public static method" - }, - "Protected Method": { - "prefix": "protected_method", - "body": ["protected ${1:void} ${2:name}(${3}) {", "\t$0", "}"], - "description": "Protected method" - }, - "Switch Statement": { - "prefix": "switch", - "body": [ - "switch (${1:key}) {", - "\tcase ${2:value}:", - "\t\t$0", - "\t\tbreak;", - "", - "\tdefault:", - "\t\tbreak;", - "}" - ], - "description": "Switch Statement" - }, - "While Statement": { - "prefix": "while", - "body": ["while (${1:condition}) {", "\t$0", "}"], - "description": "While Statement" - }, - "Do-While Statement": { - "prefix": "dowhile", - "body": ["do {", "\t$0", "} while (${1:condition});"], - "description": "Do-While Statement" - }, - "newObject": { - "prefix": "new", - "body": ["${1:Object} ${2:foo} = new ${1:Object}();"], - "description": "Create new Object" - }, - "Public field": { - "prefix": "public_field", - "body": ["public ${1:String} ${2:name};"], - "description": "Public field" - }, - "Private field": { - "prefix": "private_field", - "body": ["private ${1:String} ${2:name};"], - "description": "Private field" - }, - "Protected field": { - "prefix": "protected_field", - "body": ["protected ${1:String} ${2:name};"], - "description": "Protected field" - }, - "package": { - "prefix": "package", - "body": ["package ${1:PackageName}"], - "description": "Package statement" - }, - "import": { - "prefix": "import", - "body": ["import ${1:PackageName}"], - "description": "Import statement" - } -} + "main": { + "prefix": "main", + "body": ["public static void main(String[] args) {", "\t$0", "}"], + "description": "Public static main method" + }, + "class": { + "prefix": "class", + "body": ["public class ${TM_FILENAME_BASE} {", "\t$0", "}"], + "description": "Public class" + }, + "sysout": { + "prefix": "sysout", + "body": ["System.out.println($0);"], + "description": "Print to standard out" + }, + "syserr": { + "prefix": "syserr", + "body": ["System.err.println($0);"], + "description": "Print to standard err" + }, + "fori": { + "prefix": "fori", + "body": ["for (${1:int} ${2:i} = ${3:0}; $2 < ${4:max}; $2++) {", "\t$0", "}"], + "description": "Indexed for loop" + }, + "foreach": { + "prefix": "foreach", + "body": ["for (${1:type} ${2:var} : ${3:iterable}) {", "\t$0", "}"], + "description": "Enhanced for loop" + }, + "Public constructor": { + "prefix": "ctor", + "body": ["public ${1:${TM_FILENAME_BASE}}($2) {", "\t${0:super();}", "}"], + "description": "Public constructor" + }, + "if": { + "prefix": "if", + "body": ["if (${1:condition}) {", "\t$0", "}"], + "description": "if statement" + }, + "ifelse": { + "prefix": "ifelse", + "body": ["if (${1:condition}) {", "\t$2", "} else {", "\t$0", "}"], + "description": "if/else statement" + }, + "ifnull": { + "prefix": "ifnull", + "body": ["if (${1:condition} == null) {", "\t$0", "}"], + "description": "if statement checking for null" + }, + "ifnotnull": { + "prefix": "ifnotnull", + "body": ["if (${1:condition} != null) {", "\t$0", "}"], + "description": "if statement checking for not null" + }, + "trycatch": { + "prefix": "try_catch", + "body": [ + "try {", + "\t$1", + "} catch (${2:Exception} ${3:e}) {", + "\t$4//${0:TODO}: handle exception", + "}" + ], + "description": "try/catch block" + }, + "tryresources": { + "prefix": "try_resources", + "body": [ + "try ($1) {", + "\t$2", + "} catch (${3:Exception} ${4:e}) {", + "\t$5//${0:TODO}: handle exception", + "}" + ] + }, + "private_method": { + "prefix": "private_method", + "body": ["private ${1:void} ${2:name}($3) {", "\t$0", "}"], + "description": "private method" + }, + "Public method": { + "prefix": "public_method", + "body": ["public ${1:void} ${2:name}(${3}) {", "\t$0", "}"], + "description": "public method" + }, + "Private static method": { + "prefix": "private_static_method", + "body": ["private static ${1:Type} ${2:name}(${3}) {", "\t$0", "}"], + "description": "private static method" + }, + "Public static method": { + "prefix": "public_static_method", + "body": ["public static ${1:void} ${2:name}(${3}) {", "\t$0", "}"], + "description": "public static method" + }, + "Protected Method": { + "prefix": "protected_method", + "body": ["protected ${1:void} ${2:name}(${3}) {", "\t$0", "}"], + "description": "Protected method" + }, + "Switch Statement": { + "prefix": "switch", + "body": [ + "switch (${1:key}) {", + "\tcase ${2:value}:", + "\t\t$0", + "\t\tbreak;", + "", + "\tdefault:", + "\t\tbreak;", + "}" + ], + "description": "Switch Statement" + }, + "While Statement": { + "prefix": "while", + "body": ["while (${1:condition}) {", "\t$0", "}"], + "description": "While Statement" + }, + "Do-While Statement": { + "prefix": "dowhile", + "body": ["do {", "\t$0", "} while (${1:condition});"], + "description": "Do-While Statement" + }, + "newObject": { + "prefix": "new", + "body": ["${1:Object} ${2:foo} = new ${1:Object}();"], + "description": "Create new Object" + }, + "Public field": { + "prefix": "public_field", + "body": ["public ${1:String} ${2:name};"], + "description": "Public field" + }, + "Private field": { + "prefix": "private_field", + "body": ["private ${1:String} ${2:name};"], + "description": "Private field" + }, + "Protected field": { + "prefix": "protected_field", + "body": ["protected ${1:String} ${2:name};"], + "description": "Protected field" + }, + "package": { + "prefix": "package", + "body": ["package ${1:PackageName}"], + "description": "Package statement" + }, + "import": { + "prefix": "import", + "body": ["import ${1:PackageName}"], + "description": "Import statement" + } +} \ No newline at end of file diff --git a/snippets/general/java/java_tests.json b/snippets/general/java/java_tests.json index 28eba54..782ab82 100644 --- a/snippets/general/java/java_tests.json +++ b/snippets/general/java/java_tests.json @@ -1,194 +1,176 @@ { - "JUnit 4 - Imports for Tests": { - "prefix": "imports_junit4", - "body": [ - "import static org.hamcrest.Matchers.*;", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertThat;", - "import static org.mockito.Mockito.*;", - "import org.hamcrest.CoreMatchers;", - "import org.junit.After;", - "import org.junit.Before;", - "import org.junit.Test;", - "import org.mockito.ArgumentCaptor;", - "import org.mockito.Mock;" - ], - "description": "Imports to write tests with JUnit 4, Mockito and Hamcrest" - }, - "JUnit 5 - Imports for Tests": { - "prefix": "imports_junit5", - "body": [ - "import static org.hamcrest.Matchers.*;", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.junit.jupiter.api.Assertions.assertEquals;", - "import static org.mockito.Mockito.*;", - "import org.hamcrest.CoreMatchers;", - "import org.junit.jupiter.api.AfterEach;", - "import org.junit.jupiter.api.BeforeEach;", - "import org.junit.jupiter.api.DisplayName;", - "import org.junit.jupiter.api.Test;", - "import org.junit.jupiter.api.extension.ExtendWith;", - "import org.junit.jupiter.params.ParameterizedTest;", - "import org.junit.jupiter.params.provider.CsvSource;", - "import org.mockito.ArgumentCaptor;", - "import org.mockito.junit.jupiter.MockitoExtension;", - "import org.mockito.Mock;" - ], - "description": "Imports to write tests with JUnit 4, Mockito and Hamcrest" - }, - "Assert - equals": { - "prefix": "test_equals", - "body": ["assertEquals(${1:anObject}, ${2:anotherObject});"], - "description": "assert equals" - }, - "Assert - is": { - "prefix": "test_is", - "body": [ - "assertThat(${1:mockedService.executeMagic()}, is(${2:\"42\"}));" - ], - "description": "assert that is" - }, - "Assert - is null": { - "prefix": "test_null", - "body": ["assertThat(${1:mockedService.executeMagic()}, nullValue());"], - "description": "assert that is null" - }, - "Assert - is not null": { - "prefix": "test_not_null", - "body": [ - "assertThat(${1:mockedService.executeMagic()}, notNullValue());" - ], - "description": "assert that is not null" - }, - "Assert - string is null or empty": { - "prefix": "test_nullorempty", - "body": [ - "assertThat(${1:mockedService.executeMagic()}, emptyOrNullString());" - ], - "description": "assert that a string is null or empty" - }, - "Assert - string is not null and not empty": { - "prefix": "test_not_nullorempty", - "body": [ - "assertThat(${1:mockedService.executeMagic()}, not(emptyOrNullString()));" - ], - "description": "assert that string is not null or empty" - }, - "Assert - isOneOf": { - "prefix": "test_isOneOf", - "body": ["assertThat(${1:\"Test\"}, isOneOf(${2:\"Test\", \"TDD\"}));"], - "description": "assert that isOneOf" - }, - "Assert - hasSize": { - "prefix": "test_hasSize", - "body": ["assertThat(List.of(\"Test\", \"TDD\"), hasSize(2));"], - "description": "assert that hasSize" - }, - "Assert - hasItem": { - "prefix": "test_hasItem", - "body": [ - "assertThat(${1:List.of(\"Test\", \"TDD\")}, hasItem(${2:\"Test\"}));" - ], - "description": "assert that hasItem" - }, - "Assert - hasItems": { - "prefix": "test_hasItems", - "body": [ - "assertThat(${1:List.of(\"Test\", \"TDD\")}, hasItem(${2:List.of(\"Test\", \"TDD\")}));" - ], - "description": "assert that hasItem" - }, - "Assert - isIn": { - "prefix": "test_isIn", - "body": [ - "assertThat(${1:\"test\"}, isIn(${2:List.of(\"test\", \"TDD\")}));" - ], - "description": "assert that isIn" - }, - "Mockito - Create mock": { - "prefix": "mock_class", - "body": [ - "${1:MyService} ${2:mockedService} = mock(${1:MyService}.class);" - ], - "description": "Create a mock object of a class" - }, - "Mock - Method return": { - "prefix": "mock_method_return", - "body": [ - "when(${1:mockedService.executeMagicWith(any())}).thenReturn(${2:\"42\"});" - ], - "description": "Mock a method's return" - }, - "Mock - Method throws": { - "prefix": "mock_method_throw", - "body": [ - "when(${1:mockedService.executeMagic()}).thenThrow(new ${2:IllegalArgumentException()};" - ], - "description": "Mock a method to throw exception" - }, - "Mockito - Verify call only": { - "prefix": "mock_verify_only", - "body": ["verify(${1:mockedService}, only()).${2:executeMagic()};"], - "description": "Verify if a mocked method was the only one called" - }, - "Mockito - Verify call once": { - "prefix": "mock_verify_once", - "body": ["verify(${1:mockedService}).${2:executeMagic()};"], - "description": "Verify if a mocked method was called only once" - }, - "Mockito - Verify call N times": { - "prefix": "mock_verify_times", - "body": [ - "verify(${1:mockedService}, times(${2:2})).${3:executeMagic()};" - ], - "description": "Verify if a mocked method was called `n` times" - }, - "Mockito - Verify never called": { - "prefix": "mock_verify_never", - "body": ["verify(${1:mockedService}, never()).${2:executeMagic()};"], - "description": "Verify if a mocked method was never called" - }, - "Mock - Argument captor": { - "prefix": "mock_arg_capture", - "body": [ - "ArgumentCaptor<${1:Object}> ${2:argCaptor} = ArgumentCaptor.forClass(${1:Object}.class);", - "verify(${3:mockedService}).${4:executeMagicWith}(${2:argCaptor}.capture());", - "${1:Object} ${5:actualArg} = ${2:argCaptor}.getValue();" - ], - "description": "Capture an argument given to a mocked method" - }, - "JUnit 4 - Before each": { - "prefix": "test_before_junit4", - "body": "@Before\npublic void setup() {\n\t${1}\n}", - "description": "Create setup method with `@Before`" - }, - "JUnit 4 - After each": { - "prefix": "test_after_junit4", - "body": "@After\npublic void tearDown() {\n\t${1}\n}", - "description": "Create tear down method with `@After`" - }, - "JUnit 5 - Before each": { - "prefix": "test_before", - "body": "@BeforeEach\npublic void setup() {\n\t${1}\n}", - "description": "Create setup method with `@BeforeEach`" - }, - "JUnit 5 - After each": { - "prefix": "test_after", - "body": "@AfterEach\npublic void tearDown() {\n\t${1}\n}", - "description": "Create tear down method with `@AfterEach`" - }, - "JUnit 5 - Assert Throws": { - "prefix": "test_exception", - "body": "Assertions.assertThrows(${1:Exception}.class, () -> {\n\t${0}\n});", - "description": "Assertion to verify if an exception was thrown" - }, - "JUnit 5 - Parameterized Test": { - "prefix": "test_parameterized", - "description": "Create parameterized test", - "body": [ - "@ParameterizedTest(name = \"${1:{0\\} plus {1\\} should be {2\\}}\"", - "@CsvSource({\n\t${2:\"0, 0, 0\",\n\t\"1, 0, 1\",\n\t\"1, 1, 2\"}\n})", - "public void shouldAddTwoNumbers(int x, int y, int expectedSum) {\n\t${0}\n}" - ] - } -} + "JUnit 4 - Imports for Tests": { + "prefix": "imports_junit4", + "body": [ + "import static org.hamcrest.Matchers.*;", + "import static org.junit.Assert.assertEquals;", + "import static org.junit.Assert.assertThat;", + "import static org.mockito.Mockito.*;", + "import org.hamcrest.CoreMatchers;", + "import org.junit.After;", + "import org.junit.Before;", + "import org.junit.Test;", + "import org.mockito.ArgumentCaptor;", + "import org.mockito.Mock;" + ], + "description": "Imports to write tests with JUnit 4, Mockito and Hamcrest" + }, + "JUnit 5 - Imports for Tests": { + "prefix": "imports_junit5", + "body": [ + "import static org.hamcrest.Matchers.*;", + "import static org.hamcrest.MatcherAssert.assertThat;", + "import static org.junit.jupiter.api.Assertions.assertEquals;", + "import static org.mockito.Mockito.*;", + "import org.hamcrest.CoreMatchers;", + "import org.junit.jupiter.api.AfterEach;", + "import org.junit.jupiter.api.BeforeEach;", + "import org.junit.jupiter.api.DisplayName;", + "import org.junit.jupiter.api.Test;", + "import org.junit.jupiter.api.extension.ExtendWith;", + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.junit.jupiter.params.provider.CsvSource;", + "import org.mockito.ArgumentCaptor;", + "import org.mockito.junit.jupiter.MockitoExtension;", + "import org.mockito.Mock;" + ], + "description": "Imports to write tests with JUnit 4, Mockito and Hamcrest" + }, + "Assert - equals": { + "prefix": "test_equals", + "body": ["assertEquals(${1:anObject}, ${2:anotherObject});"], + "description": "assert equals" + }, + "Assert - is": { + "prefix": "test_is", + "body": ["assertThat(${1:mockedService.executeMagic()}, is(${2:\"42\"}));"], + "description": "assert that is" + }, + "Assert - is null": { + "prefix": "test_null", + "body": ["assertThat(${1:mockedService.executeMagic()}, nullValue());"], + "description": "assert that is null" + }, + "Assert - is not null": { + "prefix": "test_not_null", + "body": ["assertThat(${1:mockedService.executeMagic()}, notNullValue());"], + "description": "assert that is not null" + }, + "Assert - string is null or empty": { + "prefix": "test_nullorempty", + "body": ["assertThat(${1:mockedService.executeMagic()}, emptyOrNullString());"], + "description": "assert that a string is null or empty" + }, + "Assert - string is not null and not empty": { + "prefix": "test_not_nullorempty", + "body": ["assertThat(${1:mockedService.executeMagic()}, not(emptyOrNullString()));"], + "description": "assert that string is not null or empty" + }, + "Assert - isOneOf": { + "prefix": "test_isOneOf", + "body": ["assertThat(${1:\"Test\"}, isOneOf(${2:\"Test\", \"TDD\"}));"], + "description": "assert that isOneOf" + }, + "Assert - hasSize": { + "prefix": "test_hasSize", + "body": ["assertThat(List.of(\"Test\", \"TDD\"), hasSize(2));"], + "description": "assert that hasSize" + }, + "Assert - hasItem": { + "prefix": "test_hasItem", + "body": ["assertThat(${1:List.of(\"Test\", \"TDD\")}, hasItem(${2:\"Test\"}));"], + "description": "assert that hasItem" + }, + "Assert - hasItems": { + "prefix": "test_hasItems", + "body": [ + "assertThat(${1:List.of(\"Test\", \"TDD\")}, hasItem(${2:List.of(\"Test\", \"TDD\")}));" + ], + "description": "assert that hasItem" + }, + "Assert - isIn": { + "prefix": "test_isIn", + "body": ["assertThat(${1:\"test\"}, isIn(${2:List.of(\"test\", \"TDD\")}));"], + "description": "assert that isIn" + }, + "Mockito - Create mock": { + "prefix": "mock_class", + "body": ["${1:MyService} ${2:mockedService} = mock(${1:MyService}.class);"], + "description": "Create a mock object of a class" + }, + "Mock - Method return": { + "prefix": "mock_method_return", + "body": ["when(${1:mockedService.executeMagicWith(any())}).thenReturn(${2:\"42\"});"], + "description": "Mock a method's return" + }, + "Mock - Method throws": { + "prefix": "mock_method_throw", + "body": [ + "when(${1:mockedService.executeMagic()}).thenThrow(new ${2:IllegalArgumentException()};" + ], + "description": "Mock a method to throw exception" + }, + "Mockito - Verify call only": { + "prefix": "mock_verify_only", + "body": ["verify(${1:mockedService}, only()).${2:executeMagic()};"], + "description": "Verify if a mocked method was the only one called" + }, + "Mockito - Verify call once": { + "prefix": "mock_verify_once", + "body": ["verify(${1:mockedService}).${2:executeMagic()};"], + "description": "Verify if a mocked method was called only once" + }, + "Mockito - Verify call N times": { + "prefix": "mock_verify_times", + "body": ["verify(${1:mockedService}, times(${2:2})).${3:executeMagic()};"], + "description": "Verify if a mocked method was called `n` times" + }, + "Mockito - Verify never called": { + "prefix": "mock_verify_never", + "body": ["verify(${1:mockedService}, never()).${2:executeMagic()};"], + "description": "Verify if a mocked method was never called" + }, + "Mock - Argument captor": { + "prefix": "mock_arg_capture", + "body": [ + "ArgumentCaptor<${1:Object}> ${2:argCaptor} = ArgumentCaptor.forClass(${1:Object}.class);", + "verify(${3:mockedService}).${4:executeMagicWith}(${2:argCaptor}.capture());", + "${1:Object} ${5:actualArg} = ${2:argCaptor}.getValue();" + ], + "description": "Capture an argument given to a mocked method" + }, + "JUnit 4 - Before each": { + "prefix": "test_before_junit4", + "body": "@Before\npublic void setup() {\n\t${1}\n}", + "description": "Create setup method with `@Before`" + }, + "JUnit 4 - After each": { + "prefix": "test_after_junit4", + "body": "@After\npublic void tearDown() {\n\t${1}\n}", + "description": "Create tear down method with `@After`" + }, + "JUnit 5 - Before each": { + "prefix": "test_before", + "body": "@BeforeEach\npublic void setup() {\n\t${1}\n}", + "description": "Create setup method with `@BeforeEach`" + }, + "JUnit 5 - After each": { + "prefix": "test_after", + "body": "@AfterEach\npublic void tearDown() {\n\t${1}\n}", + "description": "Create tear down method with `@AfterEach`" + }, + "JUnit 5 - Assert Throws": { + "prefix": "test_exception", + "body": "Assertions.assertThrows(${1:Exception}.class, () -> {\n\t${0}\n});", + "description": "Assertion to verify if an exception was thrown" + }, + "JUnit 5 - Parameterized Test": { + "prefix": "test_parameterized", + "description": "Create parameterized test", + "body": [ + "@ParameterizedTest(name = \"${1:{0\\} plus {1\\} should be {2\\}}\"", + "@CsvSource({\n\t${2:\"0, 0, 0\",\n\t\"1, 0, 1\",\n\t\"1, 1, 2\"}\n})", + "public void shouldAddTwoNumbers(int x, int y, int expectedSum) {\n\t${0}\n}" + ] + } +} \ No newline at end of file diff --git a/snippets/general/java/javadoc.json b/snippets/general/java/javadoc.json index 267832e..0371ad1 100644 --- a/snippets/general/java/javadoc.json +++ b/snippets/general/java/javadoc.json @@ -1,127 +1,99 @@ { - "comment": { - "prefix": "/**", - "body": [ - "/**", - " * ${1:A one-line summary.}", - " *", - " * ${2:Description.}$0", - " *", - " * @param ${4:name} ${5:Type and description of the parameter.}", - " * @return ${6:Type and description of the returned object.}", - " *", - " * @example", - " * ```", - " * ${7:Write me later}", - " * ```", - " */" - ], - "description": "A Java comment block including short summary, description, param, return, and examples." - }, - "comment_simple": { - "prefix": "/*", - "body": [ - "/**", - " * ${1:A one-line summary.}", - " *", - " * ${2:Description.}$0", - " */" - ], - "description": "A simple Java comment block with short summary and description. Useful when the user prefers to manually add the other documentation tags." - }, - "@param": { - "prefix": "@param", - "body": [ - "@param ${1:name} ${2:Type and description of the parameter.}$0" - ], - "description": "Documents a parameter." - }, - "@return": { - "prefix": "@return", - "body": [ - "@param ${1:name} ${2:Type and description of the parameter.}$0" - ], - "description": "Documents a the returned object." - }, - "@example": { - "prefix": "@example", - "body": [ - "@example", - "```", - "${1:Write me later}$0", - "```" - ], - "description": "Adds an example to the documentation." - }, - "@see": { - "prefix": "@see", - "body": [ - "@see ${1:item.}$0" - ], - "description": "References another item or piece of documentation." - }, - "@throws": { - "prefix": "@throws", - "body": [ - "@throws ${1:IOException} ${2:Description.}$0" - ], - "description": "Document an exception raised by the item. Synonym of @exception." - }, - "@exception": { - "prefix": "@exception", - "body": [ - "@exception ${1:IOException} ${2:Description.}$0" - ], - "description": "Document an exception raised by the item. Synonym of @throws." - }, - "@since": { - "prefix": "@since", - "body": [ - "@since ${1:1.0}$0" - ], - "description": "Version of Java when the the product was implemented." - }, - "@serial": { - "prefix": "@serial", - "body": [ - "@serial ${1:Field description.}$0" - ], - "description": "The @serial tag should be placed in the javadoc comment for a default serializable field. Using @serial at a class level overrides @serial at a package level." - }, - "@serialField": { - "prefix": "@serialField", - "body": [ - "@serialField ${1:Field name} ${2:Field type} ${3:Field description.}$0" - ], - "description": "The @serialField tag is used to document an ObjectStreamField component of a serialPersistentFields array. One of these tags should be used for each ObjectStreamField component." - }, - "@serialData": { - "prefix": "@serialData", - "body": [ - "@serialData ${1:Data description.}$0" - ], - "description": "The @serialData tag describes the sequences and types of data written or read. The tag describes the sequence and type of optional data written by writeObject or all data written by the Externalizable.writeExternal method." - }, - "@author": { - "prefix": "@author", - "body": [ - "@author ${1:name}$0" - ], - "description": "You can provide one @author tag, multiple @author tags, or no @author tags. For classes and interfaces only, required." - }, - "@version": { - "prefix": "@version", - "body": [ - "@version ${1:1.39}, ${2:02/28/97}$0" - ], - "description": "The Java Software convention for the argument to the @version tag is the SCCS string \"%I%, %G%\". For classes and interfaces only, required." - }, - "@deprecated": { - "prefix": "@deprecated", - "body": [ - "@deprecated As of JDK ${1:1.1}, replaced by", - "${2:{@link #setBounds(int,int,int,int)}}$0" - ], - "description": "The @deprecated description in the first sentence should at least tell the user when the API was deprecated and what to use as a replacement. Only the first sentence will appear in the summary section and index. Subsequent sentences can also explain why it has been deprecated." - } -} + "comment": { + "prefix": "/**", + "body": [ + "/**", + " * ${1:A one-line summary.}", + " *", + " * ${2:Description.}$0", + " *", + " * @param ${4:name} ${5:Type and description of the parameter.}", + " * @return ${6:Type and description of the returned object.}", + " *", + " * @example", + " * ```", + " * ${7:Write me later}", + " * ```", + " */" + ], + "description": "A Java comment block including short summary, description, param, return, and examples." + }, + "comment_simple": { + "prefix": "/*", + "body": ["/**", " * ${1:A one-line summary.}", " *", " * ${2:Description.}$0", " */"], + "description": "A simple Java comment block with short summary and description. Useful when the user prefers to manually add the other documentation tags." + }, + "@param": { + "prefix": "@param", + "body": ["@param ${1:name} ${2:Type and description of the parameter.}$0"], + "description": "Documents a parameter." + }, + "@return": { + "prefix": "@return", + "body": ["@param ${1:name} ${2:Type and description of the parameter.}$0"], + "description": "Documents a the returned object." + }, + "@example": { + "prefix": "@example", + "body": ["@example", "```", "${1:Write me later}$0", "```"], + "description": "Adds an example to the documentation." + }, + "@see": { + "prefix": "@see", + "body": ["@see ${1:item.}$0"], + "description": "References another item or piece of documentation." + }, + "@code": { + "prefix": "@see", + "body": ["@code ${1:item.}$0"], + "description": "References another item or piece of documentation." + }, + "@throws": { + "prefix": "@throws", + "body": ["@throws ${1:IOException} ${2:Description.}$0"], + "description": "Document an exception raised by the item. Synonym of @exception." + }, + "@exception": { + "prefix": "@exception", + "body": ["@exception ${1:IOException} ${2:Description.}$0"], + "description": "Document an exception raised by the item. Synonym of @throws." + }, + "@since": { + "prefix": "@since", + "body": ["@since ${1:1.0}$0"], + "description": "Version of Java when the the product was implemented." + }, + "@serial": { + "prefix": "@serial", + "body": ["@serial ${1:Field description.}$0"], + "description": "The @serial tag should be placed in the javadoc comment for a default serializable field. Using @serial at a class level overrides @serial at a package level." + }, + "@serialField": { + "prefix": "@serialField", + "body": ["@serialField ${1:Field name} ${2:Field type} ${3:Field description.}$0"], + "description": "The @serialField tag is used to document an ObjectStreamField component of a serialPersistentFields array. One of these tags should be used for each ObjectStreamField component." + }, + "@serialData": { + "prefix": "@serialData", + "body": ["@serialData ${1:Data description.}$0"], + "description": "The @serialData tag describes the sequences and types of data written or read. The tag describes the sequence and type of optional data written by writeObject or all data written by the Externalizable.writeExternal method." + }, + "@author": { + "prefix": "@author", + "body": ["@author ${1:name}$0"], + "description": "You can provide one @author tag, multiple @author tags, or no @author tags. For classes and interfaces only, required." + }, + "@version": { + "prefix": "@version", + "body": ["@version ${1:1.39}, ${2:02/28/97}$0"], + "description": "The Java Software convention for the argument to the @version tag is the SCCS string \"%I%, %G%\". For classes and interfaces only, required." + }, + "@deprecated": { + "prefix": "@deprecated", + "body": [ + "@deprecated As of JDK ${1:1.1}, replaced by", + "${2:{@link #setBounds(int,int,int,int)}}$0" + ], + "description": "The @deprecated description in the first sentence should at least tell the user when the API was deprecated and what to use as a replacement. Only the first sentence will appear in the summary section and index. Subsequent sentences can also explain why it has been deprecated." + } +} \ No newline at end of file