From b5095d9097f0c00cbd31e98a9666caf64afacb68 Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Fri, 29 Aug 2025 16:56:33 +0200 Subject: [PATCH] Refactor all the custom modules into better structures. Clear separation of keybindings that belong to cusstom modules. Added custom snippets and vsc snippets. --- lazy-lock.json | 1 + lua/conf.lua | 3 +- lua/config/keymaps.lua | 86 ++++++------------- lua/custom/{journal.lua => journal/init.lua} | 3 +- .../linker.lua => custom/linker/init.lua} | 74 ++++++++-------- lua/custom/todo/init.lua | 21 ----- lua/custom/{typst.lua => typst/init.lua} | 4 +- lua/custom/{uni.lua => uni/init.lua} | 30 ++++--- lua/plugins/custom.lua | 47 ++++++++-- lua/plugins/lsp.lua | 31 +------ lua/plugins/luasnip.lua | 7 ++ lua/plugins/treesitter.lua | 4 +- lua/utils/functions.lua | 66 +++++++++++++- snippets/all.lua | 9 ++ snippets/go.lua | 17 ++++ 15 files changed, 234 insertions(+), 169 deletions(-) rename lua/custom/{journal.lua => journal/init.lua} (92%) rename lua/{utils/linker.lua => custom/linker/init.lua} (85%) rename lua/custom/{typst.lua => typst/init.lua} (98%) rename lua/custom/{uni.lua => uni/init.lua} (88%) create mode 100644 snippets/all.lua create mode 100644 snippets/go.lua diff --git a/lazy-lock.json b/lazy-lock.json index 8778c51..defa122 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -6,6 +6,7 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, "fzf-lua": { "branch": "main", "commit": "bebc84e7ffc8fd86103f6ed6c590df72d524d342" }, "gitsigns.nvim": { "branch": "main", "commit": "6e3c66548035e50db7bd8e360a29aec6620c3641" }, "gruvbox.nvim": { "branch": "main", "commit": "12c2624287dc827edb5d72b2bc4c9619e692a554" }, diff --git a/lua/conf.lua b/lua/conf.lua index 27a9336..b1272c8 100644 --- a/lua/conf.lua +++ b/lua/conf.lua @@ -1,7 +1,8 @@ local config = {} -config.season = "S3" +config.season = "S3" -- Current semester config.projects = vim.fn.expand("~/projects") config.uni_dir = vim.fn.expand("~/projects/university/" .. config.season) +config.user = vim.fn.system('whoami'):gsub('\n', '') return config diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index c5cf720..979e896 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -1,44 +1,22 @@ -- Custom keymaps require("utils.functions") -require("custom.uni") local conf = require("conf") -local links = require("utils.linker") -local user = vim.fn.system('whoami'):gsub('\n', '') - -local function open_cal() - local current_date = os.date("%Y-%m-%d") - local week_number = os.date("%V") - local day_of_week = os.date("%a") - local path = "~/synced/brainstore/calendar/calendar_" .. os.date("%Y") .. ".txt" - local keys = ":e " .. - path .. "/" .. current_date .. " w" .. tonumber(week_number) .. " " .. day_of_week .. "$" - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'n', true) -end - ------------------------------------------------------- --------------------- KEYMAPS ------------------------- ------------------------------------------------------- - -- Fast window switch vim.keymap.set("n", "w", "w") ---------------------- NORMAL ------------------------- - - vim.keymap.set('n', 'zq', ':e ~/synced/brainstore/zettelkasten/input.txt`.zz') - --- Buildin vim - vim.keymap.set("n", "me", ":mes") vim.keymap.set("n", "snt", "set nu") vim.keymap.set("n", "snf", "set nonu") - vim.keymap.set("n", "n", "nzz", { silent = true }) vim.keymap.set("n", "N", "Nzz", { silent = true }) vim.keymap.set("n", "", "zz", { silent = true }) @@ -51,31 +29,10 @@ vim.keymap.set('n', 'tr', ':tabnew:termi') -- Indent all will be replaced by the formatting of lsp where the lsp is installed vim.keymap.set('n', 'ia', 'gg=Gzz') - vim.keymap.set('n', 'ya', 'ggVG"+y') - vim.keymap.set('n', 'ss', ':wa') - --- new quick note file --- TODO: make this smarter vim.keymap.set("n", "nn", ":e ~/synced/brainstore/zettelkasten/quick", { silent = true }) -vim.keymap.set("n", "r", - function() - local current_file = vim.fn.expand('%:p:h') -- get directory of current file - local cmd = 'git -C ' .. vim.fn.fnameescape(current_file) .. ' status' - vim.fn.system(cmd) - if vim.v.shell_error == 0 then - local git_root = vim.fn.systemlist('git -C ' .. - vim.fn.fnameescape(current_file) .. ' rev-parse --show-toplevel') - [1] - vim.cmd('cd ' .. vim.fn.fnameescape(git_root)) - else - vim.cmd('cd ' .. vim.fn.fnameescape(current_file)) - end - end -) - -- Quickly open some buffers vim.keymap.set('n', 'occ', ':e ~/.config/nvim/init.lua`.zz') vim.keymap.set('n', 'oct', ':e ~/synced/vault/contacts/contacts.txt`.zz') @@ -88,8 +45,8 @@ vim.keymap.set('n', 'ocp', ':e ~/.config/nvim/lua/plugins/misc.lua`. vim.keymap.set('n', 'ocf', ':e ~/.config/nvim/lua/utils/functions.lua`.zz') vim.keymap.set('n', 'oca', ':e ~/.config/nvim/lua/utils/after.lua`.zz') vim.keymap.set('n', 'oq', ':e ~/synced/brainstore/input.txt`.zz') -vim.keymap.set('n', 'ohh', ':e ~/configuration/nixos/users/' .. user .. '/home.nix`.zz') -vim.keymap.set('n', 'op', ':e ~/configuration/nixos/users/' .. user .. '/packages.nix`.zz') +vim.keymap.set('n', 'ohh', ':e ~/configuration/nixos/users/' .. conf.user .. '/home.nix`.zz') +vim.keymap.set('n', 'op', ':e ~/configuration/nixos/users/' .. conf.user .. '/packages.nix`.zz') vim.keymap.set('n', 'on', ':e ~/configuration/nixos/configuration.nix`.zz') vim.keymap.set('n', 'om', ':e ~/configuration/nixos/modules') vim.keymap.set('n', 'ow', ':e ~/synced/brainstore/waste.txt') @@ -101,17 +58,7 @@ vim.keymap.set('n', 'ou', ':e ~/projects/university/' .. conf.season .. vim.keymap.set('n', 'oz', ':e ~/.zshrc`.zz') vim.keymap.set('n', 'oaa', ':e ~/.common_shell`.zz') - -vim.keymap.set('n', 'ok', open_cal) -------------------------------------------------------------------------------------- - -vim.keymap.set("n", "lf", links.insert_brainstore_link, { desc = "Link Brainstore file" }) -vim.keymap.set("n", "lm", links.insert_mail_link, { desc = "Link Mail" }) vim.keymap.set('n', 'll', ':Lazy') -vim.keymap.set("n", "lp", links.insert_project_link, { desc = "Link Project" }) -vim.keymap.set("n", "lc", links.insert_contact_link, { desc = "Link Contact" }) -vim.keymap.set("n", "ld", links.insert_date_link, { desc = "Link Contact" }) - vim.keymap.set('n', 'sw', function() local word = vim.fn.expand("") @@ -150,9 +97,6 @@ end, { desc = 'Paste from system clipboard' }) vim.keymap.set('v', 'p', function() vim.cmd('normal! "+p') end, { desc = 'Yank to clipboard and keep the selection' }) -vim.keymap.set("n", "nv", function() - select_course_directory() -end, { desc = "Open UniCourse menu" }) vim.keymap.set('v', 'p', function() local unnamed_content = vim.fn.getreg('""') @@ -235,3 +179,29 @@ vim.keymap.set('n', 'ov', }) end ) + +vim.keymap.set("n", "r", + function() + local current_file = vim.fn.expand('%:p:h') -- get directory of current file + local cmd = 'git -C ' .. vim.fn.fnameescape(current_file) .. ' status' + vim.fn.system(cmd) + if vim.v.shell_error == 0 then + local git_root = vim.fn.systemlist('git -C ' .. + vim.fn.fnameescape(current_file) .. ' rev-parse --show-toplevel') + [1] + vim.cmd('cd ' .. vim.fn.fnameescape(git_root)) + else + vim.cmd('cd ' .. vim.fn.fnameescape(current_file)) + end + end +) + +vim.keymap.set('n', 'ok', function() + local current_date = os.date("%Y-%m-%d") + local week_number = os.date("%V") + local day_of_week = os.date("%a") + local path = "~/synced/brainstore/calendar/calendar_" .. os.date("%Y") .. ".txt" + local keys = ":e " .. + path .. "/" .. current_date .. " w" .. tonumber(week_number) .. " " .. day_of_week .. "$" + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, false, true), 'n', true) +end) diff --git a/lua/custom/journal.lua b/lua/custom/journal/init.lua similarity index 92% rename from lua/custom/journal.lua rename to lua/custom/journal/init.lua index b6004f4..50f1647 100644 --- a/lua/custom/journal.lua +++ b/lua/custom/journal/init.lua @@ -1,7 +1,6 @@ local M = {} -local journal_base_raw = "~/management/brainstore/knowledge/journal" -local journal_base = vim.fn.expand(journal_base_raw) +local journal_base = vim.fn.expand("~/management/brainstore/knowledge/journal") M.open_today = function() local date = os.date("*t") diff --git a/lua/utils/linker.lua b/lua/custom/linker/init.lua similarity index 85% rename from lua/utils/linker.lua rename to lua/custom/linker/init.lua index 8075905..e955fd3 100644 --- a/lua/utils/linker.lua +++ b/lua/custom/linker/init.lua @@ -20,6 +20,26 @@ local function fzf_select(options, prompt, callback) }) end +local function spliting(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do + table.insert(t, str) + end + return t +end + +local function pad2(n) + n = tonumber(n) + if n < 10 then + return "0" .. n + else + return tostring(n) + end +end + function M.insert_brainstore_link() require('telescope.builtin').find_files({ hidden = true, @@ -85,7 +105,7 @@ function M.insert_date_link() local text = string.format("[[date:.%s]]", year) vim.api.nvim_put({ text }, "c", true, true) - local row, col = unpack(vim.api.nvim_win_get_cursor(0)) + local row, col = table.unpack(vim.api.nvim_win_get_cursor(0)) vim.api.nvim_win_set_cursor(0, { row, col - 4 }) vim.cmd("startinsert") end @@ -128,35 +148,35 @@ function M.insert_project_link() "--hidden", "--glob", "!**/.git/*", }, - attach_mappings = function(prompt_bufnr, map) - local actions = require('telescope.actions') - local action_state = require('telescope.actions.state') + attach_mappings = function(prompt_bufnr_new, map_new) + actions = require('telescope.actions') + action_state = require('telescope.actions.state') - local function insert_link() - local selection = action_state.get_selected_entry() + local function insert_link_new() + selection = action_state.get_selected_entry() if not selection then return end - local selected = selection.path or selection.filename or selection[1] + selected = selection.path or selection.filename or selection[1] if selected then - actions.close(prompt_bufnr) + actions.close(prompt_bufnr_new) local link = "[[project:" .. - selected:gsub(vim.fn.expand(projects_dir) .. "/", "") .. "]]" + selected:gsub(vim.fn.expand(projects_dir) .. "/", "") .. "]]" vim.api.nvim_put({ link }, "c", true, true) end end local function insert_link_top() - actions.close(prompt_bufnr) + actions.close(prompt_bufnr_new) local link = "[[project:" .. project .. "]]" vim.api.nvim_put({ link }, "c", true, true) end - map('i', '', insert_link) - map('n', '', insert_link) + map_new('i', '', insert_link_new) + map_new('n', '', insert_link_new) - map('i', '', insert_link_top) - map('n', '', insert_link_top) + map_new('i', '', insert_link_top) + map_new('n', '', insert_link_top) return true @@ -173,28 +193,6 @@ function M.insert_project_link() }) end -local function spliting(inputstr, sep) - if sep == nil then - sep = "%s" - end - local t = {} - for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do - table.insert(t, str) - end - return t -end - -local function pad2(n) - n = tonumber(n) - if n < 10 then - return "0" .. n - else - return tostring(n) - end -end - --- The heart of this project following --- Remember to go back with C-O function M.follow_link() local line = vim.api.nvim_get_current_line() local link = line:match("%[%[(.-)%]%]") @@ -209,9 +207,7 @@ function M.follow_link() return end - -- List of all kinds that are available - -- Here brainstore and projects are kind of the same but I keep them separated if kind == "brain" then vim.cmd("edit " .. brainstore_dir .. "/" .. target) elseif kind == "mail" then @@ -236,7 +232,7 @@ function M.follow_link() vim.cmd("/" .. "20" .. year .. "-" .. month .. "-" .. day) vim.cmd("normal! zz") else - print("Unknown link type: " .. kind .. ". Must be one of: " .. "mail, contact, project, brain, date.") + print("Unknown link type: " .. kind .. ".") end end diff --git a/lua/custom/todo/init.lua b/lua/custom/todo/init.lua index 984a1a5..5776f46 100644 --- a/lua/custom/todo/init.lua +++ b/lua/custom/todo/init.lua @@ -1,6 +1,3 @@ --- custom module for todo file editing support in neovim --- inspired by a older plugin that does basically the same - local M = {} local function is_todo_file() @@ -22,7 +19,6 @@ function M.remove_priority() vim.api.nvim_set_current_line(line) end - function M.mark_done() if not is_todo_file() then return end print("Marked todo as done! (just deleted)") @@ -103,22 +99,5 @@ function M.sort_by_project() grouped_sort(get_project_key) end -function M.setup() - local opts = { noremap = true, silent = true } - - for i = string.byte("a"), string.byte("z") do - local letter = string.char(i) - vim.keymap.set("n", "p" .. letter, function() M.set_priority(letter) end, opts) - end - - vim.keymap.set("n", "p", M.remove_priority, opts) - - vim.keymap.set("n", "sp", M.sort_by_priority, opts) - vim.keymap.set("n", "sc", M.sort_by_context, opts) - vim.keymap.set("n", "sr", M.sort_by_project, opts) - - -- New keymap for marking todo as done - vim.keymap.set("n", "td", M.mark_done, opts) -end return M diff --git a/lua/custom/typst.lua b/lua/custom/typst/init.lua similarity index 98% rename from lua/custom/typst.lua rename to lua/custom/typst/init.lua index 268edb9..efb411c 100644 --- a/lua/custom/typst.lua +++ b/lua/custom/typst/init.lua @@ -6,7 +6,7 @@ local watch_job_id = nil local watch_buf_id = nil local watch_tab_id = nil -function M.Watch_and_open() +function M.watch_and_open() -- Parse the current file and check for typst vim.notify("INIT", vim.log.levels.WARN) local input = vim.fn.expand("%:p") @@ -66,7 +66,7 @@ function M.Watch_and_open() vim.notify("Started Typst watch", vim.log.levels.INFO) vim.fn.system("killall .zathura-wrapped") - functions.Sleep(0.5) + functions.sleep(0.5) vim.fn.jobstart({ "zathura", output }, { on_exit = function() if watch_job_id then diff --git a/lua/custom/uni.lua b/lua/custom/uni/init.lua similarity index 88% rename from lua/custom/uni.lua rename to lua/custom/uni/init.lua index f65892e..a423385 100644 --- a/lua/custom/uni.lua +++ b/lua/custom/uni/init.lua @@ -1,9 +1,11 @@ +local M = {} + local fzf = require("fzf-lua") local fn = vim.fn -local current_season = "S3" +local conf = require("conf") -- Function to scan for .unicourse files and get their course directories -function get_course_directories() +function M.get_course_directories() local dirs = {} local function scan_dir(dir) for _, entry in ipairs(fn.glob(dir .. "/*", true, true)) do @@ -26,13 +28,13 @@ function get_course_directories() end end - scan_dir("~/projects/university/" .. current_season) + scan_dir("~/projects/university/" .. conf.season) return dirs end -- Function to show the fzf menu for selecting a course directory -function select_course_directory() - local courses = get_course_directories() +function M.select_course_directory() + local courses = M.get_course_directories() local course_names = {} for _, course in ipairs(courses) do @@ -45,7 +47,7 @@ function select_course_directory() ["default"] = function(selected) for _, course in ipairs(courses) do if selected[1] == (course.name .. " (" .. course.short .. ")") then - show_course_menu(course) + M.show_course_menu(course) break end end @@ -55,7 +57,7 @@ function select_course_directory() end -- Function to show the fzf menu for actions on a selected course folder -function show_course_menu(course) +function M.show_course_menu(course) local files = {} -- Collect all VL files in the Vorlesungen directory for _, file in ipairs(fn.glob(course.path .. "/VL/*", true, true)) do @@ -79,10 +81,10 @@ function show_course_menu(course) actions = { ["default"] = function(selected) if selected[1] == "Open the newest VL file" then - local newest_file = get_newest_vl_file(files) + local newest_file = M.get_newest_vl_file(files) vim.cmd("edit " .. newest_file) elseif selected[1] == "Create a new VL" then - create_new_vl(course) + M.create_new_vl(course) elseif selected[1] == "Open the course folder" then vim.cmd("edit " .. course.path) elseif selected[1] == "Open a specific file" then @@ -101,7 +103,7 @@ function show_course_menu(course) end -- Function to get the newest VL file based on modification time -function get_newest_vl_file(files) +function M.get_newest_vl_file(files) local newest_file = nil local newest_time = 0 for _, file in ipairs(files) do @@ -115,18 +117,20 @@ function get_newest_vl_file(files) end -- Function to create a new VL file based on the template and incrementing the number -function create_new_vl(course) +function M.create_new_vl(course) local vl_dir = course.path .. "/VL" - local success, _ = pcall(function() + pcall(function() vim.fn.mkdir(vl_dir) end) -- Hard coded this local template_path = vim.fn.expand("~/projects/university/data/template.typ") if fn.filereadable(template_path) == 1 then -- Find the latest VL number in the folder + --- @type number? local latest_num = 0 for _, file in ipairs(fn.glob(vl_dir .. "/*", true, true)) do if file:match(course.short .. "VL(%d+).typ$") then + --- @type number? local num = tonumber(file:match(course.short .. "VL(%d+).typ$")) if num > latest_num then latest_num = num @@ -147,3 +151,5 @@ function create_new_vl(course) print("Template file (template.typ) not found!") end end + +return M diff --git a/lua/plugins/custom.lua b/lua/plugins/custom.lua index ccacec0..d675e86 100644 --- a/lua/plugins/custom.lua +++ b/lua/plugins/custom.lua @@ -12,16 +12,53 @@ return { dir = get_custom_dir("todo"), name = "todo", dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" }, - config = function() - require("custom.todo").setup() - end, + keys = { + { "ta", function() require("custom.todo").mark_done() end, desc = "Watch Typst" }, + }, + }, { - dir = get_custom_dir(), + dir = get_custom_dir("typst"), name = "typst", dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" }, keys = { - { "tw", function() require("custom.typst").Watch_and_open() end, desc = "Watch Typst" }, + { "tw", function() require("custom.typst").watch_and_open() end, desc = "Watch Typst" }, }, }, + { + dir = get_custom_dir("journal"), + name = "journal", + config = function () + local journal = require("custom.journal") + vim.keymap.set("n", "joup", function() + journal.open_today() + end, { desc = "Open todays journal" }) + end + }, + { + dir = get_custom_dir("uni"), + name = "uni", + config = function () + local uni = require("custom.uni") + vim.keymap.set("n", "nv", function() + uni.select_course_directory() + end, { desc = "Open UniCourse menu" }) + end + + }, + { + dir = get_custom_dir("linker"), + name = "linker", + config = function() + local links = require("custom.linker") + + vim.keymap.set("n", "fl", links.follow_link, { desc = "Try to follow current link" }) + + vim.keymap.set("n", "lf", links.insert_brainstore_link, { desc = "Link Brainstore file" }) + vim.keymap.set("n", "lm", links.insert_mail_link, { desc = "Link Mail" }) + vim.keymap.set("n", "lp", links.insert_project_link, { desc = "Link Project" }) + vim.keymap.set("n", "lc", links.insert_contact_link, { desc = "Link Contact" }) + vim.keymap.set("n", "ld", links.insert_date_link, { desc = "Link Contact" }) + end + }, } diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 7ecc21e..c50f47b 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,28 +1,5 @@ --- Prefilled with lsp that have no dependencies -local servers = { "lua_ls", "rust_analyzer", "denols" } - -local function populate_servers() - if vim.fn.executable("go") == 1 then - table.insert(servers, "gopls") - else - vim.notify("[mason] Skipping gopls (go not found)", vim.log.levels.WARN) - end - - if vim.fn.executable("npm") == 1 then - table.insert(servers, "pyright") - table.insert(servers, "clangd") - table.insert(servers, "bashls") - else - vim.notify("[mason] Skipping install of some lsp (npm not found)", vim.log.levels.WARN) - end - - if vim.fn.executable("cargo") == 1 then - table.insert(servers, "nil_ls") - else - vim.notify("[mason] Skipping nil (cargo not found)", vim.log.levels.WARN) - end -end -populate_servers() +-- Prefilled with servers that have no dependencies +local servers = require("utils.functions").get_lsp_servers() return { { @@ -77,7 +54,7 @@ return { dependencies = { "williamboman/mason-lspconfig.nvim" }, - priority = -10; + priority = -10, config = function() require("mason").setup() @@ -185,7 +162,7 @@ return { -- Add text in diagnostics vim.diagnostic.config({ - virtual_text = true, + virtual_text = false, }) end, }, diff --git a/lua/plugins/luasnip.lua b/lua/plugins/luasnip.lua index 4e4e52b..d61c3f5 100644 --- a/lua/plugins/luasnip.lua +++ b/lua/plugins/luasnip.lua @@ -1,11 +1,18 @@ return { { "L3MON4D3/LuaSnip", + dependencies = { + "rafamadriz/friendly-snippets" + }, version = "v2.*", build = "make install_jsregexp", event = "InsertEnter", config = function() local ls = require("luasnip") + + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_lua").lazy_load({ paths = "~/.config/nvim/snippets" }) + ls.config.setup({ enable_autosnippets = true, store_selection_keys = '', diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 3120e4f..7392a0c 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -7,7 +7,9 @@ return { local configs = require("nvim-treesitter.configs") configs.setup({ sync_install = true, - ensure_installed = { "typst" }, + ensure_installed = { "typst", "go", "bash", "python", "nix" }, + highlight = { enable = true }, + indent = { enable = true }, }) end }, diff --git a/lua/utils/functions.lua b/lua/utils/functions.lua index ebaa554..b335d2e 100644 --- a/lua/utils/functions.lua +++ b/lua/utils/functions.lua @@ -1,8 +1,72 @@ -- General helper functions local M = {} -function M.Sleep(n) +function M.sleep(n) os.execute("sleep " .. tonumber(n)) end +--- @return {} +function M.get_lsp_servers() + local servers = { "lua_ls" } + + -- persistent state file + local state_file = vim.fn.stdpath("state") .. "/mason_skipped_jonas.json" + + -- load previous warnings + local warned = {} + local ok, data = pcall(vim.fn.readfile, state_file) + if ok and #data > 0 then + local decoded = vim.fn.json_decode(data) + if decoded then warned = decoded end + end + + local function save_state() + vim.fn.writefile({ vim.fn.json_encode(warned) }, state_file) + end + + local function warn_once(key, msg) + if not warned[key] then + vim.notify(msg, vim.log.levels.WARN) + warned[key] = true + save_state() + end + end + + local function populate_servers() + if vim.fn.executable("go") == 1 then + table.insert(servers, "gopls") + else + warn_once("gopls", "[mason] Skipping gopls (go not found)") + end + + if vim.fn.executable("npm") == 1 then + table.insert(servers, "pyright") + table.insert(servers, "clangd") + table.insert(servers, "bashls") + else + warn_once("npm", "[mason] Skipping pyright/clangd/bashls (npm not found)") + end + + if vim.fn.executable("cargo") == 1 then + if vim.fn.executable("nix") == 1 then + table.insert(servers, "nil_ls") + else + warn_once("nix", "[mason] Skipping nil_ls (nix not found)") + end + table.insert(servers, "rust_analyzer") + else + warn_once("cargo", "[mason] Skipping nil_ls/rust_analyzer (cargo not found)") + end + + if vim.fn.executable("deno") == 1 then + table.insert(servers, "denols") + else + warn_once("deno", "[mason] Skipping denols (deno not found)") + end + end + + populate_servers() + return servers +end + return M diff --git a/snippets/all.lua b/snippets/all.lua new file mode 100644 index 0000000..40923f1 --- /dev/null +++ b/snippets/all.lua @@ -0,0 +1,9 @@ +local ls = require("luasnip") +local s = ls.snippet +local t = ls.text_node + +return { + s("sig", { + t("Best regards,"), t({ "", "Jonas Hahn" }), + }), +} diff --git a/snippets/go.lua b/snippets/go.lua new file mode 100644 index 0000000..30b0345 --- /dev/null +++ b/snippets/go.lua @@ -0,0 +1,17 @@ +local ls = require("luasnip") +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node + +return { + s("cfo", { -- check for error + t("if err != nil {"), t({ "", "\t" }), + i(1, "return err"), + t({ "", "}" }) + }), + s("struct", { + t("type "), i(1, "MyStruct"), t(" struct {"), + t({ "", "\t" }), i(2, "Field type"), + t({ "", "}" }) + }), +}