From e02706280ffff633823e150f17aebdba6c00cac1 Mon Sep 17 00:00:00 2001 From: Chris Pecunies Date: Sun, 15 Dec 2024 08:41:31 -0800 Subject: [PATCH] fixing cmd, scaffolds --- lua/down/mod.lua | 4 +- lua/down/mod/cmd/init.lua | 4 +- lua/down/mod/data/log/init.lua | 158 +++++++------- lua/down/mod/data/template/init.lua | 156 +++++++------- lua/down/mod/edit/conceal/init.lua | 7 +- lua/down/mod/edit/cursor/init.lua | 4 +- lua/down/mod/edit/find/init.lua | 40 ++-- lua/down/mod/edit/hl/init.lua | 31 --- lua/down/mod/edit/parse/datetime/init.lua | 4 +- lua/down/mod/edit/parse/heading/init.lua | 7 +- lua/down/mod/edit/parse/link/init.lua | 11 + lua/down/mod/edit/parse/scan/init.lua | 2 + lua/down/mod/edit/parse/tag/init.lua | 12 ++ lua/down/mod/edit/syntax/init.lua | 139 +++++------- lua/down/mod/edit/toc/init.lua | 75 +++---- lua/down/mod/edit/toc/util.lua | 3 + lua/down/mod/edit/todo/init.lua | 39 ++-- lua/down/mod/lsp/init.lua | 249 +++++++++++----------- lua/down/mod/note/init.lua | 87 +++----- lua/down/mod/note/util.lua | 57 +++++ 20 files changed, 553 insertions(+), 536 deletions(-) create mode 100644 lua/down/mod/edit/toc/util.lua create mode 100644 lua/down/mod/note/util.lua diff --git a/lua/down/mod.lua b/lua/down/mod.lua index 2bd1639..1346c1a 100644 --- a/lua/down/mod.lua +++ b/lua/down/mod.lua @@ -439,7 +439,7 @@ end --- @param cfg? table A config that reflects the structure of down.config.user.setup["init.name"].config function Mod.load_mod_as_dependency(modn, parent_mod, cfg) if Mod.load_mod(modn, cfg) and Mod.is_mod_loaded(parent_mod) then - Mod.loaded_mod[parent_mod].required[modn] = Mod.get_mod_config(modn) + Mod.loaded_mod[parent_mod].required[modn] = Mod.mod_config(modn) end end @@ -461,7 +461,7 @@ end --- Returns the init.config table if the init is loaded --- @param modn string The name of the init to retrieve (init must be loaded) --- @return table? -function Mod.get_mod_config(modn) +function Mod.mod_config(modn) if not Mod.is_mod_loaded(modn) then log.trace( "Attempt to get init config with name" diff --git a/lua/down/mod/cmd/init.lua b/lua/down/mod/cmd/init.lua index 0a49488..d32588b 100644 --- a/lua/down/mod/cmd/init.lua +++ b/lua/down/mod/cmd/init.lua @@ -83,7 +83,7 @@ M.data = { if #args == 0 or argument_count < ref.min_args then local completions = M.data.data.generate_completions( _, - table.concat({ "down ", data.args, " " }) + table.concat({ "Down ", data.args, " " }) ) M.data.data.select_next_cmd_arg(data.args, completions) return @@ -230,7 +230,7 @@ M.data = { ---@param qargs table #A string of arguments previously supplied to the down command ---@param choices table #all possible choices for the next argument select_next_cmd_arg = function(qargs, choices) - local current = table.concat({ "down ", qargs }) + local current = table.concat({ "Down ", qargs }) local query diff --git a/lua/down/mod/data/log/init.lua b/lua/down/mod/data/log/init.lua index df22df5..1988df9 100644 --- a/lua/down/mod/data/log/init.lua +++ b/lua/down/mod/data/log/init.lua @@ -6,7 +6,7 @@ local M = mod.create("data.log") M.setup = function() if M.config.strategies[M.config.strategy] then M.config.strategy = - M.config.strategies[M.config.strategy] + M.config.strategies[M.config.strategy] end -- mod.await("cmd", function(cmd) @@ -102,7 +102,7 @@ M.data = { open_log = function(time, custom_date) -- TODO(vhyrro): Change this to use down dates! local workspace = M.config.workspace - or M.required["workspace"].get_current_workspace()[1] + or M.required["workspace"].get_current_workspace()[1] local workspace_path = M.required["workspace"].get_workspace(workspace) local folder_name = M.config.log_folder local template_name = M.config.template_name @@ -124,8 +124,8 @@ M.data = { local path = os.date( type(M.config.strategy) == "function" - and M.config.strategy(os.date("*t", time)) - or M.config.strategy, + and M.config.strategy(os.date("*t", time)) + or M.config.strategy, time ) @@ -144,20 +144,20 @@ M.data = { ) if - not log_file_exists - and M.config.use_template - and M.required["workspace"].file_exists( - workspace_path .. "/" .. folder_name .. "/" .. template_name - ) + not log_file_exists + and M.config.use_template + and M.required["workspace"].file_exists( + workspace_path .. "/" .. folder_name .. "/" .. template_name + ) then vim.cmd( "$read " - .. workspace_path - .. "/" - .. folder_name - .. "/" - .. template_name - .. "| silent! w" + .. workspace_path + .. "/" + .. folder_name + .. "/" + .. template_name + .. "| silent! w" ) end end, @@ -201,15 +201,15 @@ M.data = { --- Opens the toc file open_toc = function() local workspace = M.config.workspace - or M.required["workspace"].get_current_workspace()[1] - local index = mod.get_mod_config("workspace").index + or M.required["workspace"].get_current_workspace()[1] + local index = mod.mod_config("workspace").index local folder_name = M.config.log_folder -- If the toc exists, open it, if not, create it if - M.required["workspace"].file_exists( - folder_name .. config.pathsep .. index - ) + M.required["workspace"].file_exists( + folder_name .. config.pathsep .. index + ) then M.required["workspace"].open_file( workspace, @@ -223,8 +223,8 @@ M.data = { --- Creates or updates the toc file create_toc = function() local workspace = M.config.workspace - or M.required["workspace"].get_current_workspace()[1] - local index = mod.get_mod_config("workspace").index + or M.required["workspace"].get_current_workspace()[1] + local index = mod.mod_config("workspace").index local workspace_path = M.required["workspace"].get_workspace(workspace) local workspace_name_for_link = M.config.workspace or "" local folder_name = M.config.log_folder @@ -238,10 +238,10 @@ M.data = { path = path or "" local handle = vim.loop.fs_scandir( workspace_path - .. config.pathsep - .. folder_name - .. config.pathsep - .. path + .. config.pathsep + .. folder_name + .. config.pathsep + .. path ) if type(handle) ~= "userdata" then @@ -263,10 +263,10 @@ M.data = { local get_title = function(file) local buffer = vim.fn.bufadd( workspace_path - .. config.pathsep - .. folder_name - .. config.pathsep - .. file + .. config.pathsep + .. folder_name + .. config.pathsep + .. file ) local meta = M.required["workspace"].get_document_metadata(buffer) return meta.title @@ -306,7 +306,7 @@ M.data = { if mtype == "directory" then local months_handle = - get_fs_handle(name .. config.pathsep .. mname) + get_fs_handle(name .. config.pathsep .. mname) while true do -- dname is the day local dname, dtype = vim.loop.fs_scandir_next(months_handle) @@ -324,10 +324,10 @@ M.data = { -- Get the title from the metadata, else, it just base to the name of the file local title = get_title( name - .. config.pathsep - .. mname - .. config.pathsep - .. dname + .. config.pathsep + .. mname + .. config.pathsep + .. dname ) or file[1] -- Insert a new entry @@ -336,16 +336,16 @@ M.data = { tonumber(mname), tonumber(file[1]), "{:$" - .. workspace_name_for_link - .. config.pathsep - .. M.config.log_folder - .. config.pathsep - .. name - .. config.pathsep - .. mname - .. config.pathsep - .. file[1] - .. ":}", + .. workspace_name_for_link + .. config.pathsep + .. M.config.log_folder + .. config.pathsep + .. name + .. config.pathsep + .. mname + .. config.pathsep + .. file[1] + .. ":}", title, }) end) @@ -379,12 +379,12 @@ M.data = { parts[2], parts[3], "{:$" - .. workspace_name_for_link - .. config.pathsep - .. M.config.log_folder - .. config.pathsep - .. file[1] - .. ":}", + .. workspace_name_for_link + .. config.pathsep + .. M.config.log_folder + .. config.pathsep + .. file[1] + .. ":}", title, }) end) @@ -394,34 +394,34 @@ M.data = { vim.schedule(function() -- Gets a base format for the entries local format = M.config.toc_format - or function(entries) - local months_text = M.data.months - -- Convert the entries into a certain format to be written - local output = {} - local current_year - local current_month - for _, entry in ipairs(entries) do - -- Don't print the year and month if they haven't changed - if not current_year or current_year < entry[1] then - current_year = entry[1] - current_month = nil - table.insert(output, "* " .. current_year) - end - if not current_month or current_month < entry[2] then - current_month = entry[2] - table.insert(output, "** " .. months_text[current_month]) + or function(entries) + local months_text = M.data.months + -- Convert the entries into a certain format to be written + local output = {} + local current_year + local current_month + for _, entry in ipairs(entries) do + -- Don't print the year and month if they haven't changed + if not current_year or current_year < entry[1] then + current_year = entry[1] + current_month = nil + table.insert(output, "* " .. current_year) + end + if not current_month or current_month < entry[2] then + current_month = entry[2] + table.insert(output, "** " .. months_text[current_month]) + end + + -- Prints the file link + table.insert( + output, + " " .. entry[4] .. string.format("[%s]", entry[5]) + ) end - -- Prints the file link - table.insert( - output, - " " .. entry[4] .. string.format("[%s]", entry[5]) - ) + return output end - return output - end - M.required["workspace"].create_file( folder_name .. config.pathsep .. index, workspace or M.required["workspace"].get_current_workspace()[1] @@ -463,10 +463,10 @@ M.on = function(event) M.data.open_log( nil, string.format("%04d", osdate.year) - .. "-" - .. string.format("%02d", osdate.month) - .. "-" - .. string.format("%02d", osdate.day) + .. "-" + .. string.format("%02d", osdate.month) + .. "-" + .. string.format("%02d", osdate.day) ) end), }) diff --git a/lua/down/mod/data/template/init.lua b/lua/down/mod/data/template/init.lua index a18993e..4e2098f 100644 --- a/lua/down/mod/data/template/init.lua +++ b/lua/down/mod/data/template/init.lua @@ -6,7 +6,7 @@ local M = mod.create("data.template") M.setup = function() if M.config.strategies[M.config.strategy] then M.config.strategy = - M.config.strategies[M.config.strategy] + M.config.strategies[M.config.strategy] end -- mod.await("cmd", function(cmd) @@ -90,7 +90,7 @@ M.data = { open_template = function(time, custom_date) -- TODO(vhyrro): Change this to use down dates! local workspace = M.config.workspace - or M.required["workspace"].get_current_workspace()[1] + or M.required["workspace"].get_current_workspace()[1] local workspace_path = M.required["workspace"].get_workspace(workspace) local folder_name = M.config.template_folder local template_name = M.config.template_name @@ -112,8 +112,8 @@ M.data = { local path = os.date( type(M.config.strategy) == "function" - and M.config.strategy(os.date("*t", time)) - or M.config.strategy, + and M.config.strategy(os.date("*t", time)) + or M.config.strategy, time ) @@ -132,20 +132,20 @@ M.data = { ) if - not template_file_exists - and M.config.use_template - and M.required["workspace"].file_exists( - workspace_path .. "/" .. folder_name .. "/" .. template_name - ) + not template_file_exists + and M.config.use_template + and M.required["workspace"].file_exists( + workspace_path .. "/" .. folder_name .. "/" .. template_name + ) then vim.cmd( "$read " - .. workspace_path - .. "/" - .. folder_name - .. "/" - .. template_name - .. "| silent! w" + .. workspace_path + .. "/" + .. folder_name + .. "/" + .. template_name + .. "| silent! w" ) end end, @@ -180,13 +180,13 @@ M.data = { --- Opens the toc file open_toc = function() local workspace = M.config.workspace - or M.required["workspace"].get_current_workspace()[1] - local index = mod.get_mod_config("workspace").index + or M.required["workspace"].get_current_workspace()[1] + local index = mod.mod_config("workspace").index local folder_name = M.config.template_folder -- If the toc exists, open it, if not, create it if - M.required.workspace.file_exists(folder_name .. config.pathsep .. index) + M.required.workspace.file_exists(folder_name .. config.pathsep .. index) then M.required.workspace.open_file( workspace, @@ -200,8 +200,8 @@ M.data = { --- Creates or updates the toc file create_toc = function() local workspace = M.config.workspace - or M.required["workspace"].get_current_workspace()[1] - local index = mod.get_mod_config("workspace").index + or M.required["workspace"].get_current_workspace()[1] + local index = mod.mod_config("workspace").index local workspace_path = M.required["workspace"].get_workspace(workspace) local workspace_name_for_link = M.config.workspace or "" local folder_name = M.config.template_folder @@ -215,10 +215,10 @@ M.data = { path = path or "" local handle = vim.loop.fs_scandir( workspace_path - .. config.pathsep - .. folder_name - .. config.pathsep - .. path + .. config.pathsep + .. folder_name + .. config.pathsep + .. path ) if type(handle) ~= "userdata" then @@ -240,10 +240,10 @@ M.data = { local get_title = function(file) local buffer = vim.fn.bufadd( workspace_path - .. config.pathsep - .. folder_name - .. config.pathsep - .. file + .. config.pathsep + .. folder_name + .. config.pathsep + .. file ) local meta = M.required["workspace"].get_document_metadata(buffer) return meta.title @@ -283,7 +283,7 @@ M.data = { if mtype == "directory" then local months_handle = - get_fs_handle(name .. config.pathsep .. mname) + get_fs_handle(name .. config.pathsep .. mname) while true do -- dname is the day local dname, dtype = vim.loop.fs_scandir_next(months_handle) @@ -301,10 +301,10 @@ M.data = { -- Get the title from the metadata, else, it just base to the name of the file local title = get_title( name - .. config.pathsep - .. mname - .. config.pathsep - .. dname + .. config.pathsep + .. mname + .. config.pathsep + .. dname ) or file[1] -- Insert a new entry @@ -313,16 +313,16 @@ M.data = { tonumber(mname), tonumber(file[1]), "{:$" - .. workspace_name_for_link - .. config.pathsep - .. M.config.template_folder - .. config.pathsep - .. name - .. config.pathsep - .. mname - .. config.pathsep - .. file[1] - .. ":}", + .. workspace_name_for_link + .. config.pathsep + .. M.config.template_folder + .. config.pathsep + .. name + .. config.pathsep + .. mname + .. config.pathsep + .. file[1] + .. ":}", title, }) end) @@ -356,12 +356,12 @@ M.data = { parts[2], parts[3], "{:$" - .. workspace_name_for_link - .. config.pathsep - .. M.config.template_folder - .. config.pathsep - .. file[1] - .. ":}", + .. workspace_name_for_link + .. config.pathsep + .. M.config.template_folder + .. config.pathsep + .. file[1] + .. ":}", title, }) end) @@ -371,35 +371,35 @@ M.data = { vim.schedule(function() -- Gets a base format for the entries local format = M.config.toc_format - or function(entries) - local months_text = - require("down.mod.data.template.util").months - -- Convert the entries into a certain format to be written - local output = {} - local current_year - local current_month - for _, entry in ipairs(entries) do - -- Don't print the year and month if they haven't changed - if not current_year or current_year < entry[1] then - current_year = entry[1] - current_month = nil - table.insert(output, "* " .. current_year) - end - if not current_month or current_month < entry[2] then - current_month = entry[2] - table.insert(output, "** " .. months_text[current_month]) + or function(entries) + local months_text = + require("down.mod.data.template.util").months + -- Convert the entries into a certain format to be written + local output = {} + local current_year + local current_month + for _, entry in ipairs(entries) do + -- Don't print the year and month if they haven't changed + if not current_year or current_year < entry[1] then + current_year = entry[1] + current_month = nil + table.insert(output, "* " .. current_year) + end + if not current_month or current_month < entry[2] then + current_month = entry[2] + table.insert(output, "** " .. months_text[current_month]) + end + + -- Prints the file link + table.insert( + output, + " " .. entry[4] .. string.format("[%s]", entry[5]) + ) end - -- Prints the file link - table.insert( - output, - " " .. entry[4] .. string.format("[%s]", entry[5]) - ) + return output end - return output - end - M.required["workspace"].create_file( folder_name .. config.pathsep .. index, workspace or M.required["workspace"].get_current_workspace()[1] @@ -441,10 +441,10 @@ M.on = function(event) M.data.data.open_template( nil, string.format("%04d", osdate.year) - .. "-" - .. string.format("%02d", osdate.month) - .. "-" - .. string.format("%02d", osdate.day) + .. "-" + .. string.format("%02d", osdate.month) + .. "-" + .. string.format("%02d", osdate.day) ) end), }) diff --git a/lua/down/mod/edit/conceal/init.lua b/lua/down/mod/edit/conceal/init.lua index d543626..4ecf423 100644 --- a/lua/down/mod/edit/conceal/init.lua +++ b/lua/down/mod/edit/conceal/init.lua @@ -13,14 +13,17 @@ M.setup = function() } end +---@class down.edit.conceal.Data +M.data = {} M.data.math = M.math.data M.data.border = M.border.data M.data.chars = M.chars.data +---@class down.edit.conceal.Config M.config = { link_style = "markdown", } -M.data.data.start_link_concealing = function() - if M.config == "markdown" then +M.data.start_link_concealing = function() + if M.config.link_style == "markdown" then madd( "Conceal", "\\[[^[]\\{-}\\]\\zs([^(]\\{-})\\ze", diff --git a/lua/down/mod/edit/cursor/init.lua b/lua/down/mod/edit/cursor/init.lua index e085788..c1ee5eb 100644 --- a/lua/down/mod/edit/cursor/init.lua +++ b/lua/down/mod/edit/cursor/init.lua @@ -11,10 +11,10 @@ function L.setup() } end ----@class edit.cursor.Config +---@class down.edit.cursor.Config L.config = {} ----@class edit.cursor.Data +---@class down.edit.cursor.Data ---@field public node TSNode|nil ---@field public text string[] ---@field public prev TSNode|nil diff --git a/lua/down/mod/edit/find/init.lua b/lua/down/mod/edit/find/init.lua index 83bfb69..1e4c12b 100644 --- a/lua/down/mod/edit/find/init.lua +++ b/lua/down/mod/edit/find/init.lua @@ -6,27 +6,24 @@ local lib, mod = d.lib, d.mod local M = mod.create("edit.find") -M.load = function() - mod.await("cmd", function(cmd) - cmd.add_commands_from_table({ - find = { - subcommands = { - update = { - args = 0, - name = "edit.find.update", - }, - insert = { - name = "edit.find.insert", - args = 0, - }, - }, - name = "edit.find", - }, - }) - end) -end - M.setup = function() + -- mod.await("cmd", function(cmd) + -- cmd.add_commands_from_table({ + -- find = { + -- subcommands = { + -- update = { + -- args = 0, + -- name = "edit.find.update", + -- }, + -- insert = { + -- name = "edit.find.insert", + -- args = 0, + -- }, + -- }, + -- name = "edit.find", + -- }, + -- }) + -- end) return { loaded = true, requires = { @@ -35,10 +32,11 @@ M.setup = function() } end +---@class down.edit.find.Data M.data = {} +---@class down.edit.find.Config M.config = {} -M.data.data = {} M.events = {} M.events.subscribed = { diff --git a/lua/down/mod/edit/hl/init.lua b/lua/down/mod/edit/hl/init.lua index 8c172b8..af087ee 100644 --- a/lua/down/mod/edit/hl/init.lua +++ b/lua/down/mod/edit/hl/init.lua @@ -3,35 +3,8 @@ local lib, log, mod = down.lib, down.log, down.mod local M = mod.create("edit.hl") ---[[ ---]] M.config = { - -- The TS highlight for each down type. - -- - -- The `highlight` table is a large collection of nested trees. At the leaves of each of these - -- trees is the final highighlightight to apply to that tree. For example: `"+@comment"` tells down to - -- link to an existing highighlightight group `@comment` (denoted by the `+` prefix). When no prefix is - -- found, the string is treated as arguments passed to `:highighlightight`, for example: `gui=bold - -- fg=#000000`. - -- - -- Nested trees concatenate, thus: - -- ```lua - -- tags = { - -- ranged_verbatim = { - -- begin = "+@comment", - -- }, - -- } - -- ``` - -- matches the highighlightight group: - -- ```lua - -- @down.tags.ranged_verbatim.begin - -- ``` - -- and converts into the following command: - -- ```vim - -- highighlightight! link @down.tags.ranged_verbatim.begin @comment - -- ``` highlight = { - -- highlight displayed in down selection window popups. selection_window = { heading = "+@annotation", arrow = "+@none", @@ -40,11 +13,7 @@ M.config = { nestedkeyname = "+@string", }, - -- highlight displayed in all sorts of tag types. - -- - -- These include: `@`, `.`, `|`, `#`, `+` and `=`. tags = { - -- highlight for the `@` verbatim tags. ranged_verbatim = { begin = "+@keydown", diff --git a/lua/down/mod/edit/parse/datetime/init.lua b/lua/down/mod/edit/parse/datetime/init.lua index b9fd621..1323f3e 100644 --- a/lua/down/mod/edit/parse/datetime/init.lua +++ b/lua/down/mod/edit/parse/datetime/init.lua @@ -8,9 +8,9 @@ M.setup = function() } end ----@class parse.datetime.Config +---@class down.edit.parse.datetime.Config M.config = {} ----@class parse.datetime.Data +---@class down.edit.parse.datetime.Data ---@field date parse.datetime.Date ---@field grammar parse.datetime.Grammar ---@field time parse.datetime.Time diff --git a/lua/down/mod/edit/parse/heading/init.lua b/lua/down/mod/edit/parse/heading/init.lua index a491287..2f732ee 100644 --- a/lua/down/mod/edit/parse/heading/init.lua +++ b/lua/down/mod/edit/parse/heading/init.lua @@ -2,10 +2,13 @@ local M = Mod.create("edit.parse.heading") local l = vim.lpeg ----@class parse.heading.Data +---@class down.edit.parse.heading.Config +M.config = {} + +---@class down.edit.parse.heading.Data ---@field heading parse.heading.Heading M.data = {} ----@class (exact) parse.heading.Heading +---@class (exact) down.edit.parse.heading.Heading ---@field level integer: Level of heading ---@field isTitle boolean: Is title of document ---@field content string: Content of heading diff --git a/lua/down/mod/edit/parse/link/init.lua b/lua/down/mod/edit/parse/link/init.lua index c5bd47b..0ca9242 100644 --- a/lua/down/mod/edit/parse/link/init.lua +++ b/lua/down/mod/edit/parse/link/init.lua @@ -1,3 +1,14 @@ local P = Mod.create("edit.parse.link") +P.setup = function() + return { + loaded = true + } +end + +---@class down.edit.parse.link.Config +P.config = {} +---@class down.edit.parse.link.Data +P.data = {} + return P diff --git a/lua/down/mod/edit/parse/scan/init.lua b/lua/down/mod/edit/parse/scan/init.lua index 528b370..77aea72 100644 --- a/lua/down/mod/edit/parse/scan/init.lua +++ b/lua/down/mod/edit/parse/scan/init.lua @@ -6,8 +6,10 @@ M.setup = function() } end +---@class down.edit.parse.scan.Config M.config = {} +---@class down.edit.parse.scan.Data M.data = {} return M diff --git a/lua/down/mod/edit/parse/tag/init.lua b/lua/down/mod/edit/parse/tag/init.lua index 5e39bf3..2c18c92 100644 --- a/lua/down/mod/edit/parse/tag/init.lua +++ b/lua/down/mod/edit/parse/tag/init.lua @@ -1,3 +1,15 @@ local P = Mod.create("edit.parse.tag") +P.setup = function() + return { + loaded = true + } +end + +---@class down.edit.parse.tag.Config +P.config = {} + +---@class down.edit.parse.tag.Data +P.data = {} + return P diff --git a/lua/down/mod/edit/syntax/init.lua b/lua/down/mod/edit/syntax/init.lua index 63f54b0..5dd9c93 100644 --- a/lua/down/mod/edit/syntax/init.lua +++ b/lua/down/mod/edit/syntax/init.lua @@ -1,15 +1,15 @@ local down = require("down") local mod, utils = down.mod, down.utils -local M = Mod.create("edit.syntax") +local M = mod.create("edit.syntax") local function schedule(func) vim.schedule(function() if - M.data.data.disable_deferred_updates + M.data.disable_deferred_updates or ( ( - M.data.data.debounce_counters[vim.api.nvim_win_get_cursor(0)[1] + 1] + M.data.debounce_counters[vim.api.nvim_win_get_cursor(0)[1] + 1] or 0 ) >= M.config.performance.max_debounce ) @@ -30,8 +30,8 @@ M.setup = function() } end -M.data.data = { - +---@class down.edit.syntax.Data +M.data = { largest_change_start = -1, largest_change_end = -1, @@ -57,20 +57,16 @@ M.data.data = { }, available_languages = {}, -} ----@class syntax -M.data = { - - -- fills M.data.data.ooaded_code_blocks with the list of active code blocks in the buffer + -- fills M.data.ooaded_code_blocks with the list of active code blocks in the buffer -- stores globally apparently check_code_block_type = function(buf, reload, from, to) -- parse the current buffer, and clear out the buffer's loaded code blocks if needed local current_buf = vim.api.nvim_buf_get_name(buf) -- load nil table with empty values - if M.data.data.code_block_table[current_buf] == nil then - M.data.data.code_block_table[current_buf] = { loaded_regex = {} } + if M.data.code_block_table[current_buf] == nil then + M.data.code_block_table[current_buf] = { loaded_regex = {} } end -- recreate table for buffer on buffer change @@ -81,16 +77,16 @@ M.data = { like reentering the buffer, this will get cleared to recreate what languages are loaded. then another function will handle unloading syntax files on next load --]] - for key in pairs(M.data.data.code_block_table) do + for key in pairs(M.data.code_block_table) do if current_buf == key and reload == true then for k, _ in - pairs(M.data.data.code_block_table[current_buf].loaded_regex) + pairs(M.data.code_block_table[current_buf].loaded_regex) do M.data.remove_syntax( string.format("textGroup%s", string.upper(k)), string.format("textSnip%s", string.upper(k)) ) - M.data.data.code_block_table[current_buf].loaded_regex[k] = nil + M.data.code_block_table[current_buf].loaded_regex[k] = nil end end end @@ -132,7 +128,7 @@ M.data = { -- make sure that the language is actually valid local type_func = function() - return M.data.data.available_languages[regex_lang].type + return M.data.available_languages[regex_lang].type end local ok, type = pcall(type_func) @@ -143,10 +139,10 @@ M.data = { -- add language to table -- if type is empty it means this language has never been found if - M.data.data.code_block_table[current_buf].loaded_regex[regex_lang] + M.data.code_block_table[current_buf].loaded_regex[regex_lang] == nil then - M.data.data.code_block_table[current_buf].loaded_regex[regex_lang] = + M.data.code_block_table[current_buf].loaded_regex[regex_lang] = { type = type, range = {}, @@ -154,7 +150,7 @@ M.data = { } end -- else just do what we need to do - M.data.data.code_block_table[current_buf].loaded_regex[regex_lang].range[start_row] = + M.data.code_block_table[current_buf].loaded_regex[regex_lang].range[start_row] = end_row table.insert(compare_table, regex_lang) end @@ -163,7 +159,7 @@ M.data = { -- compare loaded languages to see if the file actually has the code blocks if from == nil then for lang in - pairs(M.data.data.code_block_table[current_buf].loaded_regex) + pairs(M.data.code_block_table[current_buf].loaded_regex) do local found_lang = false for _, matched in pairs(compare_table) do @@ -176,7 +172,7 @@ M.data = { -- remove the syntax include and region if found_lang == false then -- delete loaded lang from the table - M.data.data.code_block_table[current_buf].loaded_regex[lang] = nil + M.data.code_block_table[current_buf].loaded_regex[lang] = nil M.data.remove_syntax( string.format("textGroup%s", string.upper(lang)), string.format("textSnip%s", string.upper(lang)) @@ -199,10 +195,10 @@ M.data = { -- schedule(function() local current_buf = vim.api.nvim_buf_get_name(buf) -- only parse from the loaded_code_blocks M, not from the file directly - if M.data.data.code_block_table[current_buf] == nil then + if M.data.code_block_table[current_buf] == nil then return end - local lang_table = M.data.data.code_block_table[current_buf].loaded_regex + local lang_table = M.data.code_block_table[current_buf].loaded_regex for lang_name, curr_table in pairs(lang_table) do if curr_table.type == "syntax" then -- NOTE: the regex fallback code was originally mostly adapted from Vimwiki @@ -216,7 +212,7 @@ M.data = { -- sync groups when needed if ignore_buf == false - and vim.api.nvim_buf_get_name(buf) == M.data.data.last_buffer + and vim.api.nvim_buf_get_name(buf) == M.data.last_buffer then M.data.sync_regex_code_blocks(buf, lang_name, from, to) end @@ -277,7 +273,7 @@ M.data = { -- include the cluster that will put inside the region -- source using the available languages - for syntax, table in pairs(M.data.data.available_languages) do + for syntax, table in pairs(M.data.available_languages) do if table.type == "syntax" then if lang_name == syntax then if empty_result == 0 then @@ -316,17 +312,17 @@ M.data = { actual_cluster = match end if actual_cluster ~= nil then - M.data.data.code_block_table[current_buf].loaded_regex[lang_name].cluster = + M.data.code_block_table[current_buf].loaded_regex[lang_name].cluster = actual_cluster end elseif - M.data.data.code_block_table[current_buf].loaded_regex[lang_name].cluster + M.data.code_block_table[current_buf].loaded_regex[lang_name].cluster ~= nil then local command = string.format( "silent! syntax cluster %s add=%s", group, - M.data.data.code_block_table[current_buf].loaded_regex[lang_name].cluster + M.data.code_block_table[current_buf].loaded_regex[lang_name].cluster ) vim.cmd(command) end @@ -379,7 +375,7 @@ M.data = { end vim.b.current_syntax = "" ---@diagnostic disable-line - M.data.data.last_buffer = vim.api.nvim_buf_get_name(buf) + M.data.last_buffer = vim.api.nvim_buf_get_name(buf) end end -- end) @@ -400,10 +396,10 @@ M.data = { sync_regex_code_blocks = function(buf, regex, from, to) local current_buf = vim.api.nvim_buf_get_name(buf) -- only parse from the loaded_code_blocks M, not from the file directly - if M.data.data.code_block_table[current_buf] == nil then + if M.data.code_block_table[current_buf] == nil then return end - local lang_table = M.data.data.code_block_table[current_buf].loaded_regex + local lang_table = M.data.code_block_table[current_buf].loaded_regex for lang_name, curr_table in pairs(lang_table) do -- if we got passed a regex, then we need to only parse the right one if regex ~= nil then @@ -466,6 +462,7 @@ M.data = { end, } +---@class down.edit.syntax.Config M.config = { -- Performance options for highlighting. -- @@ -496,26 +493,16 @@ M.config = { } M.load = function() - -- Enabled the required autocommands - -- This is generally any potential redraw event - -- M.required["autocommands"].enable_autocommand("BufEnter") - -- M.required["autocommands"].enable_autocommand("ColorScheme") - -- M.required["autocommands"].enable_autocommand("TextChanged") - -- M.required["autocommands"].enable_autocommand("InsertLeave") - -- M.required["autocommands"].enable_autocommand("VimLeavePre") - - -- Load available regex languages - -- get the available regex files for the current session - M.data.data.available_languages = utils.get_language_list(false) + M.data.available_languages = utils.get_language_list(false) end M.on = function(event) - M.data.data.debounce_counters[event.cursor_position[1] + 1] = M.data.data.debounce_counters + M.data.debounce_counters[event.cursor_position[1] + 1] = M.data.debounce_counters [event.cursor_position[1] + 1] or 0 local function should_debounce() - return M.data.data.debounce_counters[event.cursor_position[1] + 1] + return M.data.debounce_counters[event.cursor_position[1] + 1] >= M.config.performance.max_debounce end @@ -530,12 +517,6 @@ M.on = function(event) M.data.check_code_block_type(buf, false) M.data.trigger_highlight_regex_code_block(buf, false, false) else - -- This bit of code gets triggered if the line count of the file is bigger than one increment level - -- provided by the user. - -- In this case, the syntax trigger enters a block mode and splits up the file into chunks. It then goes through each - -- chunk at a set interval and applies the syntax that way to reduce load and improve performance. - - -- This points to the current block the user's cursor is in local block_current = math.floor(event.cursor_position[1] / M.config.performance.increment) @@ -605,12 +586,12 @@ M.on = function(event) return end - M.data.data.last_change.active = true + M.data.last_change.active = true local mode = vim.api.nvim_get_mode().mode if mode ~= "i" then - M.data.data.debounce_counters[event.cursor_position[1] + 1] = M.data.data.debounce_counters + M.data.debounce_counters[event.cursor_position[1] + 1] = M.data.debounce_counters [event.cursor_position[1] + 1] + 1 @@ -629,28 +610,28 @@ M.on = function(event) line_count = new_line_count vim.schedule(function() - M.data.data.debounce_counters[event.cursor_position[1] + 1] = M.data.data.debounce_counters + M.data.debounce_counters[event.cursor_position[1] + 1] = M.data.debounce_counters [event.cursor_position[1] + 1] - 1 end) end) else - if M.data.data.largest_change_start == -1 then - M.data.data.largest_change_start = start + if M.data.largest_change_start == -1 then + M.data.largest_change_start = start end - if M.data.data.largest_change_end == -1 then - M.data.data.largest_change_end = _end + if M.data.largest_change_end == -1 then + M.data.largest_change_end = _end end - M.data.data.largest_change_start = start - < M.data.data.largest_change_start + M.data.largest_change_start = start + < M.data.largest_change_start and start - or M.data.data.largest_change_start - M.data.data.largest_change_end = _end - > M.data.data.largest_change_end + or M.data.largest_change_start + M.data.largest_change_end = _end + > M.data.largest_change_end and _end - or M.data.data.largest_change_end + or M.data.largest_change_end end end, }) @@ -661,56 +642,50 @@ M.on = function(event) schedule(function() if - not M.data.data.last_change.active - or M.data.data.largest_change_end == -1 + not M.data.last_change.active + or M.data.largest_change_end == -1 then M.data.check_code_block_type( event.buffer, false - -- M.data.data.last_change.line, - -- M.data.data.last_change.line + 1 + -- M.data.last_change.line, + -- M.data.last_change.line + 1 ) M.data.trigger_highlight_regex_code_block( event.buffer, false, true, - M.data.data.last_change.line, - M.data.data.last_change.line + 1 + M.data.last_change.line, + M.data.last_change.line + 1 ) else M.data.check_code_block_type( event.buffer, false, - M.data.data.last_change.line, - M.data.data.last_change.line + 1 + M.data.last_change.line, + M.data.last_change.line + 1 ) M.data.trigger_highlight_regex_code_block( event.buffer, false, true, - M.data.data.largest_change_start, - M.data.data.largest_change_end + M.data.largest_change_start, + M.data.largest_change_end ) end - M.data.data.largest_change_start, M.data.data.largest_change_end = + M.data.largest_change_start, M.data.largest_change_end = -1, -1 end) elseif event.type == "autocommands.events.vimleavepre" then - M.data.data.disable_deferred_updates = true - -- this autocmd is used to fix hi link syntax languages - -- TEMP(vhyrro): Temporarily removed for testing - executes code twice when it should not. - -- elseif event.type == "autocommands.events.textchanged" then - -- M.data.data.origger_highlight_regex_code_block(event.buffer, false, true) - -- elseif event.type == "autocommands.events.textchangedi" then - -- M.data.data.origger_highlight_regex_code_block(event.buffer, false, true) + M.data.disable_deferred_updates = true elseif event.type == "autocommands.events.colorscheme" then M.data.trigger_highlight_regex_code_block(event.buffer, true, false) end end M.events.subscribed = { - ["autocommands"] = { + autocommands = { bufenter = true, colorscheme = true, insertleave = true, diff --git a/lua/down/mod/edit/toc/init.lua b/lua/down/mod/edit/toc/init.lua index 2447f28..39fa0fe 100644 --- a/lua/down/mod/edit/toc/init.lua +++ b/lua/down/mod/edit/toc/init.lua @@ -38,6 +38,7 @@ end ---Track if the next TOC open was automatic. Used to determine if we should enter the TOC or not. local next_open_is_auto = false +---@class down.edit.toc.Config M.config = { -- close the Table of Contents after an entry in the table is picked close_after_use = false, @@ -100,7 +101,7 @@ local function get_target_location_under_cursor(ui_data) local curline = vim.api.nvim_win_get_cursor(ui_window)[1] local offset = ui_data.start_lines.offset local extmark_lookup = - data_of_down_buf[ui_data.down_buffer].extmarks[curline - offset] + data_of_down_buf[ui_data.down_buffer].extmarks[curline - offset] if not extmark_lookup then return @@ -116,7 +117,7 @@ end local toc_query ----@class toc +---@class down.edit.toc.Data M.data = { parse_toc_macro = function(buffer) local toc, toc_name = false, nil @@ -131,16 +132,16 @@ M.data = { local capture_name = query.captures[id] if - capture_name == "name" - and M.required["integration.treesitter"] - .get_node_text(node, buffer) - :lower() + capture_name == "name" + and M.required["integration.treesitter"] + .get_node_text(node, buffer) + :lower() == "toc" then toc = true elseif capture_name == "parameters" and toc then toc_name = - M.required["integration.treesitter"].get_node_text(node, buffer) + M.required["integration.treesitter"].get_node_text(node, buffer) return true end end, @@ -182,10 +183,10 @@ M.data = { if prefix and title then local prefix_text = - M.required["integration.treesitter"].get_node_text( - prefix, - original_buffer - ) + M.required["integration.treesitter"].get_node_text( + prefix, + original_buffer + ) local title_text = M.required["integration.treesitter"].get_node_text( title, original_buffer @@ -231,7 +232,7 @@ M.data = { assert(start_lines) local current_toc_item_idx = upper_bound(start_lines, current_row_1b - 1) - - 1 + - 1 local current_toc_row = ( current_toc_item_idx == 0 and math.max(1, start_lines.offset) or current_toc_item_idx + start_lines.offset @@ -265,9 +266,9 @@ M.data = { ui_data.start_lines = start_lines toc_query = toc_query - or utils.ts_parse_query( - "down", - [[ + or utils.ts_parse_query( + "down", + [[ ( [(heading1_prefix)(heading2_prefix)(heading3_prefix)(heading4_prefix)(heading5_prefix)(heading6_prefix)]@prefix . @@ -275,10 +276,10 @@ M.data = { . title: (paragraph_segment)@title )]] - ) + ) local down_root = - M.required["integration.treesitter"].get_document_root(down_buffer) + M.required["integration.treesitter"].get_document_root(down_buffer) if not down_root then return end @@ -297,7 +298,7 @@ M.data = { local heading_texts = {} for _, capture in ipairs(heading_nodes) do if - capture.modifier and capture.modifier:type() == "todo_item_cancelled" + capture.modifier and capture.modifier:type() == "todo_item_cancelled" then goto continue end @@ -318,16 +319,16 @@ M.data = { ) for _, line in - ipairs( - vim.api.nvim_buf_get_text( - down_buffer, - row_start_0b, - col_start_0b, - row_end_0bin, - col_end_0bex, - {} - ) + ipairs( + vim.api.nvim_buf_get_text( + down_buffer, + row_start_0b, + col_start_0b, + row_end_0bin, + col_end_0bex, + {} ) + ) do table.insert(heading_texts, line) end @@ -352,7 +353,7 @@ M.data = { local buf_width = nil if toc_window ~= -1 then buf_width = vim.api.nvim_win_get_width(toc_window) - - M.data.data.get_toc_width(ui_data) + - M.data.data.get_toc_width(ui_data) if buf_width < 1 then buf_width = nil end @@ -490,7 +491,7 @@ M.on = function(event) end local toc_title = - vim.split(M.data.parse_toc_macro(event.buffer) or "Table of Contents", "\n") + vim.split(M.data.parse_toc_macro(event.buffer) or "Table of Contents", "\n") local down_buffer = event.buffer if event.content and event.content[1] == "qflist" then @@ -525,7 +526,7 @@ M.on = function(event) end local ui_data = - create_ui(tabpage, event.content[1] or "left", enter_toc_win()) + create_ui(tabpage, event.content[1] or "left", enter_toc_win()) next_open_is_auto = false M.data.update_toc(toc_title, ui_data_of_tabpage[tabpage], down_buffer) @@ -557,7 +558,7 @@ M.on = function(event) pattern = "*.down", callback = unlisten_if_closed(function(buf, ui) toc_title = - vim.split(M.data.parse_toc_macro(buf) or "Table of Contents", "\n") + vim.split(M.data.parse_toc_macro(buf) or "Table of Contents", "\n") data_of_down_buf[buf].last_row = nil -- invalidate cursor cache M.data.update_toc(toc_title, ui, buf) end), @@ -571,7 +572,7 @@ M.on = function(event) end toc_title = - vim.split(M.data.parse_toc_macro(buf) or "Table of Contents", "\n") + vim.split(M.data.parse_toc_macro(buf) or "Table of Contents", "\n") M.data.update_toc(toc_title, ui, buf) end), }) @@ -645,11 +646,11 @@ M.on = function(event) callback = unlisten_if_closed(function(_, _) vim.schedule(function() local real_windows = vim - .iter(vim.api.nvim_list_wins()) - :filter(function(win) - return vim.api.nvim_win_get_config(win).relative == "" - end) - :totable() + .iter(vim.api.nvim_list_wins()) + :filter(function(win) + return vim.api.nvim_win_get_config(win).relative == "" + end) + :totable() if #real_windows == 1 then vim.schedule(vim.cmd.q) end diff --git a/lua/down/mod/edit/toc/util.lua b/lua/down/mod/edit/toc/util.lua new file mode 100644 index 0000000..d4a49f8 --- /dev/null +++ b/lua/down/mod/edit/toc/util.lua @@ -0,0 +1,3 @@ +local U = {} + +return U diff --git a/lua/down/mod/edit/todo/init.lua b/lua/down/mod/edit/todo/init.lua index c964696..4810a37 100644 --- a/lua/down/mod/edit/todo/init.lua +++ b/lua/down/mod/edit/todo/init.lua @@ -1,7 +1,7 @@ local down = require("down") -local log, Ms = down.log, down.mod +local log, mod = down.log, down.mod -local M = Ms.create("edit.todo") +local M = mod.create("edit.todo") M.setup = function() return { loaded = true, requires = { "integration.treesitter" } } @@ -28,14 +28,15 @@ M.load = function() end end +---@class down.edit.todo.Config M.config = { -- The default order of TODO item cycling when cycling via -- ``. -- -- Defaults to the following order: `undone`, `done`, `pending`. order = { - { "undone", " " }, - { "done", "x" }, + { "undone", " " }, + { "done", "x" }, { "pending", "-" }, }, @@ -48,7 +49,7 @@ M.config = { -- Defaults to the following order: `undone`, `done`. order_with_children = { { "undone", " " }, - { "done", "x" }, + { "done", "x" }, }, -- When set to `true`, will automatically convert parent @@ -100,7 +101,7 @@ local function task_set(character, name) local cursor = vim.api.nvim_win_get_cursor(0) local todo_at_cursor = - M.data.data.get_todo_from_cursor(buffer, cursor[1] - 1) + M.data.data.get_todo_from_cursor(buffer, cursor[1] - 1) if not todo_at_cursor then return @@ -110,7 +111,7 @@ local function task_set(character, name) end) end ----@class todos +------@class down.edit.todo.Data M.data = { data = { @@ -135,9 +136,9 @@ M.data = { -- If the final item does not exist or the target item is not a detached modifier -- (i.e. it does not have a "prefix" node) then it is not a node worth updating. if - not item_at_cursor - or not item_at_cursor:named_child(0) - or not item_at_cursor:named_child(0):type():match("prefix") + not item_at_cursor + or not item_at_cursor:named_child(0) + or not item_at_cursor:named_child(0):type():match("prefix") then return end @@ -158,8 +159,8 @@ M.data = { -- Go through all the children of the current todo item node and count the amount of "done" children for node in item_at_cursor:iter_children() do if - node:named_child(1) - and node:named_child(1):type() == "detached_modifier_extension" + node:named_child(1) + and node:named_child(1):type() == "detached_modifier_extension" then for status in node:named_child(1):iter_children() do if status:type():match("^todo_") then @@ -194,8 +195,8 @@ M.data = { if counts.uncertain > 0 and counts.done + counts.uncertain == counter then resulting_char = "=" elseif - counts.on_hold > 0 - and counts.done + counts.on_hold + counts.uncertain == counter + counts.on_hold > 0 + and counts.done + counts.on_hold + counts.uncertain == counter then resulting_char = "=" elseif counts.pending > 0 then @@ -209,7 +210,7 @@ M.data = { end local first_status_extension = - M.data.data.find_first_status_extension(item_at_cursor:named_child(1)) + M.data.data.find_first_status_extension(item_at_cursor:named_child(1)) -- TODO(vhyrro): -- Implement a toggleable behaviour where down can automatically convert this: @@ -273,7 +274,7 @@ M.data = { ---@return userdata? #The node if it was located, else nil get_todo_from_cursor = function(buf, line) local node_at_cursor = - M.required["integration.treesitter"].get_first_node_on_line(buf, line) + M.required["integration.treesitter"].get_first_node_on_line(buf, line) if not node_at_cursor then return @@ -314,7 +315,7 @@ M.data = { end local todo_type = - M.data.data.find_first_status_extension(todo_node:named_child(1)) ---@diagnostic disable-line -- TODO: type error workaround + M.data.data.find_first_status_extension(todo_node:named_child(1)) ---@diagnostic disable-line -- TODO: type error workaround return todo_type and todo_type:type():sub(string.len("todo_") + 1) or nil end, @@ -338,7 +339,7 @@ M.data = { end local first_status_extension = - M.data.data.find_first_status_extension(node:named_child(1)) ---@diagnostic disable-line -- TODO: type error workaround + M.data.data.find_first_status_extension(node:named_child(1)) ---@diagnostic disable-line -- TODO: type error workaround if not first_status_extension then if not M.config.create_todos then @@ -419,7 +420,7 @@ M.data = { for child in todo_at_cursor:iter_children() do if M.data.data.get_todo_type(child) then next = alternative_types[get_index(alternative_types, todo_type)] - or alternative_types[1] + or alternative_types[1] break end end diff --git a/lua/down/mod/lsp/init.lua b/lua/down/mod/lsp/init.lua index ef55b39..4a02514 100644 --- a/lua/down/mod/lsp/init.lua +++ b/lua/down/mod/lsp/init.lua @@ -111,6 +111,7 @@ M.setup = function() } end +---@class down.lsp.Data M.data = { experimentalCapabilities = { followLinks = true, @@ -167,7 +168,7 @@ M.data = { ws_folders = Mod.get_mod("lsp.workspace.folders"), } ----@class down.lsp.config +---@class down.lsp.Config M.config = { diagnostic = { enable = true }, format = { enable = true }, @@ -180,7 +181,7 @@ M.config = { semantic = { enable = true, }, - signature = mod.get_mod_config("lsp.completion.signature"), + signature = mod.mod_config("lsp.completion.signature"), completion = { -- Enable or disable the completion provider enable = true, @@ -443,36 +444,36 @@ M.data.handlers = { ---@param callback fun(err: any, result: lsp.InitializeResult):nil ---@param notify_reply_callback fun(err: any, result: lsp.InitializeResult):nil ["window/showMessageRequest"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) end, ---@param params lsp.InitializeParams: params ---@param callback fun(err: any, result: lsp.InitializeResult):nil ---@param notify_reply_callback fun(err: any, result: lsp.InitializeResult):nil ["workspace/diagnostic/refresh"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) end, ---@param params lsp.InitializeParams: params ---@param callback fun(err: any, result: lsp.InitializeResult):nil ---@param notify_reply_callback fun(err: any, result: lsp.InitializeResult):nil ["workspace/didChangeConfiguration"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) end, ---@param params lsp.InitializeParams: params ---@param callback fun(err: any, result: lsp.InitializeResult):nil ---@param notify_reply_callback fun(err: any, result: lsp.InitializeResult):nil ["workspace/didChangeWorkspaceFolders"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) end, ---@param params lsp.InitializeParams: params @@ -502,33 +503,33 @@ M.data.handlers = { ["codeLens/resolve"] = function() end, ["inlayHint/resolve"] = function() end, ["textDocument/moniker"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) end, ["workspace/applyEdit"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) end, ["textDocument/documentLink"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) end, ["documentLink/resolve"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) end, ["textDocument/declaration"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) end, ["textDocument/hover"] = function(params, callback, _notify_reply_callback) @@ -556,31 +557,31 @@ M.data.handlers = { end, ["textDocument/formatting"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) format.format_document(params.textDocument.uri, callback) end, ["textDocument/inlineValue/refresh"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) callback() end, ["textDocument/inlineValue"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) callback() end, ["textDocument/inlayHint"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) vim.lsp.inlay_hint.enable(true, { bufnr = buf }) @@ -600,9 +601,9 @@ M.data.handlers = { _callback(nil, hints) end, ["textDocument/documentSymbol"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) local symbols = {} @@ -631,9 +632,9 @@ M.data.handlers = { end, ["textDocument/linkedEditingRange"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) -- local node = ts.get_first_node_on_line(buf, params.position.line) @@ -651,9 +652,9 @@ M.data.handlers = { callback(nil, range) end, ["textDocument/foldingRange"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) local ranges = {} @@ -671,9 +672,9 @@ M.data.handlers = { callback(nil, ranges) end, ["textDocument/completion"] = function( - params, - callback, - notify_reply_callback + params, + callback, + notify_reply_callback ) if M.config.completion.categories then local cats = cmp.category_completion() @@ -686,9 +687,9 @@ M.data.handlers = { end, ["textDocument/prepareRename"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) -- local node = ts.get_first_node_on_line(buf, params.position.line) @@ -714,9 +715,9 @@ M.data.handlers = { end, ["textDocument/codeLens"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) local codeLens = {} @@ -747,9 +748,9 @@ M.data.handlers = { end, ["textDocument/references"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) local wspath = M.required["workspace"].get_current_workspace()[2] @@ -775,9 +776,9 @@ M.data.handlers = { end, ["workspace/inlayHint/refresh"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.uri) local hints = {} @@ -797,87 +798,87 @@ M.data.handlers = { end, ["typeHierarchy/subtypes"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["typeHierarchy/supertypes"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/typeDefinition"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["workspace/configuration"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["workspace/executeCommand"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["workspace/workspaceFolders"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["workspace/symbol"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/semanticTokens/full"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/semanticTokens/refresh"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/semanticTokens/delta"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/semanticTokens/range"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/publishDiagnostics"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/prepareTypeHierarchy"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) end, ["textDocument/implementation"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) -- local node = ts.get_first_node_on_line(buf, params.position.line) @@ -905,9 +906,9 @@ M.data.handlers = { end, ["textDocument/codeLens"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) local codeLens = {} @@ -939,24 +940,24 @@ M.data.handlers = { end, ["textDocument/documentHighlight"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) vim.lsp.buf.document_highlight() end, ["textDocument/signatureHelp"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) vim.lsp.buf.signature_help() end, ["completionItem/resolve"] = function() end, ["textDocument/codeAction"] = function( - params, - callback, - _notify_reply_callback + params, + callback, + _notify_reply_callback ) local buf = vim.uri_to_bufnr(params.textDocument.uri) local actions = {} @@ -999,9 +1000,9 @@ M.data.handlers = { ["workspace/willCreateFiles"] = function() end, ["workspace/willDeleteFiles"] = function() end, ["workspace/willRenameFiles"] = function( - params, - _callback, - _notify_reply_callback + params, + _callback, + _notify_reply_callback ) for _, files in ipairs(params.files) do local old = vim.uri_to_fname(files.oldUri) @@ -1019,7 +1020,7 @@ M.data.start_lsp = function() -- cmd = { "down-lsp", "serve" }, -- }) vim.lsp.start( - ---@type vim.lsp.ClientConfig + ---@type vim.lsp.ClientConfig { name = "down", -- workspace_folders = { @@ -1027,7 +1028,7 @@ M.data.start_lsp = function() -- }, -- capabilities = M.data.initResult().capabilities, capabilities = vim.lsp.protocol.resolve_capabilities(M.data.capabilities) - or M.data.capabilities, + or M.data.capabilities, handlers = M.data.handlers, commands = { ls = { diff --git a/lua/down/mod/note/init.lua b/lua/down/mod/note/init.lua index 352b294..9972358 100644 --- a/lua/down/mod/note/init.lua +++ b/lua/down/mod/note/init.lua @@ -1,4 +1,5 @@ local down = require("down") +local u = require "down.mod.note.util" local config, lib, log, mod = require("down.config").config, down.lib, down.log, down.mod @@ -355,7 +356,7 @@ M.data = { open_toc = function() local workspace = M.config.workspace or M.required["workspace"].get_current_workspace()[1] - local index = mod.get_mod_config("workspace").index + local index = mod.mod_config("workspace").index local folder_name = M.config.note_folder -- If the toc exists, open it, if not, create it @@ -377,7 +378,7 @@ M.data = { create_toc = function() local workspace = M.config.workspace or M.required["workspace"].get_current_workspace()[1] - local index = mod.get_mod_config("workspace").index + local index = mod.mod_config("workspace").index local workspace_path = M.required["workspace"].get_workspace(workspace) local workspace_name_for_link = M.config.workspace or "" local folder_name = M.config.note_folder @@ -660,6 +661,28 @@ M.on = function(event) M.data.note_tomorrow() elseif event.split_type[2] == "note.yesterday" then M.data.note_yesterday() + elseif event.split_type[2] == "calendar" then + if not event.content[1] then + local cal = M.required["ui.calendar"] + if not cal then + print("[ERROR]: `ui.calendar` is not loaded!") + return + end + cal.select_date({ + callback = vim.schedule_wrap(function(osdate) + M.data.open_note( + nil, + string.format("%04d", osdate.year) + .. "-" + .. string.format("%02d", osdate.month) + .. "-" + .. string.format("%02d", osdate.day) + ) + end), + }) + else + M.data.open_note(nil, event.content[1]) + end elseif event.split_type[2] == "note.calendar" then if not event.content[1] then local cal = M.required["ui.calendar"] @@ -705,56 +728,6 @@ M.on = function(event) end end -M.data.weekdays = { - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", -} -M.data.months = { - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", -} -M.data.dateformat = { - week = "%V", - hour24 = "%H:%M:%S", - hour12 = "%I:%M:%S %p", -} -function M.data:number_to_weekday(n) - if n ~= nil then - return M.data.weekday[n] - end -end - -M.data.number_to_month = function(n) - return M.data.months[n] -end -M.data.year = tonumber(os.date("%Y")) -M.data.month = tonumber(os.date("%m")) -M.data.day = tonumber(os.date("%d")) -M.data.timetable = { - year = M.data.year, - month = M.data.month, - day = M.data.day, - hour = 0, - min = 0, - sec = 0, -} -M.data.time = os.time() -M.data.weekday = tonumber(os.date("%w", os.time(M.data.timetable))) M.setup = function() if M.config.strategies[M.config.strategy] then M.config.strategy = @@ -763,6 +736,10 @@ M.setup = function() mod.await("cmd", function(cmd) cmd.add_commands_from_table({ + calendar = { + max_args = 1, + name = "calendar", + }, -- format :yyyy-mm-dd note = { min_args = 1, max_args = 2, @@ -817,7 +794,10 @@ M.setup = function() tomorrow = { args = 0, name = "note.tomorrow" }, yesterday = { args = 0, name = "note.yesterday" }, today = { args = 0, name = "note.today" }, - calendar = { max_args = 1, name = "note.calendar" }, -- format :yyyy-mm-dd + calendar = { + max_args = 1, + name = "note.calendar" + }, -- format :yyyy-mm-dd template = { subcommands = { year = { @@ -886,6 +866,7 @@ M.events.subscribed = { ["note.tomorrow"] = true, ["note.capture"] = true, ["note.today"] = true, + ["calendar"] = true, ["note.calendar"] = true, ["note.template"] = true, ["note.template.day"] = true, diff --git a/lua/down/mod/note/util.lua b/lua/down/mod/note/util.lua new file mode 100644 index 0000000..28d1dce --- /dev/null +++ b/lua/down/mod/note/util.lua @@ -0,0 +1,57 @@ +local U = {} + +U.weekdays = { + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", +} +U.months = { + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", +} + +U.dateformat = { + week = "%V", + hour24 = "%H:%M:%S", + hour12 = "%I:%M:%S %p", +} + +U.number_to_month = function(n) + return U.months[n] +end +U.year = tonumber(os.date("%Y")) +U.month = tonumber(os.date("%m")) +U.day = tonumber(os.date("%d")) +U.timetable = { + year = U.year, + month = U.month, + day = U.day, + hour = 0, + min = 0, + sec = 0, +} +U.time = os.time() +U.weekday = tonumber(os.date("%w", os.time(U.timetable))) + + +function U.number_to_weekday(n) + if n ~= nil then + return U.weekday[n] + end +end + +return U