From ce4a14554679a5f4f06f2865eb5f1b32d4d54680 Mon Sep 17 00:00:00 2001 From: Chris Pecunies Date: Sun, 22 Dec 2024 23:40:01 -0800 Subject: [PATCH] types --- .gitignore | 2 +- ext/lsp | 2 +- lua/down.lua | 60 +- lua/down/core/data/cache.lua | 51 -- lua/down/core/data/store.lua | 3 - lua/down/core/parse/init.lua | 2 +- lua/down/lsp/completion/init.lua | 0 lua/down/lsp/core/init.lua | 0 lua/down/lsp/document/init.lua | 0 lua/down/lsp/init.lua | 166 ----- lua/down/lsp/main.lua | 19 - lua/down/lsp/notebook/init.lua | 2 - lua/down/lsp/service/init.lua | 33 - lua/down/lsp/util/init.lua | 0 lua/down/lsp/util/json.lua | 8 - lua/down/lsp/workspace/init.lua | 7 - lua/down/mod.lua | 195 +++--- lua/down/mod/config.lua | 28 +- lua/down/mod/data/encrypt/init.lua | 2 + lua/down/mod/data/init.lua | 16 +- lua/down/mod/data/media/init.lua | 9 +- lua/down/mod/data/metadata/init.lua | 2 + lua/down/mod/data/todo/init.lua | 44 +- lua/down/mod/edit/find/README.md | 0 lua/down/mod/edit/find/init.lua | 49 -- lua/down/mod/edit/init.lua | 115 ++-- lua/down/mod/edit/parse/README.md | 0 lua/down/mod/edit/parse/datetime/README.md | 0 lua/down/mod/edit/parse/datetime/init.lua | 25 - lua/down/mod/edit/parse/heading/README.md | 0 lua/down/mod/edit/parse/heading/init.lua | 20 - lua/down/mod/edit/parse/init.lua | 38 -- lua/down/mod/edit/parse/link/README.md | 0 lua/down/mod/edit/parse/link/init.lua | 14 - lua/down/mod/edit/parse/scan/README.md | 0 lua/down/mod/edit/parse/scan/init.lua | 15 - lua/down/mod/edit/parse/tag/README.md | 0 lua/down/mod/edit/parse/tag/init.lua | 15 - lua/down/mod/edit/todo/README.md | 1 - lua/down/mod/edit/todo/init.lua | 464 -------------- lua/down/mod/lsp/init.lua | 2 + lua/down/mod/workspace/util.lua | 22 + lua/down/types.lua | 193 ------ lua/down/types/config.lua | 62 ++ lua/down/types/context.lua | 23 + lua/down/types/data.lua | 20 + lua/down/types/date.lua | 27 + lua/down/types/entity.lua | 118 ++++ lua/down/types/enum.lua | 112 ++++ lua/down/types/event.lua | 1 + lua/down/types/file.lua | 14 + lua/down/types/init.lua | 211 +++++++ lua/down/types/mod.lua | 16 + lua/down/types/store.lua | 156 +++++ lua/down/types/util.lua | 56 ++ lua/down/types/workspace.lua | 7 + lua/down/util/lsp.lua | 49 ++ readme.dn | 1 + scripts/bin/down | 504 +++++++-------- scripts/bin/down-lsp | 702 --------------------- scripts/bin/down-lsp.sh | 386 ----------- scripts/bin/downls | 115 ---- selene.toml | 7 - test/init.lua | 5 +- {lua/down/lsp/client => test/lsp}/init.lua | 0 test/test.down | 0 test/test.lua | 35 + test/test.md | 46 -- 68 files changed, 1385 insertions(+), 2912 deletions(-) delete mode 100644 lua/down/lsp/completion/init.lua delete mode 100644 lua/down/lsp/core/init.lua delete mode 100644 lua/down/lsp/document/init.lua delete mode 100644 lua/down/lsp/init.lua delete mode 100644 lua/down/lsp/main.lua delete mode 100644 lua/down/lsp/notebook/init.lua delete mode 100644 lua/down/lsp/service/init.lua delete mode 100644 lua/down/lsp/util/init.lua delete mode 100644 lua/down/lsp/util/json.lua delete mode 100644 lua/down/lsp/workspace/init.lua delete mode 100644 lua/down/mod/edit/find/README.md delete mode 100644 lua/down/mod/edit/find/init.lua delete mode 100644 lua/down/mod/edit/parse/README.md delete mode 100644 lua/down/mod/edit/parse/datetime/README.md delete mode 100644 lua/down/mod/edit/parse/datetime/init.lua delete mode 100644 lua/down/mod/edit/parse/heading/README.md delete mode 100644 lua/down/mod/edit/parse/heading/init.lua delete mode 100644 lua/down/mod/edit/parse/init.lua delete mode 100644 lua/down/mod/edit/parse/link/README.md delete mode 100644 lua/down/mod/edit/parse/link/init.lua delete mode 100644 lua/down/mod/edit/parse/scan/README.md delete mode 100644 lua/down/mod/edit/parse/scan/init.lua delete mode 100644 lua/down/mod/edit/parse/tag/README.md delete mode 100644 lua/down/mod/edit/parse/tag/init.lua delete mode 100644 lua/down/mod/edit/todo/README.md delete mode 100644 lua/down/mod/edit/todo/init.lua delete mode 100644 lua/down/types.lua create mode 100644 lua/down/types/config.lua create mode 100644 lua/down/types/context.lua create mode 100644 lua/down/types/data.lua create mode 100644 lua/down/types/date.lua create mode 100644 lua/down/types/entity.lua create mode 100644 lua/down/types/enum.lua create mode 100644 lua/down/types/event.lua create mode 100644 lua/down/types/file.lua create mode 100644 lua/down/types/init.lua create mode 100644 lua/down/types/mod.lua create mode 100644 lua/down/types/store.lua create mode 100644 lua/down/types/util.lua create mode 100644 lua/down/types/workspace.lua create mode 100644 lua/down/util/lsp.lua create mode 100644 readme.dn delete mode 100755 scripts/bin/down-lsp delete mode 100755 scripts/bin/down-lsp.sh delete mode 100755 scripts/bin/downls delete mode 100644 selene.toml rename {lua/down/lsp/client => test/lsp}/init.lua (100%) delete mode 100644 test/test.down create mode 100644 test/test.lua delete mode 100644 test/test.md diff --git a/.gitignore b/.gitignore index d3b5d27..50f1410 100644 --- a/.gitignore +++ b/.gitignore @@ -29,11 +29,11 @@ downls .pre-commit-config.yaml /doc/tags **ext/sublime +**autoload/ **ext/v **ext/oc **ext/helix **ext/zed -# **ext/lsp **ext/rust-lsp **ext/nim **.book/ diff --git a/ext/lsp b/ext/lsp index 585e145..c42052d 160000 --- a/ext/lsp +++ b/ext/lsp @@ -1 +1 @@ -Subproject commit 585e145d1e5ca727dd93c72ae14159f23df14aba +Subproject commit c42052db35846f68372ad55f7ea58de2086b11a3 diff --git a/lua/down.lua b/lua/down.lua index 06879ac..5eda808 100644 --- a/lua/down.lua +++ b/lua/down.lua @@ -11,26 +11,25 @@ ---@class down.down local W = { - cfg = require("down.config").config, - mod = require("down.mod"), - config = require("down.config"), - callbacks = require("down.util.event.callback"), - log = require("down.util.log"), - types = require("down.types"), - health = require("down.health"), - core = require("down.core"), + cfg = require('down.config').config, + mod = require('down.mod'), + config = require('down.config'), + callbacks = require('down.util.event.callback'), + log = require('down.util.log'), + health = require('down.health'), + core = require('down.core'), util = { - util = require("down.util"), - log = require("down.util.log"), - buf = require("down.util.buf"), + util = require('down.util'), + log = require('down.util.log'), + buf = require('down.util.buf'), -- cb = require("down.event.cb"), }, - utils = require("down.util"), - lib = require("down.util.lib"), + utils = require('down.util'), + lib = require('down.util.lib'), } -- local e = require("down") -local con, log, m, utils = require("down.config").config, W.log, W.mod, W.utils +local con, log, m, utils = require('down.config').config, W.log, W.mod, W.utils local a, f, ext = vim.api, vim.fn, vim.tbl_deep_extend --- @init "down.config" @@ -44,8 +43,8 @@ function W.setup(conf) end con.user = utils.extend(con.user, conf) -- log.new(con.user.logger or log.get_base_config(), true) - require("down.config").setup_maps() - require("down.config").setup_opts() + require('down.config').setup_maps() + require('down.config').setup_opts() if W.util.buf.check_md() or not con.user.lazy then W.enter(false) @@ -54,14 +53,15 @@ function W.setup(conf) -- vim.cmd.delcommand("downInit") -- W.enter(true) -- end, {}) - - a.nvim_create_autocmd("BufAdd", { - pattern = "markdown", + a.nvim_create_autocmd('BufAdd', { + pattern = { 'markdown' }, callback = function() W.enter(false) end, }) end + require 'down.util.lsp'.setup() + require 'down.util.lsp'.run() end ---@param manual table @@ -76,7 +76,7 @@ function W.enter(manual, args) end con.manual = manual if args and args:len() > 0 then - for key, value in args:gmatch("([%w%W]+)=([%w%W]+)") do + for key, value in args:gmatch('([%w%W]+)=([%w%W]+)') do con.args[key] = value end end @@ -86,7 +86,7 @@ function W.enter(manual, args) end for name, _ in pairs(mods) do if not m.load_mod(name) then - log.warn("Error recovery") + log.warn('Error recovery') m.loaded_mod[name] = nil end end @@ -96,23 +96,23 @@ function W.enter(manual, args) con.started = true m.broadcast({ - type = "started", + type = 'started', split_type = { - "started", + 'started', }, - filename = "", - filehead = "", + filename = '', + filehead = '', cursor_position = { 0, 0 }, - referrer = "config", - topic = "started", - line_content = "", + referrer = 'config', + topic = 'started', + line_content = '', broadcast = true, buffer = a.nvim_get_current_buf(), window = a.nvim_get_current_win(), mode = f.mode(), }) - vim.api.nvim_exec_autocmds("User", { - pattern = "downLoaded", -- + vim.api.nvim_exec_autocmds('User', { + pattern = 'downLoaded', -- }) end diff --git a/lua/down/core/data/cache.lua b/lua/down/core/data/cache.lua index 007066a..8b13789 100644 --- a/lua/down/core/data/cache.lua +++ b/lua/down/core/data/cache.lua @@ -1,52 +1 @@ ----@class down.core.data.cache.Cache ----@field public head any ----@field public tail any ----@field public len integer ----@field public cache table ----@field public cap integer -local Cache = {} -Cache.__index = Cache - -function Cache.newcache() end - -function Cache.new(cap) - local c = { - head = nil, - tail = nil, - len = 0, - cap = cap, - cache = { } - } - return setmetatable({ - __index = c, - }, c) -end - -Cache.__len = function() - return Cache.len -end - -function Cache:set(k, v) - self.cache[k] = v -end - -function Cache.__newindex(self, k, v) - self.set(k, v) -end - -Cache.__tostring = function(self) - local s = "" - for ii, i in ipairs(self.cache) do - s = s .. tostring(ii) .. tostring(i) - end - return s -end - -function Cache:del() end - -function Cache:clear() end - -function Cache:get() end - -return Cache diff --git a/lua/down/core/data/store.lua b/lua/down/core/data/store.lua index 8bfa72f..8b13789 100644 --- a/lua/down/core/data/store.lua +++ b/lua/down/core/data/store.lua @@ -1,4 +1 @@ ----@class down.core.data.store.Store -local S = {} -return S diff --git a/lua/down/core/parse/init.lua b/lua/down/core/parse/init.lua index 0548699..4bb58db 100644 --- a/lua/down/core/parse/init.lua +++ b/lua/down/core/parse/init.lua @@ -1,6 +1,6 @@ ---@class down.core.parse.Parse local P = {} - +local l = vim.lpeg return P diff --git a/lua/down/lsp/completion/init.lua b/lua/down/lsp/completion/init.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/lsp/core/init.lua b/lua/down/lsp/core/init.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/lsp/document/init.lua b/lua/down/lsp/document/init.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/lsp/init.lua b/lua/down/lsp/init.lua deleted file mode 100644 index 7a281a4..0000000 --- a/lua/down/lsp/init.lua +++ /dev/null @@ -1,166 +0,0 @@ -local Lsp = {} - -Lsp.attributes = { - -} - -Lsp.capabilities = { - textDocumentSync = { - save = { - includeText = false - } - }, - definitionProvider = true, - hoverProvider = true, - workspace = { - workspaceFolders = { - supported = true, - changeNotifications = true - }, - fileOperations = { - didRename = { - filters = function() - local filters = {} - return filters - end, - } - } - }, - typeDefinitionProvider = true, - implementationProvider = true, - referencesProvider = true, - workspaceSymbolProvider = true, - codeLensProvider = { - resolveProvider = true - }, - executeCommandProvider = { - commands = { - "down.rename", - "down.note.new", - "down.workspace.change", - "down.workspace.new", - "down.workspace.delete", - "down.file.remove", - "down.file.new" - } - }, - codeActionProvider = { - codeActionKinds = { - '', 'quickfix', - 'refactor.rewrite', - 'refactor.extract', - }, - resolveProvider = false - }, - diagnosticProvider = { - identifier = "down", - interFileDependencies = true, - workspaceDiagnostics = true, - }, - inlayHintProvider = { - resolveProvider = true - }, - documentSymbolProvider = true, - documentRangeFormattingProvider = true, - foldingRangeProvider = true, - -} -Lsp.info = { - serverInfo = { name = "down", version = "0.1.2-alpha" }, - capabilities = Lsp.capabilities -} - -Lsp.register = function(method) - return function(attr) - Lsp.attributes[method] = attr - end -end - -Lsp.register "initialize" { - function(params) - if params.rootUri then - - end - if params.workspaceFolders then - - end - print "Server init" - return Lsp.info - end -} - -Lsp.register "initialized" { - ---@async - function(params) - local _ = {} - local registrations = {} - print "Server initialized" - return true - end -} - -Lsp.register "exit" { - function() - print "Server exit" - os.exit(0, true) - end -} - -Lsp.register "shutdown" { - function() - print "Server shutdown" - return true - end -} -Lsp.register "workspace/didChangeConfiguration" { - ---@async - function(params) - - end -} -Lsp.register "textDocument/completion" { - ---@async - function(params) - end -} -Lsp.register "completionItem/resolve" { - ---@async - function(params) - end -} -Lsp.register "textDocument/codeAction" { - ---@async - function(params) - end -} -Lsp.register "textDocument/codeLens" { - ---@async - function(params) - local lenses = {} - return lenses - end -} -Lsp.register "workspace/executeCommand" { - ---@async - function(params) - - end -} -Lsp.register "codeLens/resolve" { - ---@async - function(params) - end -} -Lsp.register "textDocument/inlayHint" { - ---@async - function(params) - local hints = {} - return hints - end -} -Lsp.register "inlayHint/resolve" { - ---@async - function(params) - end -} -return Lsp diff --git a/lua/down/lsp/main.lua b/lua/down/lsp/main.lua deleted file mode 100644 index b57b623..0000000 --- a/lua/down/lsp/main.lua +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env lua - -Lsp = require "./init" -Work = require "./workspace/init" -Doc = require "./document/init" - -function main() - Work.init() - local a, ac = arg, #arg - - for i, ar in pairs(a) do - print(i, ar) - end - print("\x1b[33mRunning...\x1b[0m") -end - -main() - ---vim:ft=lua diff --git a/lua/down/lsp/notebook/init.lua b/lua/down/lsp/notebook/init.lua deleted file mode 100644 index 7e58986..0000000 --- a/lua/down/lsp/notebook/init.lua +++ /dev/null @@ -1,2 +0,0 @@ -local N = {} -return N \ No newline at end of file diff --git a/lua/down/lsp/service/init.lua b/lua/down/lsp/service/init.lua deleted file mode 100644 index c1fb52d..0000000 --- a/lua/down/lsp/service/init.lua +++ /dev/null @@ -1,33 +0,0 @@ -local e = require "/nix/store/6qk1rdc2lnk8yc6bvnnda70crcx5jysp-luarocks_bootstrap-3.11.1/lib/luarocks/rocks-5.2/luasocket/3.1.0-1" -local e = require "/nix/store/6qk1rdc2lnk8yc6bvnnda70crcx5jysp-luarocks_bootstrap-3.11.1/lib/lua/5.2" -e -local S = {} - -S.send = function() - print("Sending message") -end - -S.start = function() - print("Server started") -end - -S.req = function(name, params, cb) - local id = l - local m = { - id = 1, - method = name, - params = params, - } - print("Request received") -end -S.listen = function() - print("Listening") -end -S.reply = function() - local m = { - id = 1, - result = "ok", - } -end - -return S diff --git a/lua/down/lsp/util/init.lua b/lua/down/lsp/util/init.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/lsp/util/json.lua b/lua/down/lsp/util/json.lua deleted file mode 100644 index 7cd22c1..0000000 --- a/lua/down/lsp/util/json.lua +++ /dev/null @@ -1,8 +0,0 @@ -local J = {} - -module("down.lsp.util.json") - -J.rpc = function() - -end -return J diff --git a/lua/down/lsp/workspace/init.lua b/lua/down/lsp/workspace/init.lua deleted file mode 100644 index dabf474..0000000 --- a/lua/down/lsp/workspace/init.lua +++ /dev/null @@ -1,7 +0,0 @@ -local W = {} - -function W.init() - print("W.init") -end - -return W diff --git a/lua/down/mod.lua b/lua/down/mod.lua index dfbe0c5..aa0478d 100644 --- a/lua/down/mod.lua +++ b/lua/down/mod.lua @@ -1,11 +1,15 @@ local uv, lu, fn = vim.loop or vim.uv, vim.lsp.util, vim.fn -local cb = require("down.util.event.callback") -local config = require("down.config").config -local log = require("down.util.log") -local utils = require("down.util") +local cb = require('down.util.event.callback') +local config = require('down.config').config +local log = require('down.util.log') +local utils = require('down.util') + +--- @!TODO : Change to body access where appropriate and now available to avoid complex config for end user +--- 1. Firsr try with modules, then workspace -- TODO: remove global +---@return ---@class down.Mod Mod = setmetatable({}, { __index = Mod, @@ -20,6 +24,7 @@ Mod = setmetatable({}, { end, }) +---@return down.Mod ---@param name string The name of the new mod Mod.default = function(name) return { @@ -42,25 +47,14 @@ Mod.default = function(name) ]]) end, maps = function() - -- TODO: obviously inefficient - local Map = require("down.util.maps") - Map.nmap(",wi", "Down index") - Map.nmap(",wp", "Down note template") - Map.nmap(",wc", "Down note calendar") - Map.nmap(",wn", "Down note index") - Map.nmap(",w.", "Down note tomorrow") - Map.nmap(",w,", "Down note yesterday") - Map.nmap(",wm", "Down note month") - Map.nmap(",wt", "Down note today") - Map.nmap(",wy", "Down note year") end, load = function() end, on = function() end, post_load = function() end, - name = "config", - namespace = "down." .. name, - path = "mod.config", - version = require("down").config.version, + name = 'config', + namespace = 'down.' .. name, + path = 'mod.config', + version = require('down').config.version, data = { --TODO: remove data = {}, @@ -85,13 +79,9 @@ function Mod.create(name, imports) local new = Mod.default(name) if imports then for _, imp in ipairs(imports) do - local fullpath = table.concat({ name, imp }, ".") + local fullpath = table.concat({ name, imp }, '.') if not Mod.load_mod(fullpath) then - log.error( - "Unable to load import '" - .. fullpath - .. "'! An error (see traceback below):" - ) + log.error("Unable to load import '" .. fullpath .. "'! An error (see traceback below):") assert(false) end new.import[fullpath] = Mod.loaded_mod[fullpath] @@ -100,8 +90,8 @@ function Mod.create(name, imports) if name then new.name = name - new.path = "mod." .. name - new.namespace = "down.mod." .. name + new.path = 'mod.' .. name + new.namespace = 'down.mod.' .. name vim.api.nvim_create_namespace(new.namespace) end return new @@ -128,9 +118,15 @@ Mod.modules = function(name, ...) return { loaded = true } end -- TODO: consider removing - if m.cmds then m.cmds() end - if m.opts then m.opts() end - if m.maps then m.maps() end + if m.cmds then + m.cmds() + end + if m.opts then + m.opts() + end + if m.maps then + m.maps() + end m.load = function() m.config.enable = (function() @@ -161,11 +157,11 @@ Mod.loaded_mod = {} --- @param m down.Mod The actual init to load. --- @return boolean # Whether the init successfully loaded. function Mod.load_mod_from_table(m) - log.info("Loading init with name" .. m.name) + log.info('Loading init with name' .. m.name) -- If our init is already loaded don't try loading it again if Mod.loaded_mod[m.name] then - log.trace("mod" .. m.name .. "already loaded. Omitting...") + log.trace('mod' .. m.name .. 'already loaded. Omitting...') return true end @@ -183,49 +179,45 @@ function Mod.load_mod_from_table(m) -- We do not expect init.setup() to ever return nil, that's why this check is in place if not mod_load then log.error( - "init" + 'init' .. m.name - .. "does not handle init loading correctly; init.setup() returned nil. Omitting..." + .. 'does not handle init loading correctly; init.setup() returned nil. Omitting...' ) return false end -- A part of the table returned by init.setup() tells us whether or not the init initialization was successful if mod_load.loaded == false then - log.trace("mod" .. m.name .. "did not load properly.") + log.trace('mod' .. m.name .. 'did not load properly.') return false end local mod_to_replace - if mod_load.replaces and mod_load.replaces ~= "" then + if mod_load.replaces and mod_load.replaces ~= '' then mod_to_replace = vim.deepcopy(Mod.loaded_mod[mod_load.replaces]) end Mod.loaded_mod[m.name] = m if mod_load.wants and not vim.tbl_isempty(mod_load.wants) then - log.info( - "mod" .. m.name .. "wants certain mod. Ensuring they are loaded..." - ) + log.info('mod' .. m.name .. 'wants certain mod. Ensuring they are loaded...') -- Loop through each dependency and ensure it's loaded for _, req_mod in ipairs(mod_load.wants) do - log.trace("Verifying" .. req_mod) + log.trace('Verifying' .. req_mod) if not Mod.is_mod_loaded(req_mod) then if config.user.mod[req_mod] then log.trace( - "Wanted init" + 'Wanted init' .. req_mod .. "isn't loaded but can be as it's defined in the user's config. Loading..." ) if not Mod.load_mod(req_mod) then - require("down.util.log").error( - "Unable to load wanted init for" - .. m.name - .. "- the init didn't load successfully" + require('down.util.log').error( + 'Unable to load wanted init for' .. m.name .. "- the init didn't load successfully" ) -- Modake sure to clean up after ourselves if the init failed to load @@ -234,7 +226,7 @@ function Mod.load_mod_from_table(m) end else log.error( - ("Unable to load init %s, wanted dependency %s was not satisfied. Be sure to load the init and its appropriate config too!") + ('Unable to load init %s, wanted dependency %s was not satisfied. Be sure to load the init and its appropriate config too!') :format( m.name, req_mod @@ -254,19 +246,16 @@ function Mod.load_mod_from_table(m) -- If any dependencies have been defined, handle them if mod_load.requires and vim.tbl_count(mod_load.requires) > 0 then - log.info( - "mod" .. m.name .. "has dependencies. Loading dependencies first..." - ) + log.info('mod' .. m.name .. 'has dependencies. Loading dependencies first...') -- Loop through each dependency and load it one by one for _, req_mod in pairs(mod_load.requires) do - log.trace("Loading submod" .. req_mod) + log.trace('Loading submod' .. req_mod) if not Mod.is_mod_loaded(req_mod) then if not Mod.load_mod(req_mod) then log.error( - ("Unable to load init %s, required dependency %s did not load successfully"):format( - m.name .. - req_mod + ('Unable to load init %s, required dependency %s did not load successfully'):format( + m.name .. req_mod ) ) -- Modake sure to clean up after ourselves if the init failed to load @@ -274,7 +263,7 @@ function Mod.load_mod_from_table(m) return false end else - log.trace("mod" .. req_mod .. "already loaded, skipping...") + log.trace('mod' .. req_mod .. 'already loaded, skipping...') end -- Create a reference to the dependency's public table m.required[req_mod] = Mod.loaded_mod[req_mod].data @@ -314,7 +303,7 @@ function Mod.load_mod_from_table(m) m.replaced = true end - log.info("Successfully loaded init" .. m.name) + log.info('Successfully loaded init' .. m.name) Mod.loaded_mod_count = Mod.loaded_mod_count + 1 @@ -335,16 +324,16 @@ function Mod.load_mod_from_table(m) -- vim.notify(msg.." "..init.name) Mod.broadcast({ - type = "mod_loaded", - split_type = { "mod_loaded" }, - filename = "", - filehead = "", + type = 'mod_loaded', + split_type = { 'mod_loaded' }, + filename = '', + filehead = '', cursor_position = { 0, 0 }, referrer = m.name, - line_content = "", + line_content = '', content = m, payload = m, - topic = "mod_loaded", + topic = 'mod_loaded', broadcast = true, buffer = vim.api.nvim_get_current_buf(), window = vim.api.nvim_get_current_win(), @@ -364,19 +353,19 @@ function Mod.load_mod(modn, cfg) if Mod.is_mod_loaded(modn) then return true end - local modl = require("down.mod." .. modn) + local modl = require('down.mod.' .. modn) if not modl then log.error( - "Unable to load init" + 'Unable to load init' .. modn - .. "- loaded file returned nil. Be sure to return the table created by mod.create() at the end of your init.lua file!" + .. '- loaded file returned nil. Be sure to return the table created by mod.create() at the end of your init.lua file!' ) return false end if modl == true then log.error( - "An error has occurred when loading" + 'An error has occurred when loading' .. modn .. "- loaded file didn't return anything meaningful. Be sure to return the table created by mod.create() at the end of your init.lua file!" @@ -405,9 +394,9 @@ end --- @param parent_mod string|down.Mod If a string, then the parent is searched for in the loaded mod. If a table, then the init is treated as a valid init as returned by mod.create() function Mod.load_mod_as_dependency_from_table(md, parent_mod) if Mod.load_mod_from_table(md) then - if type(parent_mod) == "string" then + if type(parent_mod) == 'string' then Mod.loaded_mod[parent_mod].required[md.name] = md.data - elseif type(parent_mod) == "table" then + elseif type(parent_mod) == 'table' then parent_mod.required[md.name] = md.data end end @@ -429,9 +418,7 @@ end --- @return T? function Mod.get_mod(modn) if not Mod.is_mod_loaded(modn) then - log.trace( - "Attempt to get init with name" .. modn .. "failed - init is not loaded." - ) + log.trace('Attempt to get init with name' .. modn .. 'failed - init is not loaded.') return end @@ -443,11 +430,7 @@ end --- @return table? function Mod.mod_config(modn) if not Mod.is_mod_loaded(modn) then - log.trace( - "Attempt to get init config with name" - .. modn - .. "failed - init is not loaded." - ) + log.trace('Attempt to get init config with name' .. modn .. 'failed - init is not loaded.') return end @@ -467,11 +450,7 @@ end function Mod.get_mod_version(modn) -- If the init isn't loaded then don't bother retrieving its version if not Mod.is_mod_loaded(modn) then - log.trace( - "Attempt to get init version with name" - .. modn - .. "failed - init is not loaded." - ) + log.trace('Attempt to get init version with name' .. modn .. 'failed - init is not loaded.') return end @@ -481,9 +460,7 @@ function Mod.get_mod_version(modn) -- If it can't be found then error out if not version then log.trace( - "Attempt to get init version with name" - .. modn - .. "failed - version variable not present." + 'Attempt to get init version with name' .. modn .. 'failed - version variable not present.' ) return end @@ -500,7 +477,7 @@ function Mod.await(modn, callback) return end - cb.on("mod_loaded", function(_, m) + cb.on('mod_loaded', function(_, m) callback(m.data) end, function(event) return event.content.name == modn @@ -510,12 +487,12 @@ end --- @param type string The full path of a init event --- @return string[]? function Mod.split_event_type(type) - local start_str, end_str = type:find("%.events%.") + local start_str, end_str = type:find('%.events%.') local split_event_type = { type:sub(0, start_str - 1), type:sub(end_str + 1) } if #split_event_type ~= 2 then - log.warn("Invalid type name:", type) + log.warn('Invalid type name:', type) return end @@ -529,20 +506,18 @@ end function Mod.get_event_template(m, type) -- You can't get the event template of a type if the type isn't loaded if not Mod.is_mod_loaded(m.name) then - log.info("Unable to get event of type" .. type .. "with init", m.name) + log.info('Unable to get event of type' .. type .. 'with init', m.name) return end local split_type = Mod.split_event_type(type) if not split_type then - log.warn( - "Unable to get event template for event" .. type .. "and init" .. m.name - ) + log.warn('Unable to get event template for event' .. type .. 'and init' .. m.name) return end - log.trace("Returning" .. split_type[2] .. "for init" .. split_type[1]) + log.trace('Returning' .. split_type[2] .. 'for init' .. split_type[1]) -- Return the defined event from the specific init return Mod.loaded_mod[m.name].events[split_type[2]] @@ -558,23 +533,23 @@ function Mod.define_event(m, name) ---@type down.Event local new_event = { payload = nil, - topic = "base_event", - type = "base_event", + topic = 'base_event', + type = 'base_event', split_type = {}, content = nil, - referrer = "config", + referrer = 'config', broadcast = true, cursor_position = {}, - filename = "", - filehead = "", - line_content = "", + filename = '', + filehead = '', + line_content = '', buffer = 0, window = 0, - mode = "", + mode = '', } if name then - new_event.type = m.name .. ".events." .. name + new_event.type = m.name .. '.events.' .. name end new_event.referrer = m.name return new_event @@ -591,11 +566,10 @@ function Mod.create_event(m, type, content, ev) local modn = Mod.split_event_type(type)[1] -- Retrieve the template from init.events - local event_template = - Mod.get_event_template(Mod.loaded_mod[modn] or { name = "" }, type) + local event_template = Mod.get_event_template(Mod.loaded_mod[modn] or { name = '' }, type) if not event_template then - log.warn("Unable to create event of type" .. type .. ". Returning nil...") + log.warn('Unable to create event of type' .. type .. '. Returning nil...') return end @@ -608,8 +582,8 @@ function Mod.create_event(m, type, content, ev) -- Override all the important values new_event.split_type = assert(Mod.split_event_type(type)) - new_event.filename = vim.fn.expand("%:t") --[[@as string]] - new_event.filehead = vim.fn.expand("%:p:h") --[[@as string]] + new_event.filename = vim.fn.expand('%:t') --[[@as string]] + new_event.filehead = vim.fn.expand('%:p:h') --[[@as string]] local bufid = ev and ev.buf or vim.api.nvim_get_current_buf() local winid = assert(vim.fn.bufwinid(bufid)) if winid == -1 then @@ -617,8 +591,7 @@ function Mod.create_event(m, type, content, ev) end new_event.cursor_position = vim.api.nvim_win_get_cursor(winid) local row_1b = new_event.cursor_position[1] - new_event.line_content = - vim.api.nvim_buf_get_lines(bufid, row_1b - 1, row_1b, true)[1] + new_event.line_content = vim.api.nvim_buf_get_lines(bufid, row_1b - 1, row_1b, true)[1] new_event.referrer = m.name new_event.broadcast = true new_event.buffer = bufid @@ -634,11 +607,7 @@ end function Mod.broadcast(event, callback) -- Broadcast the event to all mod if not event.split_type then - log.error( - "Unable to broadcast event of type" - .. event.type - .. "- invalid event name" - ) + log.error('Unable to broadcast event of type' .. event.type .. '- invalid event name') return end @@ -663,9 +632,7 @@ end --- @return nil function Mod.send_event(recv, ev) if not Mod.is_mod_loaded(recv) then - log.warn( - "Unable to send event to init" .. recv .. "- the init is not loaded." - ) + log.warn('Unable to send event to init' .. recv .. '- the init is not loaded.') return end ev.broadcast = false diff --git a/lua/down/mod/config.lua b/lua/down/mod/config.lua index b222a4d..43daa95 100644 --- a/lua/down/mod/config.lua +++ b/lua/down/mod/config.lua @@ -1,17 +1,19 @@ -local M = require("down.mod").modules( +---@brief rest of modules are loaded ---@type string: name of config created - "config", - ---@brief rest of modules are loaded - "ui", - "edit", - "note", - "cmd", - "workspace", - "tool.telescope", - "tool.treesitter", - "data", - "lsp", - "edit" +local M = require('down.mod').modules( + 'config', + 'ui', + 'edit', + 'data', + 'note', + 'cmd', + 'workspace', + 'tool.telescope', + 'tool.treesitter', + 'data', + 'lsp', + 'tool', + 'edit' ) return M diff --git a/lua/down/mod/data/encrypt/init.lua b/lua/down/mod/data/encrypt/init.lua index 15f9d96..35d3d72 100644 --- a/lua/down/mod/data/encrypt/init.lua +++ b/lua/down/mod/data/encrypt/init.lua @@ -1,6 +1,8 @@ local mod = require("down.mod") +local io, os, bit = require("io"), require("os"), require("bit") local E = mod.create("data.encrypt") + E.setup = function() -- mod.await("cmd", function(cmd) -- cmd.add_commands_from_table({ diff --git a/lua/down/mod/data/init.lua b/lua/down/mod/data/init.lua index 52fcfc5..fd268cd 100644 --- a/lua/down/mod/data/init.lua +++ b/lua/down/mod/data/init.lua @@ -4,6 +4,8 @@ --- util.lua file that is required for submodules local M = require("down.mod").create("data", { "log", + "store", + "task", "mod", "sync", "dirs", @@ -17,6 +19,17 @@ local M = require("down.mod").create("data", { -- "code", }) + +---@type down.Store +local files = { + store = { + + + + + } +} + M.setup = function() vim.api.nvim_create_autocmd("VimLeavePre", { callback = function() @@ -24,6 +37,7 @@ M.setup = function() end, }) + M.data.sync() ---@type down.mod.Setup return { @@ -133,7 +147,7 @@ M.data = { file:write( vim.mpack.encode and vim.mpack.encode(M.data.data.data) - or vim.mpack.pack(M.data.data.data) + or vim.mpack.pack(M.data.data.data) ) io.close(file) diff --git a/lua/down/mod/data/media/init.lua b/lua/down/mod/data/media/init.lua index d944f47..dce09a8 100644 --- a/lua/down/mod/data/media/init.lua +++ b/lua/down/mod/data/media/init.lua @@ -1,15 +1,20 @@ local mod = require("down.mod") local M = mod.create("data.media") +---@return down.mod.Setup M.setup = function() + ---@type down.mod.Setup return { + requires = { + "data.dirs", + }, loaded = true, } end ----@class data.media.Data +---@class data.data.media.Data M.data = {} ----@class data.media.Config +---@class data.data.media.Config M.config = {} return M diff --git a/lua/down/mod/data/metadata/init.lua b/lua/down/mod/data/metadata/init.lua index e51941d..1ed5fac 100644 --- a/lua/down/mod/data/metadata/init.lua +++ b/lua/down/mod/data/metadata/init.lua @@ -2,6 +2,7 @@ local mod = require("down.mod") local M = mod.create("data.metadata") +---@return down.mod.Setup M.setup = function() -- mod.await("cmd", function(cmd) -- cmd.add_commands_from_table({ @@ -24,6 +25,7 @@ M.setup = function() -- }, -- }) -- end) + ---@type down.mod.Setup return { loaded = true, required = { diff --git a/lua/down/mod/data/todo/init.lua b/lua/down/mod/data/todo/init.lua index f92e3ce..336c707 100644 --- a/lua/down/mod/data/todo/init.lua +++ b/lua/down/mod/data/todo/init.lua @@ -1,19 +1,19 @@ local mod, map = require("down.mod"), require("down.util.maps") -local M = mod.create("data.todo") +local M = mod.create("data.task") M.maps = function() - map.nmap(",wt", "Telescope down todo") + map.nmap(",wt", "Telescope down task") end ----@class down.data.todo.Data +---@class down.data.task.Data M.data = { - namespace = vim.api.nvim_create_namespace("down.data.todo"), + namespace = vim.api.nvim_create_namespace("down.data.task"), --- List of active buffers buffers = {}, } ----@class down.data.todo.Config +---@class down.data.task.Config M.config = { highlight_group = "Normal", @@ -49,7 +49,7 @@ end M.load = function() vim.api.nvim_create_autocmd("Filetype", { pattern = "markdown", - desc = "Attaches the TODO introspector to any down buffer.", + desc = "Attaches the task introspector to any down buffer.", callback = function(ev) local buf = ev.buf @@ -58,7 +58,7 @@ M.load = function() end M.data.buffers[buf] = true - -- M.public.attach_introspector(buf) -- TODO + -- M.public.attach_introspector(buf) -- task end, }) end @@ -68,8 +68,8 @@ end ---@param buffer number #The buffer ID to attach to. function M.data.attach_introspector(buffer) if - not vim.api.nvim_buf_is_valid(buffer) - or vim.bo[buffer].filetype ~= "markdown" + not vim.api.nvim_buf_is_valid(buffer) + or vim.bo[buffer].filetype ~= "markdown" then error( string.format( @@ -104,7 +104,7 @@ function M.data.attach_introspector(buffer) ---@type TSNode? local node = - M.required["tool.treesitter"].get_first_node_on_line(buf, first) + M.required["tool.treesitter"].get_first_node_on_line(buf, first) if not node then return @@ -135,16 +135,16 @@ function M.data.attach_introspector(buffer) introspect(node) local node_above = - M.required["tool.treesitter"].get_first_node_on_line( - buf, - first - 1 - ) + M.required["tool.treesitter"].get_first_node_on_line( + buf, + first - 1 + ) do - local todo_status = node_above:named_child(1) + local task_status = node_above:named_child(1) if - todo_status and todo_status:type() == "detached_modifier_extension" + task_status and task_status:type() == "detached_modifier_extension" then introspect(node_above) end @@ -158,7 +158,7 @@ function M.data.attach_introspector(buffer) }) end ---- Aggregates TODO item counts from children. +--- Aggregates task item counts from children. ---@param node TSNode ---@return number completed Total number of completed tasks ---@return number total Total number of counted tasks @@ -170,15 +170,15 @@ function M.data.calculate_items(node) local total = 0 - -- Go through all the children of the current todo item node and count the amount of "done" children + -- Go through all the children of the current task item node and count the amount of "done" children for child in node:iter_children() do if - child:named_child(1) - and child:named_child(1):type() == "detached_modifier_extension" + child:named_child(1) + and child:named_child(1):type() == "detached_modifier_extension" then for status in child:named_child(1):iter_children() do - if status:type():match("^todo_item_") then - local type = status:type():match("^todo_item_(.+)$") + if status:type():match("^task_item_") then + local type = status:type():match("^task_item_(.+)$") if not counts[type] then break diff --git a/lua/down/mod/edit/find/README.md b/lua/down/mod/edit/find/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/find/init.lua b/lua/down/mod/edit/find/init.lua deleted file mode 100644 index ef84527..0000000 --- a/lua/down/mod/edit/find/init.lua +++ /dev/null @@ -1,49 +0,0 @@ -local uv = vim.uv -local e = vim.lpeg - -local d = require("down") -local lib, mod = d.lib, d.mod - -local M = mod.create("edit.find") - -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 = { - "workspace", - }, - } -end - ----@class down.edit.find.Data -M.data = {} - ----@class down.edit.find.Config -M.config = {} -M.events = {} - -M.subscribed = { - cmd = { - ["edit.find.insert"] = true, - ["edit.find.update"] = true, - }, -} - -return M diff --git a/lua/down/mod/edit/init.lua b/lua/down/mod/edit/init.lua index c9219fc..2759bb5 100644 --- a/lua/down/mod/edit/init.lua +++ b/lua/down/mod/edit/init.lua @@ -1,22 +1,20 @@ -local M = require("down.mod").create("edit", { - "toc", - "parse", - "find", - "todo", +local M = require('down.mod').create('edit', { + 'toc', + 'task', -- "fold", -- "inline", -- "syntax", - "cursor", - "indent", - "link", + 'cursor', + 'indent', + 'link', }) -local down = require("down") +local down = require('down') local config, lib, log, mod = down.cfg, down.lib, down.log, down.mod M.setup = function() return { loaded = true, - requires = { "edit.link" }, + requires = { 'edit.link' }, } end @@ -25,7 +23,7 @@ M.config = { wrap = false, continue = true, ---@type boolean | nil context = 0, - jump_patterns = { "%[.*%]%(.-%)" }, + jump_patterns = { '%[.*%]%(.-%)' }, } M.data = {} @@ -33,7 +31,7 @@ M.data = {} M.data.find_patterns = function(str, patterns, reverse, init) reverse = reverse or false -- If the patterns arg is a string, add it to a table - patterns = type(patterns) == "table" and patterns or { patterns } + patterns = type(patterns) == 'table' and patterns or { patterns } -- Truncate the string if we're doing a reverse search str = (reverse and init and string.sub(str, 1, init)) or str local left, right, left_tmp, right_tmp @@ -53,10 +51,7 @@ M.data.find_patterns = function(str, patterns, reverse, init) -- If we've found a closer match amongst the provided patterns, use that instead -- (NOTE: 'closer' means closer to the beginning of the string if we're doing a forward -- search and closer to the end of the string if we're doing a reverse search) - if - left_tmp - and (left == nil or ((reverse and left_tmp > left) or left_tmp < left)) - then + if left_tmp and (left == nil or ((reverse and left_tmp > left) or left_tmp < left)) then left, right = left_tmp, right_tmp end end @@ -79,8 +74,7 @@ M.data.jump = function(pattern, reverse) line_len = #line if M.config.context > 0 and line_len > 0 then for i = 1, M.config.context, 1 do - local following_line = - vim.api.nvim_buf_get_lines(0, row, row + 1, false)[1] + local following_line = vim.api.nvim_buf_get_lines(0, row, row + 1, false)[1] line = (following_line and line .. following_line) or line end end @@ -101,12 +95,7 @@ M.data.jump = function(pattern, reverse) continue = false else -- If it isn't, search after the end of the previous match (before if reverse). -- These values will be used on the next iteration of the loop. - left, right = M.data.find_patterns( - line, - pattern, - reverse, - reverse and left or right - ) + left, right = M.data.find_patterns(line, pattern, reverse, reverse and left or right) end else -- If there's not a match on the current line, keep checking line-by-line -- Update row to search next line @@ -119,8 +108,7 @@ M.data.jump = function(pattern, reverse) col = reverse and line_len or -1 if line and M.config.context > 0 and line_len > 0 then for i = 1, M.config.context, 1 do - local following_line = - vim.api.nvim_buf_get_lines(0, row, row + 1, false)[1] + local following_line = vim.api.nvim_buf_get_lines(0, row, row + 1, false)[1] line = (following_line and line .. following_line) or line end end @@ -155,18 +143,17 @@ M.data.go_to_heading = function(anchor_text, reverse) local in_fenced_code_block = utils.cursorInCodeBlock(starting_row, reverse) local row = (reverse and starting_row - 1) or starting_row + 1 while continue do - local line = ( - reverse and vim.api.nvim_buf_get_lines(0, row - 1, row, false) - ) or vim.api.nvim_buf_get_lines(0, row - 1, row, false) + local line = (reverse and vim.api.nvim_buf_get_lines(0, row - 1, row, false)) + or vim.api.nvim_buf_get_lines(0, row - 1, row, false) -- If the line has contents, do the thing if line[1] then -- Are we in a code block? - if string.find(line[1], "^```") then + if string.find(line[1], '^```') then -- Flip the truth value in_fenced_code_block = not in_fenced_code_block end -- Does the line start with a hash? - local has_heading = string.find(line[1], "^#") + local has_heading = string.find(line[1], '^#') if has_heading and not in_fenced_code_block then if anchor_text == nil then -- Send the cursor to the heading @@ -174,11 +161,10 @@ M.data.go_to_heading = function(anchor_text, reverse) continue = false else -- Format current heading to see if it matches our search term - local heading_as_anchor = - M.required["link"].formatLink(line[1], nil, 2) + local heading_as_anchor = M.required['link'].formatLink(line[1], nil, 2) if anchor_text == heading_as_anchor then -- Set a mark - vim.api.nvim_buf_set_mark(0, "`", position[1], position[2], {}) + vim.api.nvim_buf_set_mark(0, '`', position[1], position[2], {}) -- Send the cursor to the row w/ the matching heading vim.api.nvim_win_set_cursor(0, { row, 0 }) continue = false @@ -191,14 +177,12 @@ M.data.go_to_heading = function(anchor_text, reverse) if anchor_text == nil then local message = "⬇️ Couldn't find a heading to go to!" if not M.config.silent then - vim.api.nvim_echo({ { message, "WarningMsg" } }, true, {}) + vim.api.nvim_echo({ { message, 'WarningMsg' } }, true, {}) end else - local message = "⬇️ Couldn't find a heading matching " - .. anchor_text - .. "!" + local message = "⬇️ Couldn't find a heading matching " .. anchor_text .. '!' if not M.config.silent then - vim.api.nvim_echo({ { message, "WarningMsg" } }, true, {}) + vim.api.nvim_echo({ { message, 'WarningMsg' } }, true, {}) end end end @@ -209,15 +193,15 @@ M.data.go_to_heading = function(anchor_text, reverse) in_fenced_code_block = false else M.config.continue = nil - local place = (reverse and "beginning") or "end" - local preposition = (reverse and "after") or "before" - local message = "⬇️ There are no more headings " + local place = (reverse and 'beginning') or 'end' + local preposition = (reverse and 'after') or 'before' + local message = '⬇️ There are no more headings ' .. preposition - .. " the " + .. ' the ' .. place - .. " of the document!" + .. ' of the document!' if not silent then - vim.api.nvim_echo({ { message, "WarningMsg" } }, true, {}) + vim.api.nvim_echo({ { message, 'WarningMsg' } }, true, {}) end end end @@ -231,24 +215,22 @@ M.data.go_to_id = function(id, starting_row) local start, finish while continue and row <= line_count do local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false)[1] - start, finish = line:find("%b[]%b{}") + start, finish = line:find('%b[]%b{}') -- Look for Pandoc-style ID attributes in headings if a bracketed span wasn't found if not start and not finish then - start, finish = line:find("%s*#+.*%b{}%s*$") + start, finish = line:find('%s*#+.*%b{}%s*$') end if start then local substring = string.sub(line, start, finish) - if substring:match("{[^%}]*" .. utils.luaEscape(id) .. "[^%}]*}") then + if substring:match('{[^%}]*' .. utils.luaEscape(id) .. '[^%}]*}') then continue = false else local continue_line = true while continue_line do - start, finish = line:find("%b[]%b{}", finish) + start, finish = line:find('%b[]%b{}', finish) if start then substring = string.sub(line, start, finish) - if - substring:match("{[^%}]*" .. utils.luaEscape(id) .. "[^%}]*}") - then + if substring:match('{[^%}]*' .. utils.luaEscape(id) .. '[^%}]*}') then continue_line = false continue = false end @@ -279,20 +261,20 @@ M.data.changeHeadingLevel = function(change) local row = vim.api.nvim_win_get_cursor(0)[1] local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false) -- See if the line starts with a hash - local is_heading = string.find(line[1], "^#") + local is_heading = string.find(line[1], '^#') if is_heading then - if change == "decrease" then + if change == 'decrease' then -- Add a hash - vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 0, { "#" }) + vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 0, { '#' }) else -- Remove a hash, but only if there's more than one - if not string.find(line[1], "^##") then + if not string.find(line[1], '^##') then local message = "⬇️ Can't increase this heading any more!" if not M.config.silent then - vim.api.nvim_echo({ { message, "WarningMsg" } }, true, {}) + vim.api.nvim_echo({ { message, 'WarningMsg' } }, true, {}) end else - vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 1, { "" }) + vim.api.nvim_buf_set_text(0, row - 1, 0, row - 1, 1, { '' }) end end end @@ -338,7 +320,7 @@ M.data.yankAsAnchorLink = function(full_path) local row = vim.api.nvim_win_get_cursor(0)[1] local line = vim.api.nvim_buf_get_lines(0, row - 1, row, false) -- See if the line starts with a hash - local is_heading = string.find(line[1], "^#") + local is_heading = string.find(line[1], '^#') local is_bracketed_span = M.required.link.getBracketedSpanPart() if is_heading then -- Format the line as an anchor link @@ -347,8 +329,8 @@ M.data.yankAsAnchorLink = function(full_path) if full_path then -- Get the full buffer name and insert it before the hash local buffer = vim.api.nvim_buf_get_name(0) - local left = anchor_link:match("(%b[]%()#") - local right = anchor_link:match("%b[]%((#.*)$") + local left = anchor_link:match('(%b[]%()#') + local right = anchor_link:match('%b[]%((#.*)$') anchor_link = left .. buffer .. right vim.cmd('let @"="' .. anchor_link .. '"') else @@ -356,23 +338,22 @@ M.data.yankAsAnchorLink = function(full_path) vim.cmd('let @"="' .. anchor_link .. '"') end elseif is_bracketed_span then - local name = M.required.link.getBracketedSpanPart("text") + local name = M.required.link.getBracketedSpanPart('text') local attr = is_bracketed_span local anchor_link if name and attr then if full_path then local buffer = vim.api.nvim_buf_get_name(0) - anchor_link = "[" .. name .. "]" .. "(" .. buffer .. attr .. ")" + anchor_link = '[' .. name .. ']' .. '(' .. buffer .. attr .. ')' else - anchor_link = "[" .. name .. "]" .. "(" .. attr .. ")" + anchor_link = '[' .. name .. ']' .. '(' .. attr .. ')' end vim.cmd('let @"="' .. anchor_link .. '"') end else - local message = - "⬇️ The current line is not a heading or bracketed span!" + local message = '⬇️ The current line is not a heading or bracketed span!' if not M.config.silent then - vim.api.nvim_echo({ { message, "WarningMsg" } }, true, {}) + vim.api.nvim_echo({ { message, 'WarningMsg' } }, true, {}) end end end diff --git a/lua/down/mod/edit/parse/README.md b/lua/down/mod/edit/parse/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/parse/datetime/README.md b/lua/down/mod/edit/parse/datetime/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/parse/datetime/init.lua b/lua/down/mod/edit/parse/datetime/init.lua deleted file mode 100644 index 1323f3e..0000000 --- a/lua/down/mod/edit/parse/datetime/init.lua +++ /dev/null @@ -1,25 +0,0 @@ -local M = Mod.create("edit.parse.datetime") - -local l = vim.lpeg - -M.setup = function() - return { - loaded = true, - } -end - ----@class down.edit.parse.datetime.Config -M.config = {} ----@class down.edit.parse.datetime.Data ----@field date parse.datetime.Date ----@field grammar parse.datetime.Grammar ----@field time parse.datetime.Time -M.data = {} ----@class (exact) parse.datetime.Grammar -M.data.grammar = {} ----@class (exact) parse.datetime.Time -M.data.time = {} ----@class (exact) parse.datetime.Date -M.data.date = {} - -return M diff --git a/lua/down/mod/edit/parse/heading/README.md b/lua/down/mod/edit/parse/heading/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/parse/heading/init.lua b/lua/down/mod/edit/parse/heading/init.lua deleted file mode 100644 index 2f732ee..0000000 --- a/lua/down/mod/edit/parse/heading/init.lua +++ /dev/null @@ -1,20 +0,0 @@ -local M = Mod.create("edit.parse.heading") - -local l = vim.lpeg - ----@class down.edit.parse.heading.Config -M.config = {} - ----@class down.edit.parse.heading.Data ----@field heading parse.heading.Heading -M.data = {} ----@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 -M.data.heading = { - level = 1, - isTitle = true, - content = "", -} -return M diff --git a/lua/down/mod/edit/parse/init.lua b/lua/down/mod/edit/parse/init.lua deleted file mode 100644 index 6bb5b26..0000000 --- a/lua/down/mod/edit/parse/init.lua +++ /dev/null @@ -1,38 +0,0 @@ ----@type down.mod -local P = Mod.create("edit.parse", { "scan", "datetime", "heading" }) - -local p = vim.lpeg -local R, V, S, C, Cc, Ct = p.R, p.V, p.S, p.C, p.Cc, p.Ct - ----@class down.edit.parse.Config -P.config = {} - ----@class down.edit.parse.Data -P.data = { - header_html = function(n) - pre = string.rep("#", n) - return P(pre) - * ( - ((1 - V("NL")) ^ 0) - / function(str) - return string.format("%s", n, str, n) - end - ) - end, -} - -P.setup = function() - return { - loaded = true, - requires = { - "tool.treesitter", - }, - } -end - -P.maps = function() end - --- local P, R, S, C, V = p.P, p.R, p.S, p.C, p.V -local Cc, Ct = p.Cc, p.Ct - -return P diff --git a/lua/down/mod/edit/parse/link/README.md b/lua/down/mod/edit/parse/link/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/parse/link/init.lua b/lua/down/mod/edit/parse/link/init.lua deleted file mode 100644 index 0ca9242..0000000 --- a/lua/down/mod/edit/parse/link/init.lua +++ /dev/null @@ -1,14 +0,0 @@ -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/README.md b/lua/down/mod/edit/parse/scan/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/parse/scan/init.lua b/lua/down/mod/edit/parse/scan/init.lua deleted file mode 100644 index 77aea72..0000000 --- a/lua/down/mod/edit/parse/scan/init.lua +++ /dev/null @@ -1,15 +0,0 @@ -local M = Mod.create("edit.parse.scan") - -M.setup = function() - return { - loaded = true, - } -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/README.md b/lua/down/mod/edit/parse/tag/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/lua/down/mod/edit/parse/tag/init.lua b/lua/down/mod/edit/parse/tag/init.lua deleted file mode 100644 index 2c18c92..0000000 --- a/lua/down/mod/edit/parse/tag/init.lua +++ /dev/null @@ -1,15 +0,0 @@ -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/todo/README.md b/lua/down/mod/edit/todo/README.md deleted file mode 100644 index d68b491..0000000 --- a/lua/down/mod/edit/todo/README.md +++ /dev/null @@ -1 +0,0 @@ -# `edit.todo` diff --git a/lua/down/mod/edit/todo/init.lua b/lua/down/mod/edit/todo/init.lua deleted file mode 100644 index bc87266..0000000 --- a/lua/down/mod/edit/todo/init.lua +++ /dev/null @@ -1,464 +0,0 @@ -local down = require("down") -local log, mod = down.log, down.mod - -local M = mod.create("edit.todo") - -M.setup = function() - return { loaded = true, requires = { "tool.treesitter" } } -end - -M.load = function() - for _, task in ipairs({ - "done", - "undone", - "pending", - "on-hold", - "cancelled", - "important", - "recurring", - "ambiguous", - "cycle", - "cycle-reverse", - }) do - vim.keymap.set( - "", - string.format("(down.insert.todo.todo.task-%s)", task), - M.data["task-" .. task] - ) - 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" }, - { "pending", "-" }, - }, - - -- The default order of TODO item cycling when the item - -- has nested children with TODO items. - -- - -- When cycling through TODO items with children it's not - -- always sensible to follow the same schema as the `order` table. - -- - -- Defaults to the following order: `undone`, `done`. - order_with_children = { - { "undone", " " }, - { "done", "x" }, - }, - - -- When set to `true`, will automatically convert parent - -- items to TODOs whenever a child item's TODO state is updated. - -- - -- For instance, given the following example: - -- ```markdown - -- - Text - -- -- ( ) Child text - -- ``` - -- - -- When this option is `true` and the child's state is updated to e.g. - -- `(x)` via the `td` keybind, the new output becomes: - -- ```markdown - -- - (x) Text - -- -- (x) Child text - -- ``` - create_todo_parents = false, - - -- When `true`, will automatically create a TODO extension for an item - -- if it does not exist and an operation is performed on that item. - -- - -- Given the following example: - -- ```markdown - -- - Test Item - -- ``` - -- With this option set to true, performing an operation (like pressing `` - -- or what have you) will convert the non-todo item into one: - -- ```markdown - -- - ( ) Test Item - -- ``` - create_todos = true, -} - ----@alias TodoItemType "undone" ----|"pending" ----|"done" ----|"cancelled" ----|"recurring" ----|"on_hold" ----|"urgent" ----|"uncertain" - -data = {} - -local function task_set(character, name) - return down.utils.wrap_dotrepeat(function() - local buffer = vim.api.nvim_get_current_buf() - local cursor = vim.api.nvim_win_get_cursor(0) - - local todo_at_cursor = - M.data.data.get_todo_from_cursor(buffer, cursor[1] - 1) - - if not todo_at_cursor then - return - end - - M.data.data.make_all(buffer, todo_at_cursor, name, character) - end) -end - -------@class down.edit.todo.Data -M.data = { - data = { - - --- Updates the parent todo item for the current todo item if it exists - ---@param recursion_level number the index of the parent to change. The higher the number the more the code will traverse up the syntax tree. - update_parent = function(buf, line, recursion_level) - -- Force a reparse (this is required because otherwise some cached nodes will be incorrect) - vim.treesitter.get_parser(buf, "markdown"):parse() - - -- If present grab the item that is under the cursor - local item_at_cursor = M.data.data.get_todo_from_cursor(buf, line) - - if not item_at_cursor then - return - end - - -- If we set a recursion level then go through and traverse up the syntax tree `recursion_level` times - for _ = 0, recursion_level do - item_at_cursor = item_at_cursor:parent() ---@diagnostic disable-line -- TODO: type error workaround - end - - -- 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") - then - return - end - - local counts = { - undone = 0, - pending = 0, - done = 0, - cancelled = 0, - recurring = 0, - on_hold = 0, - urgent = 0, - uncertain = 0, - } - - local counter = 0 - - -- 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" - then - for status in node:named_child(1):iter_children() do - if status:type():match("^todo_") then - local type = status:type():match("^todo_(.+)$") - - counts[type] = counts[type] + 1 - - if type == "cancelled" then - break - end - - counter = counter + 1 - end - end - end - end - - -- [[ - -- Compare the counter to the amount of done items. - -- If we have even one pending item then set the resulting char to `*` - -- If the counter is the same as the done item count then that means all items are complete and we should display a done item in the parent. - -- If the done item count is 0 then no task has been completed and we should set an undone item as the parent. - -- If all other checks fail and the done item count is less than the total number of todo items then set a pending item. - -- ]] - - if counter == 0 then - return - end - - local resulting_char = "" - - 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 - then - resulting_char = "=" - elseif counts.pending > 0 then - resulting_char = "-" - elseif counter == counts.done then - resulting_char = "x" - elseif counts.done == 0 then - resulting_char = " " - elseif counts.done < counter then - resulting_char = "-" - end - - local first_status_extension = - 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: - -- * (@ Mon 5th Feb) Test - -- ** ( ) Test - -- To this: - -- * (x|@ Mon 5th Feb) Test - -- ** (x) Test - if not first_status_extension then - if not M.config.create_todo_parents then - return - end - - local row, _, _, column = item_at_cursor:named_child(0):range() - - vim.api.nvim_buf_set_text( - buf, - row, - column, - row, - column, - { "(" .. resulting_char .. ") " } - ) - - M.data.data.update_parent(buf, line, recursion_level + 1) - return - end - - local range = M.required["tool.treesitter"].get_node_range( - first_status_extension - ) - - -- Replace the line where the todo item is situated - vim.api.nvim_buf_set_text( - buf, - range.row_start, - range.column_start, - range.row_end, - range.column_end, - { resulting_char } - ) - - M.data.data.update_parent(buf, line, recursion_level + 1) - end, - - -- modifier extension node. - ---@param detached_modifier_extension_node userdata #A valid node of type `detached_modifier_extension` - find_first_status_extension = function(detached_modifier_extension_node) - if not detached_modifier_extension_node then - return - end - - for status in detached_modifier_extension_node:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround - if vim.startswith(status:type(), "todo_") then - return status - end - end - end, - - --- Tries to locate a todo node under the cursor - ---@return userdata? #The node if it was located, else nil - get_todo_from_cursor = function(buf, line) - local node_at_cursor = - M.required["tool.treesitter"].get_first_node_on_line(buf, line) - - if not node_at_cursor then - return - end - - -- This is done because sometimes the first node can be - -- e.g `generic_list`, which only contains the top level list items and - -- not their data. It doesn't cost us much to do this operation for other - -- nodes anyway. - if node_at_cursor:named_child(0) then - node_at_cursor = node_at_cursor:named_child(0) - end - - while true do - if not node_at_cursor then - log.trace("Could not find TODO item under cursor, aborting...") - return - end - - local first_named_child = node_at_cursor:named_child(0) - - if first_named_child and first_named_child:type():match("prefix") then - break - else - node_at_cursor = node_at_cursor:parent() - end - end - - return node_at_cursor - end, - - --- Returns the type of a todo item (either "done", "pending" or "undone") - ---@param todo_node userdata #The todo node to extract the data from - ---@return TodoItemType? #A todo item type as a string, else nil - get_todo_type = function(todo_node) - if not todo_node or not todo_node:named_child(1) then ---@diagnostic disable-line -- TODO: type error workaround - return - end - - local todo_type = - 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, - - --- Converts the current node and all its children to a certain type - ---@param buf number the current buffer number - ---@param node userdata the node to modify - ---@param todo_type TodoItemType #The todo item type as a string - ---@param char string the character to place within the square brackets of the todo item (one of "x", "*" or " ") - make_all = function(buf, node, todo_type, char) - if not node then - return - end - - local type = node:type():match("^(.+)%d+$") ---@diagnostic disable-line -- TODO: type error workaround - - -- If the type of the current todo item differs from the one we want to change to then - -- We do this because we don't want to be unnecessarily modifying a line that doesn't need changing - if M.data.data.get_todo_type(node) == todo_type then - return - end - - local first_status_extension = - 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 - return - end - - local row, _, _, column = node:named_child(0):range() ---@diagnostic disable-line -- TODO: type error workaround - - vim.api.nvim_buf_set_text( - buf, - row, - column, - row, - column, - { "(" .. char .. ") " } - ) - else - local range = M.required["tool.treesitter"].get_node_range( - first_status_extension - ) - - vim.api.nvim_buf_set_text( - buf, - range.row_start, - range.column_start, - range.row_end, - range.column_end, - { char } - ) - end - - for child in node:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround - if type == child:type():match("^(.+)%d+$") then - M.data.data.make_all(buf, child, todo_type, char) - end - end - end, - - task_cycle = function(buf, linenr, types, alternative_types) - local todo_at_cursor = M.data.data.get_todo_from_cursor(buf, linenr - 1) - - if not todo_at_cursor then - return - end - - local todo_type = M.data.data.get_todo_type(todo_at_cursor) - - --- Gets the next item of a flat list based on the first item - ---@param type_list table[] #A list of { "type", "char" } items - ---@param item_type string #The `type` field from the `type_list` array - ---@return number? #An index into the next item of `type_list` - local function index(type_list, item_type) - for i, element in ipairs(type_list) do - if element[1] == item_type then - if i >= #type_list then - return 1 - else - return i + 1 - end - end - end - end - - if not todo_type then - if not M.config.create_todos then - return - end - - M.data.data.make_all(buf, todo_at_cursor, types[1][1], types[1][2]) - M.data.data.update_parent(buf, linenr - 1, 0) - return - end - - local index = index(types, todo_type) - - local next = types[index] or types[1] - - for child in todo_at_cursor:iter_children() do - if M.data.data.get_todo_type(child) then - next = alternative_types[index(alternative_types, todo_type)] - or alternative_types[1] - break - end - end - - M.data.data.make_all(buf, todo_at_cursor, next[1], next[2]) - M.data.data.update_parent(buf, linenr - 1, 0) - end, - }, - ["task-done"] = task_set("x", "done"), - ["task-undone"] = task_set(" ", "undone"), - ["task-pending"] = task_set("-", "pending"), - ["task-on-hold"] = task_set("=", "on_hold"), - ["task-cancelled"] = task_set("_", "cancelled"), - ["task-important"] = task_set("!", "important"), - ["task-recurring"] = task_set("+", "recurring"), - ["task-ambiguous"] = task_set("?", "ambiguous"), - ["task-cycle"] = function() - local buffer = vim.api.nvim_get_current_buf() - local cursor = vim.api.nvim_win_get_cursor(0) - - M.data.data.task_cycle( - buffer, - cursor[1], - M.config.order, - M.config.order_with_children - ) - end, - ["task-cycle-reverse"] = function() - local buffer = vim.api.nvim_get_current_buf() - local cursor = vim.api.nvim_win_get_cursor(0) - - M.data.data.task_cycle( - buffer, - cursor[1], - vim.fn.reverse(M.config.order), - vim.fn.reverse(M.config.order_with_children) - ) - end, -} - -return M diff --git a/lua/down/mod/lsp/init.lua b/lua/down/mod/lsp/init.lua index 9e01e67..ab57f76 100644 --- a/lua/down/mod/lsp/init.lua +++ b/lua/down/mod/lsp/init.lua @@ -22,7 +22,9 @@ local M = mod.create("lsp", { "completion", }) + M.opts = function() end + M.maps = function() local bufnr = require("down.util.buf").buf() local bufopts = { noremap = true, silent = true, buffer = bufnr } diff --git a/lua/down/mod/workspace/util.lua b/lua/down/mod/workspace/util.lua index 7d00e36..7290535 100644 --- a/lua/down/mod/workspace/util.lua +++ b/lua/down/mod/workspace/util.lua @@ -1,5 +1,27 @@ local W = {} +---@return down.Workspace +W.init = function() + local pwd = vim.fn.getcwd() + ---@type down.Workspace + return { + id = pwd, + config = { + init = { + }, + rc = pwd .. "rc.down", + dataDir = pwd .. ".down/" + + + }, + uri = "file:", + + name = pwd, + + } +end + + W.spl = function() return end diff --git a/lua/down/types.lua b/lua/down/types.lua deleted file mode 100644 index 6970f56..0000000 --- a/lua/down/types.lua +++ /dev/null @@ -1,193 +0,0 @@ ----@meta ---- ---- @alias down.mod.Data { [any]: any } - ---- @class down.mod.Mods ---- @field ['lsp.document']? lsp.document.Data ---- @field ['lsp.workspace']? lsp.workspace.Data ---- @field ['lsp.completion']? lsp.completion.Data ---- @field ['lsp.actions']? lsp.actions.Data ---- @field ['lsp.command']? lsp.command.Data ---- @field ['lsp.hint']? lsp.hint.Data ---- @field ['lsp.hover']? lsp.hover.Data ---- @field ['lsp.lens']? lsp.lens.Data ---- @field lsp? lsp.Data ---- @field ['lsp.window']? lsp.window.Data ---- @field ['lsp.semantic']? lsp.semantic.Data ---- @field ["edit.conceal"]? edit.conceal.Data ---- @field ["ui.icon"]? ui.icon.Data ---- @field workspace? workspace.Data ---- @field ["edit.fold"]? edit.fold.Data ---- @field ["edit.hl"]? edit.hl.Data ---- @field ["ui.win"]? ui.win.Data ---- @field note? note.Data ---- @field ['data.clipboard']? data.clipboard.Data ---- @field ['data.dirs']? data.dirs.Data ---- @field ['data.export']? data.export.Data ---- @field ['data.encrypt']? data.encrypt.Data ---- @field ['data.metadata']? data.metadata.Data ---- @field ['data.syntax']? data.syntax.Data ---- @field ['data.toc']? data.toc.Data ---- @field ['edit.parse']? edit.parse.Data ---- @field ['data.log']? data.log.Data ---- @field ['data.link']? data.link.Data ---- @field ['edit.link']? edit.link.Data ---- @field cmd? cmd.Data ---- @field ['data.tag']? data.tag.Data ---- @field ['data.sync']? data.sync.Data ---- @field ['data.mod']? data.mod.Data ---- @field ['data.code']? data.code.Data ---- @field ['data.todo']? data.todo.Data ---- @field ['edit.todo']? edit.todo.Data ---- @field ['edit.cursor']? edit.cursor.Data ---- @field ['edit.find']? down.edit.find.Data ---- @field ['edit.link']? down.edit.link.Data ---- @field ['edit.indent']? down.edit.indent.Data ---- @field ui? down.ui.Data ---- @field ['data.template']? down.data.template.Data ---- @field ["data.code.snippet"]? down.data.code.snippet.Data ---- @field ["data.code.run"]? down.data.code.run.Data ---- @field ["ui.calendar"]? down.ui.calendar.Data ---- @field ["ui.calendar.month"]? down.ui.calendar.month.Data ---- @field ["integration.treesitter"]? down.down.integration.treesitter.Data ---- @field ["integration.blink"]? down.integration.blink.Data ---- @field ["integration.cmp"]? down.integration.cmp.Data ---- @field ["integration.telescope"]? down.integration.telescope.Data ---- @field ["integration.lualine"]? down.integration.lualine.Data ---- @field ["integration.trouble"]? down.integration.trouble.Data ---- @field ["integration.fzf"]? down.integration.fzf.Data ---- @field ["ui.chat"]? down.ui.chat.Data ---- @field ["ui.sidebar"]? down.ui.sidebar.Data ---- @field ["ui.popup"]? down.ui.popup.Data ---- @field ["ui.status"]? down.ui.status.Data ---- @field ["ui.win"]? down.ui.win.Data - ---- Defines both a public and private config for a down init. ---- Public configs may be tweaked by the user from the `down.setup()` function, whereas private configs are for internal use only. ---- @alias down.mod.Config table - ---- @class down.mod.Events ---- @field defined? { [string]: down.Event } Lists all events by this init. ---- @field subscribed? { [string]: { [string]: boolean } } Lists the events that the init is subscribed to. - ---- @alias down.mod.Setup { loaded: boolean, requires?: string[], replaces?: string, merge?: boolean, wants?: string[] } - ---- Defines a init. ---- A init is an object that contains a set of hooks which are invoked by down whenever something in the ---- environment occurs. This can be an event, a simple act of the init being loaded or anything else. ---- @class down.Mod ---- @field hook? fun(manual: boolean, arguments?: string) A user-defined function that is invoked whenever down starts up. May be used to e.g. set custom keybindings. ---- @field config? down.mod.Config The config for the init. ---- @field events? down.mod.Events Describes all information related to events for this init. ---- @field import? table Imported submod of the given init. Contrary to `required`, which only exposes the public API of a init, imported mod can be accessed in their entirety. ---- @field cmds? fun() Function that adds all the commands for the init. ---- @field opts? fun() Function that adds all the options for the init. ---- @field maps? fun() Function that adds all the mappings for the init. ---- @field load? fun() Function that is invoked once the init is considered "stable", i.e. after all dependencies are loaded. Perform your main loading routine here. ---- @field test? fun() Function that is invoked when the init is being tested. ---- @field bench? fun() Function that is invoked when the init is being benchmarked. ---- @field name string The name of the init. ---- @field namespace string The name of the init. ---- @field post_load? fun() Function that is invoked after all mod are loaded. Useful if you want the down environment to be fully set up before performing some task. ---- @field path string The full path to the init (a more verbose version of `name`). Moday be used in lua's `require()` statements. ---- @field public data? down.mod.Data Every init can expose any set of information it sees fit through this field. All functions and variables declared in this table will be to any other init loaded. ---- @field required? down.mod.Mods Contains the public tables of all mod that were required via the `requires` array provided in the `setup()` function of this init. ---- @field setup? fun(): down.mod.Setup? Function that is invoked before any other loading occurs. Should perform preliminary startup tasks. ---- @field replaced? boolean If `true`, this means the init is a replacement for a base init. This flag is set automatically whenever `setup().replaces` is set to a value. ---- @field on fun(event: down.Event) A callback that is invoked any time an event the init has subscribed to has fired. ---- Returns a new down init, exposing all the necessary function and variables. ---- @return down.Mod ---- ---- ---- @alias OperatingSystem ---- | "windows" ---- | "wsl" ---- | "wsl2" ---- | "mac" ---- | "linux" ---- | "bsd" ---- TODO: make down.config.UserMod? table ---- @alias down.config.UserMod { config?: table } - ---- @class (exact) down.config.Ft ---- @field md boolean ---- @field mdx boolean ---- @field markdown boolean ---- @field down boolean - ---- @class (exact) down.Config ---- @field args table A list of arguments provided to the `:downStart` function in the form of `key=value` pairs. Only applicable when `user_config.lazy_loading` is `true`. ---- @field manual boolean? Used if down was manually loaded via `:downStart`. Only applicable when `user_config.lazy_loading` is `true`. ---- @field mod table Acts as a copy of the user's config that may be modified at runtime. ---- @field os OperatingSystem The operating system that down is currently running under. ---- @field pathsep "\\"|"/" The operating system that down is currently running under. ---- @field started boolean Set to `true` when down is fully initialized. ---- @field user down.config.User Stores the config provided by the user. ---- @field version string The version of down that is currently active. Automatically updated by CI on every release. - ---- Stores the config for the entirety of down. ---- This includes not only the user config (passed to `setup()`), but also internal ---- variables that describe something specific about the user's hardware. ---- @see down.Setup ---- ---- ---- @alias Mode ---- | "n" ---- | "no" ---- | "nov" ---- | "noV" ---- | "noCTRL-V" ---- | "CTRL-V" ---- | "niI" ---- | "niR" ---- | "niV" ---- | "nt" ---- | "Terminal" ---- | "ntT" ---- | "v" ---- | "vs" ---- | "V" ---- | "Vs" ---- | "CTRL-V" ---- | "CTRL-Vs" ---- | "s" ---- | "S" ---- | "CTRL-S" ---- | "i" ---- | "ic" ---- | "ix" ---- | "R" ---- | "Rc" ---- | "Rx" ---- | "Rv" ---- | "Rvc" ---- | "Rvx" ---- | "c" ---- | "cr" ---- | "cv" ---- | "cvr" ---- | "r" ---- | "rm" ---- | "r?" ---- | "!" ---- | "t" - ---- @class (exact) down.Event ---- @field type string The type of the event. Exists in the format of `category.name`. ---- @field split_type string[] The event type, just split on every `.` character, e.g. `{ "category", "name" }`. ---- @field content? table|any The content of the event. The data found here is specific to each individual event. Can be thought of as the payload. ---- @field referrer string The name of the init that triggered the event. ---- @field broadcast boolean Whether the event was broadcast to all mod. `true` is so, `false` if the event was specifically sent to a single recipient. ---- @field cursor_position { [1]: number, [2]: number } The position of the cursor at the moment of broadcasting the event. ---- @field filename string The name of the file that the user was in at the moment of broadcasting the event. ---- @field filehead string The directory the user was in at the moment of broadcasting the event. ---- @field line_content string The content of the line the user was editing at the moment of broadcasting the event. ---- @field buffer number The buffer ID of the buffer the user was in at the moment of broadcasting the event. ---- @field window number The window ID of the window the user was in at the moment of broadcasting the event. ---- @field mode Mode The mode Neovim was in at the moment of broadcasting the event. ---- ---- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---- ---- @brief down ---- @see down ---- diff --git a/lua/down/types/config.lua b/lua/down/types/config.lua new file mode 100644 index 0000000..26956f1 --- /dev/null +++ b/lua/down/types/config.lua @@ -0,0 +1,62 @@ +--- @meta down.types.config +--- @brief Provides core data types +--- @version <5.2,JIT +--- +--- @brief down.config +--- +--- The local config for setting up workspaces. +--- @class (exact) down.config.Local workspace config local +--- @field public dir? down.Uri"./.down/" by default +--- @field public init? down.config.Init, optional init +--- metadata?: { [string]?: any }, +--- +--- Configuration for base directories globally. +--- @class (exact) down.config.Dirs dirs +--- @field public home down.Dir default "~/.down/" +--- @field public config down.Dir default "~/.config/down/" +--- @field public cache down.Dir default "~/.cache/down/" +--- @field public temp down.Dir default "~/.temp/down/" +--- @field public runtime down.Dir string default "~/.down/runtime/" +--- @field public log down.Dir string default "~/.down/log/" +--- +--- Configuration for global settings. +--- @class (exact) down.config.Global: down.Workspaces Down global configuration +--- @field public user down.User used +--- @field public dirs down.config.Dirs dirs +--- @field public workspaces down.Workspace> workspace list +--- @field public mod table mod list +--- @field public config down.Config config +--- @field public [string]? down.Mod modules +--- +--- @brief down.config.local +--- +--- @brief down.config.global +--- +--- @brief down.onfig.init +--- +--- The important store value object +--- @class (exact) down.config.Init Init +--- @field git? down.config.init.Git Git +--- @field sync? down.config.init.Sync sync +--- @field markdown? down.config.init.Markdown sync +--- @field command? down.config.init.Command command +--- @field [string]? down.config.init.Command +--- +--- The important store value object +--- @class (exact) down.config.init.Markdown Git init +--- @field public enabled boolean Enable +--- +--- The important store value object +--- @class (exact) down.config.init.Git Git init +--- @field public enabled boolean Enable +--- +--- The important store value object +--- @class (exact) down.config.init.Command command init +--- @field public enabled? boolean Enable +--- @field public command? string Enable +--- @field public args? string[] Enable +--- +--- The important store value object +--- @class (exact) down.config.init.Sync Sync init +--- @field public enabled boolean Enable +--- diff --git a/lua/down/types/context.lua b/lua/down/types/context.lua new file mode 100644 index 0000000..8711220 --- /dev/null +++ b/lua/down/types/context.lua @@ -0,0 +1,23 @@ +--- @meta down.types.context +--- +--- The position of a character aaagin a file. +--- @class (exact) down.Position: { line?: number, char?: number } position of a character in a file +--- +--- The position of a character aaagin a file. +--- @class (exact) down.Range: { start: down.Position,start: down.Position } position of a character in a file + +--- The context of an in-file object. +--- @class (exact) down.Context context of in-file object +--- @field public loc? down.Position location +--- @field public root? down.Id root node in file scope +--- @field public parent? down.Id parent node in file scope +--- @field public scope? down.Scope in file scope +--- +--- The scope of an entity. +--- @class (exact) down.Info +--- @field public id down.Id +--- @field public uri down.Uri +--- @field public context? down.Context +--- @field public metadata? { [string]: any } +--- @field public tags? { [string]: down.Tag } +--- diff --git a/lua/down/types/data.lua b/lua/down/types/data.lua new file mode 100644 index 0000000..cb634f2 --- /dev/null +++ b/lua/down/types/data.lua @@ -0,0 +1,20 @@ +--- @meta down.types.data +--- @brief Provides core data types +--- @version <5.2,JIT +--- +--- @brief down.data +--- +--- The important store value object +--- @class (exact) down.data.Map: { [K]?: V } # store data +--- +--- The important store value object +--- @class (exact) down.data.NestedMap: { [K1]?: { [K2]?: V } } # store data +--- +--- The important store value object +--- @class (exact) down.data.NestedTable: { [K1]: table } # store data +--- +--- The important store value object +--- @class (exact) down.data.Map: { [K]: V } # store data +--- +--- The important store value object +--- @class (exact) down.data.List: { [integer]: V } # store data diff --git a/lua/down/types/date.lua b/lua/down/types/date.lua new file mode 100644 index 0000000..0820b22 --- /dev/null +++ b/lua/down/types/date.lua @@ -0,0 +1,27 @@ +--- @meta down.types.date +--- +--- The time part of the datetime. +--- @class (exact) down.Time Time +--- @field public hour? integer|string Hours +--- @field public minute? integer|string Minutes +--- @field public second? integer|string Seconds +--- @field public fmt fun(t: down.Time, tf: string): string Format the time part of the datetime. +--- @field public time fun(t: down.Time): integer Get the time part of the datetime. +--- @field public params fun(t: down.Time): osdateparam Get the time part of the datetime. +--- +--- The datetime data structure. +--- @class (exact) down.Datetime +--- @field public date? down.Date The date part of the datetime. +--- @field public time? down.Time The time part of the datetime. +--- @field public params fun(t: down.Datetime): osdateparam Get the time part of the datetime. +--- @field public fmt fun(t: down.Datetime, f: string): string Format the time part of the datetime. +--- +--- The date part of the datetime. +--- @class (exact) down.Date +--- @field public day integer|string Hours +--- @field public week integer|string Minutes +--- @field public month integer|string Seconds +--- @field public year integer|string Seconds +--- @field public fmt fun(t: down.Date, tf: string|nil): string Format the time part of the datetime. +--- @field public date fun(t: down.Date): integer Get the time part of the datetime. +--- @field public params fun(t: down.Date, d: down.Time|nil): osdateparam Get the time part of the datetime. diff --git a/lua/down/types/entity.lua b/lua/down/types/entity.lua new file mode 100644 index 0000000..7a10104 --- /dev/null +++ b/lua/down/types/entity.lua @@ -0,0 +1,118 @@ +--- @meta down.types.workspcae +--- The context of an in-file object. +--- @class (exact) down.Log: { data?: { [string]: string } } +--- +--- The context of an in-file object. +--- @class (exact) down.Template: { +--- id: string, +--- uri: down.Uri, +--- context: down.Context, +--- body: string, +--- kind: string } Link +--- +--- The context of an in-file object. +--- @class (exact) down.Snippet: { +--- id: string, +--- uri: down.Uri, +--- context: down.Context, +--- body: string, +--- kind: string } Link +--- +--- The context of an in-file object. +--- @class (exact) down.Link: { +--- id: string, +--- uri: down.Uri, +--- context: down.Context, +--- target: down.Uri, +--- body: string, +--- kind: string } Link +--- +--- The context of an in-file object. +--- @class (exact) down.Anchor: { +--- id: string, +--- uri: down.Uri, +--- context: down.Context, +--- body: string, +--- kind: string } Link +--- +--- The context of an in-file object. +--- @class (exact) down.Note: { +--- id: string, +--- uri: down.Uri, +--- context: down.Context, +--- body: string, +--- kind: string } Link +--- +--- The context of an in-file object. +--- @class (exact) down.Agenda: { +--- id: string, +--- uri: down.Uri, +--- body: string, +--- groups: down.Group[], +--- tasks: down.Task[], +--- scope: down.Scope[], +--- kind: string } Link +--- +--- The tag object. +--- @class down.Tag: { id: string, context: down.Context, flags: down.Flag[] } tags +--- +--- @class down.TagsField: { tags: down.Tag[] } Has tags +--- +--- @alias down.Tags down.Tag[] Has tags +--- +--- @class (exact) Node: { index: I, edges: E[], weight: N } +--- +--- @class (exact) Edge: { [K1]: { [K2]: E } } +--- +--- The category object. +--- @class down.Category: { group?: string } +--- +--- The project object. +--- @class (exact) down.Group: { group?: string } +--- @field public name string +--- @field public data table +--- @field public agenda? down.Data +--- @field public info? down.Info +--- @field public tasks? down.Data +--- +--- The project object. +--- @class (exact) down.Project +--- @field public id down.Uri +--- @field public info? down.Info +--- @field public data table +--- @field public agenda? down.Data +--- @field public tasks? down.Data +--- +--- The scope of an entity. +--- @alias down.Flag { +--- flag: string, +--- info: down.Info, +--- data: table, +--- } +--- +--- +--- The important store value object +--- @class (exact) down.Log: { id: string, uri: down.Uri, config?: down.config.Local } +--- +--- The user object. +--- @class (exact) down.User User +--- @field public id down.Id uri +--- @field public home down.Uri home +--- @field public email? string uri +--- @field public username? string uri +--- +--- @class (exact) down.Entity: down.Base, { +--- tags?: down.Tag[], +--- info?: down.HasInfo, +--- context: down.Context, +--- } +--- +--- The scope of an entity. +--- @class (exact) down.Task +--- @field public name string +--- @field public info down.Info +--- @field public context down.Context +--- @field public store? down.Id +--- @field public status down.task.Status +--- @field public priority down.task.Priority +--- diff --git a/lua/down/types/enum.lua b/lua/down/types/enum.lua new file mode 100644 index 0000000..e0a54a9 --- /dev/null +++ b/lua/down/types/enum.lua @@ -0,0 +1,112 @@ +---@enum down.types.enum +--- +--- The scope of an entity. +--- @alias down.Mode +--- | "n" +--- | "no" +--- | "nov" +--- | "noV" +--- | "noCTRL-V" +--- | "CTRL-V" +--- | "niI" +--- | "niR" +--- | "niV" +--- | "nt" +--- | "Terminal" +--- | "ntT" +--- | "v" +--- | "vs" +--- | "V" +--- | "Vs" +--- | "CTRL-V" +--- | "CTRL-Vs" +--- | "s" +--- | "S" +--- | "CTRL-S" +--- | "i" +--- | "ic" +--- | "ix" +--- | "R" +--- | "Rc" +--- | "Rx" +--- | "Rv" +--- | "Rvc" +--- | "Rvx" +--- | "c" +--- | "cr" +--- | "cv" +--- | "cvr" +--- | "r" +--- | "rm" +--- | "r?" +--- | "!" +--- | "t" + +--- The scope of an entity. +--- @alias down.Status 'queued' status of a task +--- | 'waiting' Waiting +--- | 'finished' Finished +--- | 'cancelled' Cancelled +--- | 'pending' Pending, todo +--- | 'blocked' Blocked +--- +--- The scope of an entity. +--- @alias down.Scope +--- | "priority" +--- | "category" +--- | "group" +--- | "flag" +--- | "user" for entities in the same profile +--- | "tag" for shared tag entities +--- | "workspace" for all files in workspace +--- | "project" for entities in the same project +--- | "global" for all entities across workspaces and profiles +--- | "local" for this file only +--- | "dir" for this and other files in the same dir +--- | "children" for this file, all in same dir, and all children of dirs +--- | "dynamic" for entities in the same dynamic scope +--- | "other" for entities in other scopes +--- +--- +--- Operating system +--- @alias down.Os +--- | "windows" +--- | "wsl" +--- | "wsl2" +--- | "mac" +--- | "linux" +--- | "bsd" +--- +--- @alias down.dirs.Down +--- | { name: "home", uri: "~/.down" } +--- | { name: "config", uri: "~/.config/down" } +--- | { name: "data", uri: "~/.local/share/down"} +--- | { name: "cache", uri: "~/.local/share/down"} +--- | { name: "temp", uri: "/tmp/down"} +--- | { name: "log", uri: "~/.down/log"} +--- | { name: "lsp", uri: "~/.down/lsp"} +--- | { name: "workspace", uri: "~/.down/workspace"} +--- +--- The status of a task. +---@alias down.task.Status "done" +--- | "todo" +--- | "cancelled" +--- | "waiting" +--- | "blocked" +--- | "doing" +--- +--- The priority of a task. +--- @alias down.task.Priority "misc" +--- | "lowest" +--- | "low" +--- | "medium" +--- | "high" +--- | "highest" +--- +--- Ranking +--- @alias down.Ranking integer 0 +--- | 1 +--- | 2 +--- | 3 +--- | 4 +--- | 5 diff --git a/lua/down/types/event.lua b/lua/down/types/event.lua new file mode 100644 index 0000000..4b0af2f --- /dev/null +++ b/lua/down/types/event.lua @@ -0,0 +1 @@ +---@meta down.types.event diff --git a/lua/down/types/file.lua b/lua/down/types/file.lua new file mode 100644 index 0000000..c1eb2c8 --- /dev/null +++ b/lua/down/types/file.lua @@ -0,0 +1,14 @@ +---@meta data.types.file +--- +--- Uri is a string that represents a file path. +--- @alias down.Uri string Uri +--- +--- +--- The important store value object +--- @alias down.Id string +--- +--- The important store value object +--- @alias down.Dir down.Uri +--- +--- The important store value object +--- @alias down.File down.Uri diff --git a/lua/down/types/init.lua b/lua/down/types/init.lua new file mode 100644 index 0000000..fa5578a --- /dev/null +++ b/lua/down/types/init.lua @@ -0,0 +1,211 @@ +--- @meta down.types +--- @brief Provides core data types +--- @version <5.2,JIT +--- +--- +--- The important store value object +--- @class (exact) down.old.Store: { id: down.store.Name, uri: down.Uri, data?: down.store.Data } store +--- +--- [string]: down.Store +--- @class (exact) down.old.store.Map: { [down.store.Key]?: down.Store } Map { log1 = { i}} +--- +--- The important store value object +--- @class (exact) down.old.store.Kind: { [down.store.ItemKind]?: down.store.Map } +--- +--- +--- +--- The scope of an entity. +--- @class (exact) down.mod.Config.Lsp lsp +--- @field ['lsp.document']? down.lsp.document.Data lsp.document +--- @field ['lsp.workspace']? down.lsp.workspace.Data lsp.workspace +--- +--- @field ['lsp.completion']? down.lsp.completion.Data lsp.completion +--- +--- The entire mod configuration +--- @class (exact) down.mod.Config +--- @field public lsp? lsp.Config +--- + +--- The scope of an entity. +--- @class down.mod.Mods +--- @field ['lsp.document']? lsp.document.Data +--- @field ['lsp.workspace']? lsp.workspace.Data +--- @field ['lsp.completion']? lsp.completion.Data +--- @field ['lsp.actions']? lsp.actions.Data +--- @field ['lsp.command']? lsp.command.Data +--- @field ['lsp.hint']? lsp.hint.Data +--- @field ['data.task']? data.task.Data +--- @field ['data.store']? data.store.Data +--- @field ['data.task.agenda']? data.task.agenda.Data +--- @field ['data.log']? data.log.Data +--- @field ['lsp.hover']? lsp.hover.Data +--- @field ['lsp.lens']? lsp.lens.Data +--- @field lsp? lsp.Data +--- @field ['lsp.window']? lsp.window.Data +--- @field ['lsp.semantic']? lsp.semantic.Data +--- @field ["edit.conceal"]? edit.conceal.Data +--- @field ["ui.icon"]? ui.icon.Data +--- @field workspace? workspace.Data +--- @field ["edit.fold"]? edit.fold.Data +--- @field ["edit.hl"]? edit.hl.Data +--- @field ["ui.win"]? ui.win.Data +--- @field note? note.Data +--- @field ['data.clipboard']? data.clipboard.Data +--- @field ['data.dirs']? data.dirs.Data +--- @field ['data.export']? data.export.Data +--- @field ['data.encrypt']? data.encrypt.Data +--- @field ['data.metadata']? data.metadata.Data +--- @field ['data.syntax']? data.syntax.Data +--- @field ['data.toc']? data.toc.Data +--- @field ['edit.parse']? edit.parse.Data +--- @field ['data.log']? data.log.Data +--- @field ['data.link']? data.link.Data +--- @field ['edit.link']? edit.link.Data +--- @field cmd? cmd.Data +--- @field ['data.tag']? data.tag.Data +--- @field ['data.sync']? data.sync.Data +--- @field ['data.mod']? data.mod.Data +--- @field ['data.code']? data.code.Data +--- @field ['data.todo']? data.todo.Data +--- @field ['edit.todo']? edit.todo.Data +--- @field ['edit.cursor']? edit.cursor.Data +--- @field ['edit.find']? down.edit.find.Data +--- @field ['edit.link']? down.edit.link.Data +--- @field ['edit.indent']? down.edit.indent.Data +--- @field ui? down.ui.Data +--- @field media? down.data.media.Data media +--- @field ['data.template']? down.data.template.Data +--- @field ["data.code.snippet"]? down.data.code.snippet.Data +--- @field ["data.code.run"]? down.data.code.run.Data +--- @field ["ui.calendar"]? down.ui.calendar.Data +--- @field ["ui.calendar.month"]? down.ui.calendar.month.Data +--- @field ["integration.treesitter"]? down.down.integration.treesitter.Data +--- @field ["integration.blink"]? down.integration.blink.Data +--- @field ["integration.cmp"]? down.integration.cmp.Data +--- @field ["integration.telescope"]? down.integration.telescope.Data +--- @field ["integration.lualine"]? down.integration.lualine.Data +--- @field ["integration.trouble"]? down.integration.trouble.Data +--- @field ["integration.fzf"]? down.integration.fzf.Data +--- @field ["ui.chat"]? down.ui.chat.Data +--- @field ["ui.sidebar"]? down.ui.sidebar.Data +--- @field ["ui.popup"]? down.ui.popup.Data +--- @field ["ui.status"]? down.ui.status.Data +--- +--- down.Mods +--- @alias down.Mods down.mod.Mods +--- +--- @class (exact) down.mod.config.Config: table +--- @field [string]? { [string]?: any } +--- @field enabled? boolean +--- @alias down.mod.Config down.mod.Modconfig.Config +--- +--- TODO: merge data field to [string]? { [string]?: down.Event } +--- TODO: down.mod.Events.defined -> +--- TODO: #field [string]? { [string]?: down.Event } +--- +--- @class (exact) down.event.Subscribed +--- @field public [string]? { [string]: boolean } + +--- @class (exact) down.mod.Events +--- @field defined? { [string]: down.Event } Lists all events by this init. +--- @field subscribed? { [string]: { [string]: boolean } } Lists the events that the init is subscribed to. +--- @field public [string]? down.Event + +--- @class (exact) down.mod.Setup: { +--- [string]?: { [string]?: any }, +--- loaded: boolean, +--- requires?: string[], +--- replaces?: string, +--- merge?: boolean, +--- wants?: string[] } +--- @field public [string]? any +--- +--- @class (exact) down.mod.Config: { [string]?: any } +--- @field public [string]? any + +--- TODO: merge data field to [string]?: down.mod.Data +--- TODO: down.Mod.data -> +--- TODO: #field [string]? down.config.UserMod +--- TODO: down.Mod.config -> +--- TODO: #field config? down.mod.Config + +--- @class (exact) down.Mod +--- @field public [string]? down.mod.Data +--- @field hook? fun(manual: boolean, arguments?: string) A user-defined function that is invoked whenever down starts up. May be used to e.g. set custom keybindings. +--- @field config? down.mod.Config The config for the init. +--- @field events? down.mod.Events Describes all information related to events for this init. +--- @field import? table Imported submod of the given init. Contrary to `required`, which only exposes the public API of a init, imported mod can be accessed in their entirety. +--- @field cmds? fun() Function that adds all the commands for the init. +--- @field opts? fun() Function that adds all the options for the init. +--- @field maps? fun() Function that adds all the mappings for the init. +--- @field load? fun() Function that is invoked once the init is considered "stable", i.e. after all dependencies are loaded. Perform your main loading routine here. +--- @field test? fun() Function that is invoked when the init is being tested. +--- @field bench? fun() Function that is invoked when the init is being benchmarked. +--- @field name string The name of the init. +--- @field namespace string The name of the init. +--- @field post_load? fun() Function that is invoked after all mod are loaded. Useful if you want the down environment to be fully set up before performing some task. +--- @field path string The full path to the init (a more verbose version of `name`). Moday be used in lua's `require()` statements. +--- @field public data? down.mod.Data Every init can expose any set of information it sees fit through this field. All functions and variables declared in this table will be to any other init loaded. +--- @field required? down.mod.Mods Contains the public tables of all mod that were required via the `requires` array provided in the `setup()` function of this init. +--- @field setup? fun(): down.mod.Setup? Function that is invoked before any other loading occurs. Should perform preliminary startup tasks. +--- @field replaced? boolean If `true`, this means the init is a replacement for a base init. This flag is set automatically whenever `setup().replaces` is set to a value. +--- @field on fun(event: down.Event) A callback that is invoked any time an event the init has subscribed to has fired. +--- +--- @class (exact) down.config.Ft +--- @field md boolean +--- @field mdx boolean +--- @field markdown boolean +--- @field down boolean +--- +--- TODO: make down.config.User? table +--- TODO: down.config.config.User.mod.config -> +--- TODO: #field [string]? down.config.UserMod +--- +--- @class (exact) down.config.User +--- @field [string]? down.config.UserMod +--- @field mod down.config.UserMod +--- +--- TODO: make down.config.UserMod? table +--- TODO: down.config.UserMod.config -> +--- TODO: #field [string]? down.Mod +--- +--- @class (exact) down.config.UserMod { config?: table } +--- @field [string]? table +--- @field config? table + +--- TODO: make mod field merge to [string]: down.Mod +--- TODO: down.Config.mod -> +--- TODO: #field [string]? down.Mod +--- +--- @class (exact) down.Config +--- @field args table A list of arguments provided to the `:downStart` function in the form of `key=value` pairs. Only applicable when `user_config.lazy_loading` is `true`. +--- @field manual boolean? Used if down was manually loaded via `:downStart`. Only applicable when `user_config.lazy_loading` is `true`. +--- @field mod table Acts as a copy of the user's config that may be modified at runtime. +--- @field os OperatingSystem The operating system that down is currently running under. +--- @field pathsep "\\"|"/" The operating system that down is currently running under. +--- @field started boolean Set to `true` when down is fully initialized. +--- @field user down.config.User Stores the config provided by the user. +--- @field version string The version of down that is currently active. Automatically updated by CI on every release. +--- @field public [string]? down.Mod + +--- Stores the config for the entirety of down. +--- This includes not only the user config (passed to `setup()`), but also internal +--- variables that describe something specific about the user's hardware. +--- @see down.Setup +--- +--- +--- @class (exact) down.Event +--- @field type string The type of the event. Exists in the format of `category.name`. +--- @field split_type string[] The event type, just split on every `.` character, e.g. `{ "category", "name" }`. +--- @field content? table|any The content of the event. The data found here is specific to each individual event. Can be thought of as the payload. +--- @field referrer string The name of the init that triggered the event. +--- @field broadcast boolean Whether the event was broadcast to all mod. `true` is so, `false` if the event was specifically sent to a single recipient. +--- @field cursor_position { [1]: number, [2]: number } The position of the cursor at the moment of broadcasting the event. +--- @field filename string The name of the file that the user was in at the moment of broadcasting the event. +--- @field filehead string The directory the user was in at the moment of broadcasting the event. +--- @field line_content string The content of the line the user was editing at the moment of broadcasting the event. +--- @field buffer number The buffer ID of the buffer the user was in at the moment of broadcasting the event. +--- @field window number The window ID of the window the user was in at the moment of broadcasting the event. +--- @field mode Mode The mode Neovim was in at the moment of broadcasting the event. +--- +--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- diff --git a/lua/down/types/mod.lua b/lua/down/types/mod.lua new file mode 100644 index 0000000..9f25a3c --- /dev/null +++ b/lua/down/types/mod.lua @@ -0,0 +1,16 @@ +---@meta down.types.mod +--- +--- The scope of an entity. +--- @alias down.mod.Data +--- | down.lsp.document.Data +--- | down.lsp.workspace.Data +--- | down.lsp.completion.Data +--- | down.lsp.actions.Data +--- | down.lsp.command.Data +--- | down.lsp.hint.Data +--- | down.data.task.Data +--- | down.data.store.Data +--- | down.data.task.agenda.Data +--- | down.data.log.Data +--- | down.lsp.hover.Data +--- | down.lsp.lens.Data diff --git a/lua/down/types/store.lua b/lua/down/types/store.lua new file mode 100644 index 0000000..226829a --- /dev/null +++ b/lua/down/types/store.lua @@ -0,0 +1,156 @@ +--- @meta down.types.store +--- @brief Provides core data types +--- @version <5.2,JIT +--- +--- @brief down.Store -------------------------------- +--- +--- The important store value object +--- @class (exact) down.Store: { [down.store.Item.Kind]?: down.store.map.Kind } +--- +--- @brief down.store.Key | down.store.Item ---------- +--- +--- @alias down.store.Item.Kind "log" log" +--- | "workspace" log" +--- | "note" log" +--- | "project" log" +--- | "group" group +--- | "scope" scope +--- | "task" task +--- | "scope" scope +--- | "tag" tag +--- | "flag" flag +--- | "store" store +--- | "status" status +--- | "priority" priority +--- | "weekday" weekday +--- | "category" category +--- | "month" month +--- | "year" year +--- | "time" time +--- | "date" date +--- | "datetime" datetime +--- | "location" location +--- | "event" event +--- | "person" person +--- | "rank" rank +--- | "file" file +--- | "folder" folder +--- | "definition" definition +--- | "mod" mod `` +--- +--- @alias down.store.Key.Kind +--- | "uri" uri +--- +--- Configuration for global settings. +--- @alias down.store.Key down.Tag Tag +--- | down.Flag Flag +--- | down.Tag +--- | down.Uri +--- | down.Id +--- | down.Dir +--- | down.File File +--- | down.Workspace +--- | down.Scope +--- | down.Project +--- | down.task.Priority +--- | down.task.Status +--- | down.Uri +--- | down.Anchor +--- | down.Ranking +--- | number string +--- | down.Category +--- | down.Date +--- | string +--- +--- Configuration for global settings. +--- @alias down.store.Item down.Store +--- | down.Workspace workspace +--- | down.User User +--- | down.Anchor Anchor +--- | down.Dir dir +--- | down.Id Id +--- | down.File file +--- | down.Position file +--- | down.Task task +--- | down.Position position +--- | down.Uri task +--- | down.Log log +--- | down.Project PProject +--- | down.Note note +--- | down.Tag tag +--- | down.Agenda agenda +--- | down.Flag Flag +--- | down.Store Store +--- | down.store.Item Item +--- | down.store.Key Key +--- | down.Scope Scope +--- | down.Group Group +--- | down.Category Category +--- | down.Mod mod Tag +--- | down.Category Category +--- | down.Ranking Ranking +--- | down.task.Priority +--- | down.task.Status +--- | { [down.store.Key]: down.store.Item } +--- | { [string]: string } +--- +--- @brief down.store ---------------------- +--- +--- @alias down.store.Name string The name associated with the vault of a certain kind +--- +--- @alias down.store.Index integer The index in the list of vault +--- +--- The important store value object +--- Contains a map of K to item type V +--- And an identifier, name, and kind string +--- id is like (if local): default.kind.item. +--- @class down.Store: { +--- id?: down.Id, +--- uri?: down.Uri, +--- name?: string, +--- about?: string, +--- workspace?: down.Id, +--- default?: K, +--- store?: { [K]?: V }, +--- config?: down.config.Local, +--- metadata?: { [string]?: any }, +--- scope?: down.Scope, +--- index?: number | down.store.Item.Kind, +--- config?: down.config.Local, +--- type?: type, +--- } Map from id to store of kind +--- +--- @alias down.store.Workspace down.Store +--- +--- @alias down.store.List down.Store +--- +--- @alias down.store.Id down.Store +--- +--- @alias down.store.Kind down.Store +--- +--- @alias down.store.Map down.Store> +--- +--- @alias down.KindId down.Store> +--- +--- @class (exact) down.store.KindIdDateMap { default?: down.store.Item.Kind, [down.store.Item.Kind]?: down.store.map.Id } +--- +--- +--- @brief down.store.data +--- +--- @alias down.store.KindId down.Store> +--- +--- THe data object for workspaces. +--- @class (exact) down.store.Stores The data object for stores. +--- @field public store? down.store.KindId stores +--- @field public agenda? down.store.KindId agenda +--- @field public tasks? down.store.KindId agenda +--- @field public logs? down.store.KindId agenda +--- @field public stores? down.store.KindId agenda +--- @field public notes? down.store.KindId agenda +--- @field public files? down.store.KindId agenda +--- @field public dirs? down.store.KindId agenda +--- @field public tags? down.store.KindId agenda +--- @field public flags? down.store.KindId agenda +--- @field public projects? down.store.KindId proj +--- @field public groups? down.store.KindId proj +--- @field public scopes? down.store.KindId proj diff --git a/lua/down/types/util.lua b/lua/down/types/util.lua new file mode 100644 index 0000000..455b6e2 --- /dev/null +++ b/lua/down/types/util.lua @@ -0,0 +1,56 @@ +---@meta data.types.util +--- +--- The data object for workspaces. +--- @class (exact) down.HasInfo: down.Tagged, down.HasScope, down.HasMetadata The info object. +--- +--- @class (exact) down.Table: { [K]?: V } The data object. +--- +--- @class (exact) down.Workspaces: { default?: down.Id, [down.Id]: down.Workspace } +--- +--- @class (exact) down.Mods: { [string]: down.Mod } +--- +--- @class (exact) down.Data: { [string]: V } The data object. +--- +--- @class (exact) down.List: { [integer]: V } List +--- +--- @class down.HasId: { id: down.Uri } Has an ID that is a URI +--- +--- @class down.HasName: { name: down.Id } Has name +--- +--- @class down.HasUri: { uri: down.Uri } Has an ID that is a URI +--- +--- @class down.HasCtx: { context?: down.Context } Has info +--- +--- @class down.HasMetadata: { metadata?: table} } Has meta +--- +--- @class down.HasData: { data?: down.Data } Has meta +--- +--- @class down.HasScope: { scope: down.Scope } Has scope +--- +--- @class down.HasStore: { store?: down.Store } The store object. +--- +--- @class down.Base.Store: down.Base, { store?: down.Store } +--- +--- @class (exact) down.Tagged: { tags?: down.Tag[] } Has tags +--- +--- @class (exact) down.Flagged: { flags?: down.Flag[] } Has tags +--- +--- @class (exact) down.NameUri: down.HasUri, down.HasName Has data store with list of values +--- +--- @class (exact) down.HasList: { data?: { [number]: V } } Has data list +--- +--- @class (exact) down.base.Base: down.HasUri, down.HasName, down.HasInfo Has base +--- +--- @class down.Base: { uri: down.Uri, id: down.Id, tags: down.Tag[], metadata: { [string]: any }, info?: {} } HasInfo Has meta +--- +--- @class (exact) down.base.Table: down.Base, { data?: { [K]?: V } } +--- +--- @class (exact) down.base.Data: down.Base, { data?: { [string]?: V } } +--- +--- @class (exact) down.base.List: down.Base, { data?: { [integer]?: V } } +--- +--- @class (exact) down.store.Set: down.Base, { data?: { [integer]: V }, } +--- +--- @class (exact) down.store.Table: down.Base, { data?: { [string]?: V } } +--- +--- @class (exact) down.base.Data: down.HasUri, down.HasName, down.HasInfo, { data?: { [K]?: V } } diff --git a/lua/down/types/workspace.lua b/lua/down/types/workspace.lua new file mode 100644 index 0000000..6586085 --- /dev/null +++ b/lua/down/types/workspace.lua @@ -0,0 +1,7 @@ +--- @meta down.types.workspcae + +--- The local config for setting up workspaces. +--- @alias down.Workspace down.store.KindId +--- +--- The local config for setting up workspaces. +--- @alias down.Workspaces down.Store diff --git a/lua/down/util/lsp.lua b/lua/down/util/lsp.lua new file mode 100644 index 0000000..5896b9e --- /dev/null +++ b/lua/down/util/lsp.lua @@ -0,0 +1,49 @@ +local M = {} + +M.config = function() + return vim.lsp.config({ + name = 'downls', + cmd = { 'down', 'lsp' }, + root_dir = vim.fn.getcwd(), + settings = { + markdown = {}, + down = { + completion = { + enable = true, + }, + hover = { + enable = true, + }, + highlight = { + enable = true, + }, + }, + }, + }) +end + +function M.run() + local ft = vim.bo.filetype + if ft == 'down' or ft == 'docdown' or ft == 'markdown' or ft == 'mdx' then + vim.lsp.start({ + name = 'downls', + cmd = { 'down', 'lsp' }, + root_dir = vim.fn.getcwd(), + settings = {}, + }) + end +end + +function M.setup() + vim.api.nvim_create_autocmd('BufEnter', { + pattern = '*', + callback = M.run, + desc = 'Start down-lsp', + }) + vim.o.rtp = vim.o.rtp .. ',/Users/clp/down' + vim.o.rtp = vim.o.rtp .. ',/Users/clp/down/ext/lsp' +end + +M.run() + +return M diff --git a/readme.dn b/readme.dn new file mode 100644 index 0000000..7b5ee7e --- /dev/null +++ b/readme.dn @@ -0,0 +1 @@ +fn main() {} diff --git a/scripts/bin/down b/scripts/bin/down index fe0ad73..5be762e 100755 --- a/scripts/bin/down +++ b/scripts/bin/down @@ -1,5 +1,7 @@ #!/usr/bin/env lua +Down = {} + --+ +----------------------+ down +----------------------+ +-- --+ | | +-- --+ | down v0.1.1-alpha | +-- @@ -33,13 +35,15 @@ --+ | | +-- --+ +----------------------------------------------------+ +-- -local w_ok, down = pcall(require, "down") -local u_ok, util = pcall(require, "down.util") -local m_ok, mod = pcall(require, "down.mod") -local c_ok, conf = pcall(require, "down.config") -local l_ok, lsp = pcall(require, "down.mod.lsp") -local ws_ok, ws = pcall(require, "down.mod.workspace") -local wts_ok, wts = pcall(require, "down.mod.integration.treesitter") +local w_ok, down = pcall(require, 'down') +local u_ok, util = pcall(require, 'down.util') +local m_ok, mod = pcall(require, 'down.mod') +local c_ok, conf = pcall(require, 'down.config') +local l_ok, lsp = pcall(require, 'down.mod.lsp') +local ws_ok, ws = pcall(require, 'down.mod.workspace') +local wts_ok, wts = pcall(require, 'down.mod.integration.treesitter') + +-- print(w_ok, u_ok) --+ +---------------------+ extern +---------------------+ +-- --+ | | +-- @@ -47,10 +51,10 @@ local wts_ok, wts = pcall(require, "down.mod.integration.tree --+ | | +-- --+ +----------------------------------------------------+ +-- -local lp_ok, lp = pcall(require, "lpeg") -local vt_ok, vts = pcall(require, "vim.treesitter") -local ts_ok, nts = pcall(require, "nvim-treesitter") -local tsu_ok, tsu = pcall(require, "nvim-treesitter.ts_utils") +local lp_ok, lp = pcall(require, 'lpeg') +local vt_ok, vts = pcall(require, 'vim.treesitter') +local ts_ok, nts = pcall(require, 'nvim-treesitter') +local tsu_ok, tsu = pcall(require, 'nvim-treesitter.ts_utils') --+ +----------------------+ util +----------------------+ +-- --+ | | +-- @@ -58,39 +62,21 @@ local tsu_ok, tsu = pcall(require, "nvim-treesitter.ts_utils" --+ | | +-- --+ +----------------------------------------------------+ +-- -local lb, rb, gb, yb, s, mb, cb, wb = "\x1b[40m", "\x1b[41m", "\x1b[42m", "\x1b[43m", "\x1b[44m", "\x1b[45m", - "\x1b[46m", - "\x1b[47m" -local x, i, s, e, u, cr = - "\x1b[0m", "\x1b[7m", "\x1b[1m", "\x1b[3m", "\x1b[4m", "\x1b[9m" +local lb, rb, gb, yb, s, mb, cb, wb = + '\x1b[40m', '\x1b[41m', '\x1b[42m', '\x1b[43m', '\x1b[44m', '\x1b[45m', '\x1b[46m', '\x1b[47m' +local x, i, s, e, u, cr = '\x1b[0m', '\x1b[7m', '\x1b[1m', '\x1b[3m', '\x1b[4m', '\x1b[9m' local ll, lr, lg, ly, lb, lm, lc, lw = - "\x1b[90m", - "\x1b[91m", - "\x1b[92m", - "\x1b[93m", - "\x1b[94m", - "\x1b[95m", - "\x1b[96m", - "\x1b[97m" -local l, r, g, y, b, m, c, w = - "\x1b[30m", - "\x1b[31m", - "\x1b[32m", - "\x1b[33m", - "\x1b[34m", - "\x1b[35m", - "\x1b[36m", - "\x1b[37m" -local bi = function(inp) + '\x1b[90m', '\x1b[91m', '\x1b[92m', '\x1b[93m', '\x1b[94m', '\x1b[95m', '\x1b[96m', '\x1b[97m' +local l, r, g, y, b, m, c, w = + '\x1b[30m', '\x1b[31m', '\x1b[32m', '\x1b[33m', '\x1b[34m', '\x1b[35m', '\x1b[36m', '\x1b[37m' +local bi = function(inp) return inp .. i end -local si = function(inp) +local si = function(inp) return inp .. s .. i end -local br, bg, by, bb, bm, bc, bw = - bi(r), bi(g), bi(y), bi(b), bi(m), bi(c), bi(w) -local sr, sg, sy, sb, sm, sc, sw = - si(r), si(g), si(y), si(b), si(m), si(c), si(w) +local br, bg, by, bb, bm, bc, bw = bi(r), bi(g), bi(y), bi(b), bi(m), bi(c), bi(w) +local sr, sg, sy, sb, sm, sc, sw = si(r), si(g), si(y), si(b), si(m), si(c), si(w) --+ +----------------------+ vars +----------------------+ +-- --+ | | +-- @@ -98,31 +84,31 @@ local sr, sg, sy, sb, sm, sc, sw = --+ | | +-- --+ +----------------------------------------------------+ +-- -local down = { +local down = { pre = { i = function(c, a) - return c .. "" .. a + return c .. '' .. a end, y = function(a) - return sy .. "" .. a + return sy .. '' .. a end, c = function(a) - return sc .. "" .. a + return sc .. '' .. a end, m = function(a) - return sm .. "" .. a + return sm .. '' .. a end, r = function(a) - return sr .. "" .. a + return sr .. '' .. a end, w = function(a) - return sw .. "" .. a + return sw .. '' .. a end, g = function(a) - return sg .. "" .. a + return sg .. '' .. a end, b = function(a) - return sb .. "" .. a + return sb .. '' .. a end, }, colors = { @@ -133,93 +119,93 @@ local down = { flag = g, }, style = function(pre, h) - return pre .. " " .. h .. " " + return pre .. ' ' .. h .. ' ' end, - version = "v0.1.0-alpha.2", - repo = "github.com/clpi/down.lua", - home = "down.cli.st", - updated = "2024-12-15", + version = 'v0.1.0-alpha.2', + repo = 'github.com/clpi/down.lua', + home = 'down.cli.st', + updated = '2024-12-15', color = true, debug = false, } -down.styles = {} -down.bits = { - vers = ll .. "v" .. x .. w .. "0.1.1" .. ll .. "-" .. x .. w .. "alpha", - lambda = ll .. s .. "󰘧 " .. x, - downi = ll .. s .. "󰘧 " .. x .. y .. "down" .. x, +down.styles = {} +down.bits = { + vers = ll .. 'v' .. x .. w .. '0.1.1' .. ll .. '-' .. x .. w .. 'alpha', + lambda = ll .. s .. '󰘧 ' .. x, + downi = ll .. s .. '󰘧 ' .. x .. y .. 'down' .. x, brk = { - l = ll .. "[" .. x, - r = ll .. "]" .. x, + l = ll .. '[' .. x, + r = ll .. ']' .. x, }, brc = { - l = ll .. "{" .. x, - r = ll .. "}" .. x, + l = ll .. '{' .. x, + r = ll .. '}' .. x, }, par = { - l = ll .. "(" .. x, - r = ll .. ")" .. x, + l = ll .. '(' .. x, + r = ll .. ')' .. x, }, icon = { - block = ll .. "󰆧 " .. x, - info = ll .. "󰆨 " .. x, + block = ll .. '󰆧 ' .. x, + info = ll .. '󰆨 ' .. x, }, arrow = { - l = ll .. "←" .. x, - r = ll .. "→" .. x, + l = ll .. '←' .. x, + r = ll .. '→' .. x, }, arr = { - l = ll .. "<" .. x, - r = ll .. ">" .. x, + l = ll .. '<' .. x, + r = ll .. '>' .. x, }, - ellipses = ll .. "…" .. x, - pipe = ll .. "|" .. x, - comma = ll .. "," .. x, - colon = ll .. ":" .. x, - period = ll .. "." .. x, - asterisk = ll .. "*" .. x, - plus = ll .. "+" .. x, - hy = ll .. "-" .. x, - hy2 = ll .. "--" .. x, - eq = ll .. "=" .. x, - down = y .. "down" .. x, - markdown = lg .. " 󰍔 " .. g .. " Mark" .. x .. g .. "down" .. x, - downluai = x .. y .. ll .. "󰘧" .. y .. " down" .. "." .. "lua", - downlua = x .. ly .. "down" .. ll .. "." .. y .. "lua", - command = ll .. "[" .. g .. "󰆧 " .. g .. "command" .. ll .. "]" .. x, - opts = ll .. "[" .. b .. "󰆧 " .. ll .. "" .. b .. "opts" .. ll .. "]" .. x, - flags = ll .. "[" .. m .. "󰆧 " .. m .. "flags" .. ll .. "]" .. x, - args = ll .. "[" .. r .. "󰆧 " .. ll .. "" .. r .. "args" .. ll .. "]" .. x, - author = "Chris Pecunies " .. g .. "", + ellipses = ll .. '…' .. x, + pipe = ll .. '|' .. x, + comma = ll .. ',' .. x, + colon = ll .. ':' .. x, + period = ll .. '.' .. x, + asterisk = ll .. '*' .. x, + plus = ll .. '+' .. x, + hy = ll .. '-' .. x, + hy2 = ll .. '--' .. x, + eq = ll .. '=' .. x, + down = y .. 'down' .. x, + markdown = lg .. ' 󰍔 ' .. g .. ' Mark' .. x .. g .. 'down' .. x, + downluai = x .. y .. ll .. '󰘧' .. y .. ' down' .. '.' .. 'lua', + downlua = x .. ly .. 'down' .. ll .. '.' .. y .. 'lua', + command = ll .. '[' .. g .. '󰆧 ' .. g .. 'command' .. ll .. ']' .. x, + opts = ll .. '[' .. b .. '󰆧 ' .. ll .. '' .. b .. 'opts' .. ll .. ']' .. x, + flags = ll .. '[' .. m .. '󰆧 ' .. m .. 'flags' .. ll .. ']' .. x, + args = ll .. '[' .. r .. '󰆧 ' .. ll .. '' .. r .. 'args' .. ll .. ']' .. x, + author = 'Chris Pecunies ' .. g .. '', } -down.bits.version = down.bits.vers - .. ll - .. " (" - .. ll - .. "updated " - .. g - .. down.updated - .. ll - .. ")" -down.bits.usage = "" - .. down.bits.downi - .. " " - .. down.bits.command - .. down.bits.opts - .. down.bits.flags - .. down.bits.args - .. down.bits.brk.l - .. down.bits.ellipses - .. down.bits.brk.r -down.bits.desc = down.bits.downlua - .. x - .. w - .. " is a dev-focused, familiar" - .. down.bits.markdown - .. "\n " - .. w - .. "environment, focused on providing familiarity \n " - .. w - .. "and extensibility for developers, in development." +down.bits.version = down.bits.vers + .. ll + .. ' (' + .. ll + .. 'updated ' + .. g + .. down.updated + .. ll + .. ')' +down.bits.usage = '' + .. down.bits.downi + .. ' ' + .. down.bits.command + .. down.bits.opts + .. down.bits.flags + .. down.bits.args + .. down.bits.brk.l + .. down.bits.ellipses + .. down.bits.brk.r +down.bits.desc = down.bits.downlua + .. x + .. w + .. ' is a dev-focused, familiar' + .. down.bits.markdown + .. '\n ' + .. w + .. 'environment, focused on providing familiarity \n ' + .. w + .. 'and extensibility for developers, in development.' --+ +----------------------+ kind +----------------------+ +-- --+ | | +-- @@ -227,13 +213,13 @@ down.bits.desc = down.bits.downlua --+ | | +-- --+ +----------------------------------------------------+ +-- -local Kind = { +local Kind = { opt = { - param = "param", - flag = "flag", + param = 'param', + flag = 'flag', }, - arg = "arg", - cmd = "cmd", + arg = 'arg', + cmd = 'cmd', } --+ +----------------------+ args +----------------------+ +-- @@ -242,7 +228,7 @@ local Kind = { --+ | | +-- --+ +----------------------------------------------------+ +-- -local Arg = { +local Arg = { long = nil, index = -1, pos = 1, @@ -250,58 +236,58 @@ local Arg = { short = nil, value = nil, handler = nil, - desc = "", - help = "", + desc = '', + help = '', } -Arg.Kind = { +Arg.Kind = { -- like --... or -... or --...=... or -...=... opt = { -- like --...=... or -...=... param = { short = { -- like -a=... - short = "opt_param_short_letter", + short = 'opt_param_short_letter', -- like -abc=... NOTE: bad - long = "opt_param_short_short", + long = 'opt_param_short_short', }, long = { -- like --a=... NOTE: bad - short = "opt_param_long_short", + short = 'opt_param_long_short', -- like --abc=... - long = "opt_param_long_long", + long = 'opt_param_long_long', }, }, flag = { -- like -... short = { -- like -a - short = "opt_flag_short_short", + short = 'opt_flag_short_short', -- like -abc NOTE: bad - long = "opt_flag_short_long", + long = 'opt_flag_short_long', }, -- like --... long = { -- like --a NOTE: bad - short = "opt_flag_long_short", + short = 'opt_flag_long_short', -- like --abc - long = "opt_flag_long_long", + long = 'opt_flag_long_long', }, }, }, - arg = "arg", + arg = 'arg', cmd = { -- like abc - long = "cmd_long", + long = 'cmd_long', -- like a - short = "cmd_short", + short = 'cmd_short', }, } ---@return string, string function Arg.Kind.check(a) - if a:sub(1, 1) == "-" then - if a:sub(2, 2) == "-" then + if a:sub(1, 1) == '-' then + if a:sub(2, 2) == '-' then a = a:sub(3) if #a == 1 then return a, Arg.Kind.opt.flag.long.short @@ -324,27 +310,27 @@ function Arg.Kind.check(a) end Arg.Kind.opt.param.is = function(k) - if k:sub(1, 9) == "opt_param" then + if k:sub(1, 9) == 'opt_param' then return true end return false end Arg.Kind.opt.flag.is = function(k) - if k:sub(1, 8) == "opt_flag" then + if k:sub(1, 8) == 'opt_flag' then return true end return false end Arg.Kind.opt.is = function(k) - if k:sub(1, 3) == "opt" then + if k:sub(1, 3) == 'opt' then return true end return false end Arg.Kind.cmd.is = function(k) - if k:sub(1, 3) == "cmd" then + if k:sub(1, 3) == 'cmd' then return true end return false @@ -353,80 +339,26 @@ end function Arg.Kind.unknown(a, k) if k == Arg.Kind.opt.flag.long.long then print( - r - .. "unknown" - .. x - .. b - .. " long " - .. l - .. "(long)" - .. x - .. " flag: " - .. down.bits.hy2 - .. a + r .. 'unknown' .. x .. b .. ' long ' .. l .. '(long)' .. x .. ' flag: ' .. down.bits.hy2 .. a ) elseif k == Arg.Kind.opt.flag.long.short then print( - r - .. "unknown" - .. x - .. b - .. " long " - .. l - .. "(short)" - .. x - .. " flag: " - .. down.bits.hy2 - .. a + r .. 'unknown' .. x .. b .. ' long ' .. l .. '(short)' .. x .. ' flag: ' .. down.bits.hy2 .. a ) elseif k == Arg.Kind.opt.flag.short.long then print( - r - .. "unknown" - .. x - .. g - .. " short " - .. l - .. "(long)" - .. x - .. " flag: " - .. down.bits.hy - .. a + r .. 'unknown' .. x .. g .. ' short ' .. l .. '(long)' .. x .. ' flag: ' .. down.bits.hy .. a ) elseif k == Arg.Kind.opt.flag.short.short then print( - r - .. "unknown" - .. x - .. g - .. " short " - .. l - .. "(short)" - .. x - .. " flag: " - .. down.bits.hy - .. a + r .. 'unknown' .. x .. g .. ' short ' .. l .. '(short)' .. x .. ' flag: ' .. down.bits.hy .. a ) elseif k == Arg.Kind.cmd.short then - print( - r - .. "unknown" - .. x - .. g - .. " short " - .. y - .. "cmd" - .. ll - .. ": " - .. x - .. a - ) + print(r .. 'unknown' .. x .. g .. ' short ' .. y .. 'cmd' .. ll .. ': ' .. x .. a) elseif k == Arg.Kind.cmd.long then - print( - r .. "unknown" .. x .. b .. " long " .. y .. "cmd" .. ll .. ": " .. x .. a - ) + print(r .. 'unknown' .. x .. b .. ' long ' .. y .. 'cmd' .. ll .. ': ' .. x .. a) else - print(r .. "unknown" .. x .. " arg" .. ll .. ": " .. x .. a) + print(r .. 'unknown' .. x .. ' arg' .. ll .. ': ' .. x .. a) end end @@ -446,8 +378,8 @@ function Arg.init(lng, sh, k, d, h, v, pos) self.__tostring = function(t) return t.long end - self.desc = d or "" - self.long = lng or "" + self.desc = d or '' + self.long = lng or '' self.short = sh or l[1] self.kind = k or Kind.arg self.handler = h or function() @@ -460,36 +392,36 @@ end function Arg:help(h) if self.kind == Kind.cmd then - return "" - .. g - .. self.short - .. "" - .. x - .. " " - .. down.bits.pipe - .. " " - .. g - .. self.long:sub(1, 1) - .. x - .. self.long:sub(2) - .. "\t " - .. self.desc + return '' + .. g + .. self.short + .. '' + .. x + .. ' ' + .. down.bits.pipe + .. ' ' + .. g + .. self.long:sub(1, 1) + .. x + .. self.long:sub(2) + .. '\t ' + .. self.desc elseif self.kind == Kind.opt.flag then - return "" - .. down.bits.hy - .. b - .. self.short - .. x - .. " " - .. down.bits.pipe - .. " " - .. down.bits.hy2 - .. b - .. self.long:sub(1, 1) - .. x - .. self.long:sub(2) - .. "\t " - .. self.desc + return '' + .. down.bits.hy + .. b + .. self.short + .. x + .. ' ' + .. down.bits.pipe + .. ' ' + .. down.bits.hy2 + .. b + .. self.long:sub(1, 1) + .. x + .. self.long:sub(2) + .. '\t ' + .. self.desc else print(self.long, self.short) end @@ -525,11 +457,11 @@ end --+ +----------------------------------------------------+ +-- local function test(...) - print("test") + print('test') end local function conf(...) - print("conf") + print('conf') end --+ +----------------------+ func +----------------------+ +-- @@ -540,52 +472,64 @@ end down.opts = {} down.args = {} - +down.fmt = { + fmt = function(c, h, i) + down.help.header.print(c, h) + end, + cmds = { + note = { title = '󰯂 note ', color = sb }, + log = { title = '󰆧 log ', color = sg }, + init = { title = '󰯂 init ', color = sm }, + run = { title = '󰆧 run ', color = sr }, + config = { title = '󰯂 config ', color = sc }, + workspace = { title = '󰯂 workspace ', color = sy }, + }, +} down.help = { header = { print = function(pre, h) - print("\n" .. pre .. " " .. h .. " ") + print('\n' .. pre .. ' ' .. h .. ' ') end, - info = "󰯂 INFO ", - cmds = " CMDS ", - args = "󰆧 ARGS ", - flag = "󰷐 FLAGS", - opts = "󰆧 OPTS ", - usage = "󰒓 USAGE", + info = '󰯂 INFO ', + cmds = ' CMDS ', + args = '󰆧 ARGS ', + flag = '󰷐 FLAGS', + opts = '󰆧 OPTS ', + usage = '󰒓 USAGE', }, down = function() - print("\n" .. down.bits.downi .. " " .. x .. down.bits.version) + print('\n' .. down.bits.downi .. ' ' .. x .. down.bits.version) -- print(b .. " author " .. x .. " " .. down.bits.author) -- print(b .. " repo " .. x .. " " .. down.repo) -- print(b .. " home " .. x .. " " .. down.home) end, info = function() down.help.header.print(sy, down.help.header.info) - print(bg .. "" .. x .. " " .. w .. down.bits.desc) + print(bg .. '' .. x .. ' ' .. w .. down.bits.desc) end, usage = function() down.help.header.print(sg, down.help.header.usage) - print(bg .. "" .. x .. " " .. w .. down.bits.usage) + print(bg .. '' .. x .. ' ' .. w .. down.bits.usage) end, cmds = function() down.help.header.print(sg, down.help.header.cmds) for _, v in pairs(down.cmds) do - print(bg .. "" .. x .. " " .. w .. Arg.help(v)) + print(bg .. '' .. x .. ' ' .. w .. Arg.help(v)) end end, flags = function() down.help.header.print(sb, down.help.header.flag) for _, v in pairs(down.flags) do - print(bg .. "" .. x .. " " .. w .. Arg.help(v)) + print(bg .. '' .. x .. ' ' .. w .. Arg.help(v)) end end, opts = function() down.help.header.print(sm, down.help.header.opts) - print(br .. "" .. x .. " " .. x .. r .. down.bits.ellipses) + print(br .. '' .. x .. ' ' .. x .. r .. down.bits.ellipses) end, args = function() down.help.header.print(sr, down.help.header.args) - print(bm .. "" .. x .. " " .. x .. m .. down.bits.ellipses) + print(bm .. '' .. x .. ' ' .. x .. m .. down.bits.ellipses) end, } down.help.print = function() @@ -598,49 +542,51 @@ down.help.print = function() -- down.help.args() end down.flags = { - version = Arg.flag("version", "Print version", function() + version = Arg.flag('version', 'Print version', function() print(down.version) end), - debug = Arg.flag("debug", "Set debug", function() - print("debug") + debug = Arg.flag('debug', 'Set debug', function() + print('debug') end), - config = Arg.flag("config", "Specify config file", function(...) - print("config") + config = Arg.flag('config', 'Specify config file', function(...) + print('config') end), - stdout = Arg.flag("stdout", "Set stdout output", function() - print("stdout") + stdout = Arg.flag('stdout', 'Set stdout output', function() + print('stdout') end), - profile = Arg.flag("color", "Set color output", function() - print("color") + profile = Arg.flag('color', 'Set color output', function() + print('color') end), - help = Arg.flag("help", "Print help", down.help.print), + help = Arg.flag('help', 'Print help', down.help.print), } down.cmds = { - init = Arg.cmd(1, "init", "Initialize workspace", function() - print("init") + init = Arg.cmd(1, 'init', 'Initialize workspace', function() + down.fmt.fmt(down.fmt.cmds.init.color, down.fmt.cmds.init.title) end), - upgrade = Arg.cmd(1, "upgrade", "Upgrade binary", function() - print("upgrade") + upgrade = Arg.cmd(1, 'upgrade', 'Upgrade binary', function() + down.fmt.fmt(down.fmt.cmds.upgrade.color, down.fmt.cmds.init.title) end), - log = Arg.cmd(1, "log", "Log functionality", function(...) - print("log") + log = Arg.cmd(1, 'log', 'Log functionality', function(...) + down.fmt.fmt(down.fmt.cmds.log.color, down.fmt.cmds.log.title) end), - note = Arg.cmd(1, "note", "Note functionality", function(...) - print("note") + note = Arg.cmd(1, 'note', 'Note functionality', function(...) + down.fmt.fmt(down.fmt.cmds.note.color, down.fmt.cmds.note.title) end), - workspace = Arg.cmd(1, "workspace", "List workspaces", function(...) - print("work") + workspace = Arg.cmd(1, 'workspace', 'List workspaces', function(...) + down.fmt.fmt(down.fmt.cmds.workspace.color, down.fmt.cmds.workspace.title) end), - run = Arg.cmd(1, "run", "Run the lsp", function(...) - print("run") + run = Arg.cmd(1, 'run', 'Run the lsp', function(...) + down.fmt.fmt(down.fmt.cmds.run.color, down.fmt.cmds.run.title) end), - serve = Arg.cmd(1, "serve", "Serve the lsp", function(...) - print("serve") + serve = Arg.cmd(1, 'serve', 'Serve the lsp', function(...) + down.fmt.fmt(down.fmt.cmds.run.color, down.fmt.cmds.run.title) end), -- version = Arg.cmd("version", "Print version", down.flags.version.desc, down.flags.version.handler), - config = Arg.cmd(1, "config", "Set config values", down.flags.config.handler), - help = Arg.cmd(1, "help", "Print help", down.flags.help.handler), + config = Arg.cmd(1, 'config', 'Set config values', function(...) + down.fmt.fmt(down.fmt.cmds.config.color, down.fmt.cmds.config.title) + end), + help = Arg.cmd(1, 'help', 'Print help', down.flags.help.handler), } --- @param a string arg function down:pflag(a, k) diff --git a/scripts/bin/down-lsp b/scripts/bin/down-lsp deleted file mode 100755 index 036322d..0000000 --- a/scripts/bin/down-lsp +++ /dev/null @@ -1,702 +0,0 @@ -#!/usr/bin/env lua - ---+----------------------+ down +----------------------+-- ---| |-- ---| down-lsp v0.1.1-alpha |-- ---| |-- ---| ABOUT |-- ---| down (down-lsp) is a dev-focused note-taking |-- ---| environment for markdown, in development. |-- ---| |-- ---| USAGE |-- ---| down [options] [file] |-- ---| |-- ---| OPTIONS |-- ---| -h, --help Show help and exit |-- ---| -v, --version Show version and exit |-- ---| -i, --interactive Run in interactive mode |-- ---| -e, --execute Run in execute mode |-- ---| -c, --config Specify a config file |-- ---| |-- ---| ARGS |-- ---| serve Run the server |-- ---| init Initialize the server |-- ---| shell Run the shell |-- ---| update Update the server |-- ---| install Install the server |-- ---| uninstall Uninstall the server |-- ---| config Configure the server |-- ---| status Show the server status |-- ---| start Start the server |-- ---| stop Stop the server |-- ---| restart Restart the server |-- ---| |-- ---+----------------------------------------------------+-- - -local w_ok, down = pcall(require, "down") -local u_ok, util = pcall(require, "down.util") -local m_ok, mod = pcall(require, "down.mod") -local c_ok, conf = pcall(require, "down.config") -local l_ok, lsp = pcall(require, "down.mod.lsp") -local ws_ok, ws = pcall(require, "down.mod.workspace") -local wts_ok, wts = pcall(require, "down.mod.integration.treesitter") - ---+---------------------+ extern +---------------------+-- ---| |-- ---| import the down-lsp dependencies. |-- ---| |-- ---+----------------------------------------------------+-- - -local lp_ok, lp = pcall(require, "lpeg") -local vt_ok, vts = pcall(require, "vim.treesitter") -local ts_ok, nts = pcall(require, "nvim-treesitter") -local tsu_ok, tsu = pcall(require, "nvim-treesitter.ts_utils") - ---+----------------------+ util +----------------------+-- ---| |-- ---| define utility functions. |-- ---| |-- ---+----------------------------------------------------+-- - -local x, i, s, e, u, cr = - "\x1b[0m", "\x1b[7m", "\x1b[1m", "\x1b[3m", "\x1b[4m", "\x1b[9m" -local lb, rb, gb, yb, bb, mb, cb, wb = - "\x1b[40m", - "\x1b[41m", - "\x1b[42m", - "\x1b[43m", - "\x1b[44m", - "\x1b[45m", - "\x1b[46m", - "\x1b[47m" -local l, r, g, y, b, m, c, w = - "\x1b[90m", - "\x1b[31m", - "\x1b[32m", - "\x1b[33m", - "\x1b[34m", - "\x1b[35m", - "\x1b[36m", - "\x1b[37m" -local bi = function(inp) - return inp .. i -end -local si = function(inp) - return inp .. s .. i -end -local br, bg, by, bb, bm, bc, bw = - bi(r), bi(g), bi(y), bi(b), bi(m), bi(c), bi(w) -local bbr, bbg, bby, bbb, bbm, bbc, bbw = - si(r), si(g), si(y), si(b), si(m), si(c), si(w) - ---+----------------------+ vars +----------------------+-- ---| |-- ---| define necessary variables. |-- ---| |-- ---+----------------------------------------------------+-- - -local down = { - pre = { - i = function(c, a) - return c .. "" .. a - end, - y = function(a) - return bby .. "" .. a - end, - c = function(a) - return bbc .. "" .. a - end, - m = function(a) - return bbm .. "" .. a - end, - r = function(a) - return bbr .. "" .. a - end, - w = function(a) - return bbw .. "" .. a - end, - g = function(a) - return bbg .. "" .. a - end, - b = function(a) - return bbb .. "" .. a - end, - }, - colors = { - down = y, - info = c, - cmd = m, - arg = w, - flag = g, - }, - style = function(pre, h) - return pre .. " " .. h .. " " - end, - version = "v0.1.0-alpha.2", - repo = "github.com/clpi/down.lua", - home = "down.cli.st", - updated = "2024-12-15", - color = true, - debug = false, -} -down.styles = {} -down.bits = { - vers = l .. "v" .. x .. w .. "0.1.1" .. l .. "-" .. x .. w .. "alpha", - lambda = l .. s .. "󰘧 " .. x, - downi = l .. s .. "󰘧 " .. x .. b .. "down-lsp" .. x, - brk = { - l = l .. "[" .. x, - r = l .. "]" .. x, - }, - brc = { - l = l .. "{" .. x, - r = l .. "}" .. x, - }, - par = { - l = l .. "(" .. x, - r = l .. ")" .. x, - }, - icon = { - block = l .. "󰆧 " .. x, - info = l .. "󰆨 " .. x, - }, - arrow = { - l = l .. "←" .. x, - r = l .. "→" .. x, - }, - arr = { - l = l .. "<" .. x, - r = l .. ">" .. x, - }, - ellipses = l .. "…" .. x, - pipe = l .. "|" .. x, - comma = l .. "," .. x, - colon = l .. ":" .. x, - period = l .. "." .. x, - asterisk = l .. "*" .. x, - plus = l .. "+" .. x, - hy = l .. "-" .. x, - hy2 = l .. "--" .. x, - eq = l .. "=" .. x, - down = b .. "down-lsp" .. x, - markdown = g .. " 󰍔 Markdown" .. x, - downlspi = x .. b .. lb .. l .. "󰘧" .. b .. " down" .. "-" .. "lsp", - downlsp = x .. b .. lb .. "down" .. "-" .. b .. "lsp", - command = l - .. "[" - .. g - .. "󰆧 " - .. l - .. "" - .. g - .. "command" - .. l - .. "]" - .. x, - opts = l .. "[" .. b .. "󰆧 " .. l .. "" .. b .. "opts" .. l .. "]" .. x, - flags = l .. "[" .. m .. "󰆧 " .. l .. "" .. m .. "flags" .. l .. "]" .. x, - args = l .. "[" .. r .. "󰆧 " .. l .. "" .. r .. "args" .. l .. "]" .. x, - author = "Chris Pecunies " .. g .. "", -} -down.bits.version = down.bits.vers - .. l - .. " (" - .. l - .. "updated" - .. g - .. " " - .. down.updated - .. l - .. ")" -down.bits.usage = "" - .. down.bits.downi - .. " " - .. " " .. down.bits.command - .. " " .. down.bits.opts - .. " " .. down.bits.flags - .. " " .. down.bits.args - .. " " .. down.bits.brk.l - .. "" .. down.bits.ellipses - .. " " .. down.bits.brk.r -down.bits.desc = down.bits.downlsp - .. x - .. " is a dev-focused, familiar" - .. down.bits.markdown - .. "\n " - .. "environment, focused on providing familiarity \n " - .. "and extensibility for developers, in development." - ---+----------------------+ kind +----------------------+-- ---| |-- ---| define kind type. |-- ---| |-- ---+----------------------------------------------------+-- - -local Kind = { - opt = { - param = "param", - flag = "flag", - }, - arg = "arg", - cmd = "cmd", -} - ---+----------------------+ args +----------------------+-- ---| |-- ---| define arg type. |-- ---| |-- ---+----------------------------------------------------+-- - -local Arg = { - long = nil, - kind = nil, - short = nil, - value = nil, - handler = nil, - desc = "", - help = "", -} - -Arg.Kind = { - -- like --... or -... or --...=... or -...=... - opt = { - -- like --...=... or -...=... - param = { - short = { - -- like -a=... - short = "opt_param_short_letter", - -- like -abc=... NOTE: bad - long = "opt_param_short_short", - }, - long = { - -- like --a=... NOTE: bad - short = "opt_param_long_short", - -- like --abc=... - long = "opt_param_long_long", - }, - }, - flag = { - -- like -... - short = { - -- like -a - short = "opt_flag_short_short", - -- like -abc NOTE: bad - long = "opt_flag_short_long", - }, - -- like --... - long = { - -- like --a NOTE: bad - short = "opt_flag_long_short", - -- like --abc - long = "opt_flag_long_long", - }, - }, - }, - arg = "arg", - cmd = { - -- like abc - long = "cmd_long", - -- like a - short = "cmd_short", - }, -} - ----@return string, string -function Arg.Kind.check(a) - if a:sub(1, 1) == "-" then - if a:sub(2, 2) == "-" then - a = a:sub(3) - if #a == 1 then - return a, Arg.Kind.opt.flag.long.short - end - return a, Arg.Kind.opt.flag.long.long - else - a = a:sub(2) - if #a == 1 then - return a, Arg.Kind.opt.flag.short.short - end - return a, Arg.Kind.opt.flag.short.long - end - else - if #a == 1 then - return a, Arg.Kind.cmd.short - else - return a, Arg.Kind.cmd.long - end - end -end - -Arg.Kind.opt.param.is = function(k) - if k:sub(1, 9) == "opt_param" then - return true - end - return false -end -Arg.Kind.opt.flag.is = function(k) - if k:sub(1, 8) == "opt_flag" then - return true - end - return false -end - -Arg.Kind.opt.isopt = function(k) - if k:sub(1, 3) == "opt" then - return true - end - return false -end - -Arg.Kind.cmd.iscmd = function(k) - if k:sub(1, 3) == "cmd" then - return true - end - return false -end - -function Arg.Kind.unknown(a, k) - if k == Arg.Kind.opt.flag.long.long then - print( - r - .. "unknown" - .. x - .. b - .. " long " - .. l - .. "(long)" - .. x - .. " flag: " - .. down.bits.hy2 - .. a - ) - elseif k == Arg.Kind.opt.flag.long.short then - print( - r - .. "unknown" - .. x - .. b - .. " long " - .. l - .. "(short)" - .. x - .. " flag: " - .. down.bits.hy2 - .. a - ) - elseif k == Arg.Kind.opt.flag.short.long then - print( - r - .. "unknown" - .. x - .. g - .. " short " - .. l - .. "(long)" - .. x - .. " flag: " - .. down.bits.hy - .. a - ) - elseif k == Arg.Kind.opt.flag.short.short then - print( - r - .. "unknown" - .. x - .. g - .. " short " - .. l - .. "(short)" - .. x - .. " flag: " - .. down.bits.hy - .. a - ) - elseif k == Arg.Kind.cmd.short then - print( - r .. "unknown" .. x .. g .. " short " .. b .. "cmd" .. l .. ": " .. x .. a - ) - elseif k == Arg.Kind.cmd.long then - print( - r .. "unknown" .. x .. b .. " long " .. b .. "cmd" .. l .. ": " .. x .. a - ) - else - print(r .. "unknown" .. x .. " arg" .. l .. ": " .. x .. a) - end -end - -function Arg.flag(lng, desc, h, sh) - return Arg.init(lng, sh or lng:sub(1, 1), Kind.opt.flag, desc, h) -end - -function Arg.cmd(lng, desc, h, sh) - return Arg.init(lng, sh or lng:sub(1, 1), Kind.cmd, desc, h) -end - -function Arg.init(lng, sh, k, d, h, v) - local self = {} - self.__index = self - self.__tostring = function(t) - return t.long - end - self.desc = d or "" - self.long = lng or "" - self.short = sh or l[1] - self.kind = k or Kind.arg - self.handler = h or function() - print(l, s) - end - self.value = v or nil - self.help = Arg.help(self) - return self -end - -function Arg:help(h) - if self.kind == Kind.cmd then - return "" - .. m - .. self.short - .. "" - .. x - .. " " - .. down.bits.pipe - .. " " - .. m - .. self.long:sub(1, 1) - .. x - .. self.long:sub(2) - .. "\t " - .. self.desc - elseif self.kind == Kind.opt.flag then - return "" - .. down.bits.hy - .. r - .. self.short - .. x - .. " " - .. down.bits.pipe - .. " " - .. down.bits.hy2 - .. r - .. self.long:sub(1, 1) - .. x - .. self.long:sub(2) - .. "\t " - .. self.desc - else - print(self.long, self.short) - end -end - -function Arg:isopt() - return self.kind == Kind.opt.param or self.kind == Kind.opt.flag -end - -function Arg:check(a, k) - if a == self.long and k == Arg.Kind.opt.flag.long.long then - return true - elseif a == self.short and k == Arg.Kind.opt.flag.short.short then - return true - elseif a == self.short and k == Arg.Kind.cmd.short then - return true - elseif a == self.long and k == Arg.Kind.cmd.long then - return true - end - return false -end - -function Arg:handle(a, k) - if Arg.check(self, a, k) then - return self.handler() - end -end - ---+--------------------+ handlers +--------------------+-- ---| |-- ---| define handler functions. |-- ---| |-- ---+----------------------------------------------------+-- - -local function test(...) - print("test") -end - -local function conf(...) - print("conf") -end - ---+----------------------+ func +----------------------+-- ---| |-- ---| define core functions. |-- ---| |-- ---+----------------------------------------------------+-- - -down.opts = {} -down.args = {} - -down.help = { - header = { - print = function(pre, h) - print("\n" .. pre .. " " .. h .. " ") - end, - info = "󰯂 INFO ", - cmds = " CMDS ", - args = "󰆧 ARGS ", - flag = "󰷐 FLAGS", - opts = "󰆧 OPTS ", - usage = "󰒓 USAGE", - }, - down = function() - print("\n" .. down.bits.downi .. " " .. x .. down.bits.version) - -- print(b .. " author " .. x .. " " .. down.bits.author) - -- print(b .. " repo " .. x .. " " .. down.repo) - -- print(b .. " home " .. x .. " " .. down.home) - end, - info = function() - down.help.header.print(bbg, down.help.header.info) - print(bg .. "" .. x .. " " .. down.bits.desc) - end, - usage = function() - down.help.header.print(bbb, down.help.header.usage) - print(bb .. "" .. x .. " " .. down.bits.usage) - end, - cmds = function() - down.help.header.print(bbm, down.help.header.cmds) - for _, v in pairs(down.cmds) do - print(bm .. "" .. x .. " " .. Arg.help(v)) - end - end, - flags = function() - down.help.header.print(bbr, down.help.header.flag) - for _, v in pairs(down.flags) do - print(br .. "" .. x .. " " .. Arg.help(v)) - end - end, - opts = function() - down.help.header.print(bbm, down.help.header.opts) - print(br .. "" .. x .. " " .. x .. r .. down.bits.ellipses) - end, - args = function() - down.help.header.print(bbr, down.help.header.args) - print(bm .. "" .. x .. " " .. x .. m .. down.bits.ellipses) - end, -} -down.help.print = function() - down.help.down() - down.help.info() - down.help.usage() - down.help.cmds() - down.help.flags() - -- down.help.opts() - -- down.help.args() -end -down.flags = { - version = Arg.flag("version", "Print version", function() - print(down.version) - end), - debug = Arg.flag("debug", "Set debug", function() - print("debug") - end), - config = Arg.flag("config", "Specify config file", function(...) - print("config") - end), - stdout = Arg.flag("stdout", "Set stdout output", function() - print("stdout") - end), - profile = Arg.flag("color", "Set color output", function() - print("color") - end), - help = Arg.flag("help", "Print help", down.help.print), -} - -down.cmds = { - init = Arg.cmd("init", "Initialize workspace", function() - print("init") - end), - upgrade = Arg.cmd("upgrade", "Upgrade binary", function() - print("upgrade") - end), - run = Arg.cmd("run", "Run the lsp", function(...) - print("run") - end), - -- version = Arg.cmd("version", "Print version", down.flags.version.desc, down.flags.version.handler), - config = Arg.cmd("config", "Set config values", down.flags.config.handler), - help = Arg.cmd("help", "Print help", down.flags.help.handler), -} - ---+---------------------+ parse +---------------------+-- ---| |-- ---| define parse functions. |-- ---| |-- ---+---------------------------------------------------+-- - ---- @param a string arg -function down:pflag(a, k) - local ok = false - for _, v in pairs(self.flags) do - if Arg.check(v, a, k) then - ok = true - return Arg.handle(v, a, k) - end - end - if ok == false then - Arg.Kind.unknown(a, k) - end -end - ---- @param a string arg -function down:pcmd(a, k) - local ok = false - for _, v in pairs(self.cmds) do - if Arg.check(v, a, k) then - ok = true - return Arg.handle(v, a, k) - end - end - if ok == false then - return Arg.Kind.unknown(a, k) - end -end - ---- @param a string -function down:pstr(a) - local st, k = Arg.Kind.check(a) - if Arg.Kind.opt.isopt(k) then - return self:pflag(st, k) - elseif Arg.Kind.cmd.iscmd(k) then - return self:pcmd(st, k) - else - Arg.Kind.unknown(st, k) - end -end - ---- @return nil -function down:parse() - local i, a, ac = 1, arg, #arg - if ac == 0 then - return self.flags.help.handler() - end - for ai, a in ipairs(a) do - return self:pstr(a) - end -end - ---+----------------------+ main +----------------------+-- ---| |-- ---| define and call main function. |-- ---| |-- ---+----------------------------------------------------+-- - -function down:main() - self:parse() -end - -down:main() - ---+----------------------+ down +----------------------+-- ---| |-- ---| version 0.1.0-alpha. |-- ---| |-- ---| author: Chris Pecunies |-- ---| |-- ---+----------------------------------------------------+-- - ---vim:ft=lua,ts=2,sw=2,sts=2,et diff --git a/scripts/bin/down-lsp.sh b/scripts/bin/down-lsp.sh deleted file mode 100755 index 88bf19a..0000000 --- a/scripts/bin/down-lsp.sh +++ /dev/null @@ -1,386 +0,0 @@ -#!/usr/bin/env bash - -# +--------------------+ down-lsp +--------------------+ # -# | | # -# | down-lsp v0.1.0-alpha | # -# | | # -# | ABOUT | # -# | down-lsp is a dev-focused note-taking | # -# | environment for markdown, in development. | # -# | | # -# | USAGE | # -# | down-lsp [options] [file] | # -# | | # -# | OPTIONS | # -# | -h, --help Show help and exit | # -# | -v, --version Show version and exit | # -# | -i, --interactive Run in interactive mode | # -# | -e, --execute Run in execute mode | # -# | -c, --config Specify a config file | # -# | | # -# | ARGS | # -# | serve Run the server | # -# | init Initialize the server | # -# | shell Run the shell | # -# | update Update the server | # -# | install Install the server | # -# | uninstall Uninstall the server | # -# | config Configure the server | # -# | status Show the server status | # -# | start Start the server | # -# | stop Stop the server | # -# | restart Restart the server | # -# | | # -# | EXAMPLES | # -# | down-lsp serve | # -# | down-lsp shell | # -# | | # -# +----------------------------------------------------+ # -# -# +--------------------+ export +--------------------+ # -# | | # -# | define exports. | # -# | | # -# +----------------------------------------------------+ # - -export DOWN_LSP_BIN="down-lsp" -export DOWN_LSP_COMPLETIONS=$(head >/tmp/out.log - echo -e "$r" -} - -# param 1: id -# param 2: method -function lsp-handle() { - ID="$1" - METHOD="$2" - case $2 in - 'initialize') lsp-reply $ID '{ - "clientInfo": '"$DOWN_LSP_CLIENTINFO"', - "capabilities": '"$DOWN_LSP_CAPABILITIES"' - }' ;; - 'textDocument/moniker') lsp-reply "$ID" '[]' ;; - 'textDocument/codeLens') lsp-reply "$ID" '[]' ;; - 'textDocument/definition') lsp-reply "$ID" '[]' ;; - 'textDocument/documentHighlight') lsp-reply "$ID" '[]' ;; - 'textDocument/documentLink') lsp-reply "$ID" '[]' ;; - 'textDocument/publishDiagnostics') lsp-reply $ID '[]' ;; - 'textDocument/signatureHelp') lsp-reply $ID '{ - "signatures": [], - "activeSignature": 0, - "activeParameter": 0 - }' ;; - 'textDocument/completion') lsp-reply "$ID" '{ - "isIncomplete": false, - "items": '"$DOWN_LSP_COMPLETIONS"' - }' ;; - 'textDocument/rename') lsp-reply "$ID" 'null' ;; - 'textDocument/formatting') lsp-reply "$ID" '[]' ;; - 'textDocument/rangeFormatting') lsp-reply "$ID" '[]' ;; - 'textDocument/onTypeFormatting') lsp-reply "$ID" '[]' ;; - 'textDocument/prepareRename') lsp-reply "$ID" 'null' ;; - 'textDocument/hover') lsp-reply "$ID" '{ - "contents": { - "kind": "markdown", - "value": "```python\nhello world\n```" - } - }' ;; - esac - -} -function lsp-format() { - echo -e "" -} -lsp-test() { - echo -e "test..." -} - -function lsp-serve() { - echo -e "Serving at " $DOWN_LSP_PORT - while IFS= read -r LN; do - [[ "$LN" =~ ^Content-Length:\ ([0-9]+) ]] - LEN="${BASH_REMATCH[1]}" - LEN=$((len + 2)) - PAYLOAD=$(head -c "$LEN") - ID=$(echo -E "$PAYLOAD" | jq --raw-output '.id') - METHOD=$(echo -E "$PAYLOAD" | jq --raw-output '.method') - log $ID $METHOD - lsp-handle $ID $METHOD - done - -} - -# +--------------------+ style +----------------------+ # -# | | # -# | define style utilities. | # -# | | # -# +-----------------------------------------------------+ # - -X="\x1b[0m" # RESET -B="\x1b[1m" # BOLD -D="\x1b[2m" # DIM -I="\x1b[3m" # ITALIC -U="\x1b[4m" # UNDERLINE -L="\x1b[5m" # BLINK -R="\x1b[7m" # REVERSE -H="\x1b[8m" # HIDDEN -F="\x1b[9m" # STRIKE - -FL="\x1b[30m" # FG BLACK -FR="\x1b[31m" # FG RED -FG="\x1b[32m" # FG GREEN -FY="\x1b[33m" # FG YELLOW -FB="\x1b[34m" # FG BLUE -FM="\x1b[35m" # FG MAGENTA -FC="\x1b[36m" # FG CYAN -FW="\x1b[37m" # FG WHITE - -BL="\x1b[40m" # BG BLACK -BR="\x1b[41m" # BG RED -BG="\x1b[42m" # BG GREEN -BY="\x1b[43m" # BG YELLOW -BB="\x1b[44m" # BG BLUE -BM="\x1b[45m" # BG MAGENTA -BC="\x1b[46m" # BG CYAN -BW="\x1b[47m" # BG WHITE - -# +---------------------+ util +----------------------+ # -# | | # -# | define utility functions. | # -# | | # -# +-----------------------------------------------------+ # - -bold() { - echo -e "$B$1$X" -} -italic() { - echo -e "$I$1$X" -} -underline() { - echo -e "$U$1$X" -} -strike() { - echo -e "$F$1$X" -} -reverse() { - echo -e "$R$1$X" -} -blink() { - echo -e "$L$1$X" -} -dim() { - echo -e "$D$1$X" -} -color() { - echo -e "$2$1$X" -} -# 1: log -# 2: message -# 3: context -# 4: location -# 5: color -logs() { - DIV="$FW$R$D$L $X" - LOC="" - CTX="" - MSG="" - LOG="" - [[ -n "$1" ]] && LOG="$B$5$R $1 $X" || LOG="" - [[ -n "$2" ]] && MSG="$FW$D$2$X" || MSG="" - [[ -n "$3" ]] && CTX="$5$B$3$X" || CTX="" - [[ -n "$4" ]] && LOC="$FL$B($4)$X" || LOC="" - echo -e "$LOG $CTX $MSG $LOC" -} -LOC="" - -# 1: context -# 2: message -# 3: location -# 󰙅 󰍔 󱡠 󰆼  󰘧󰷐 -info() { - logs "󰍡 INF" $2 $1 "" "$FB" -} -log() { - logs "󰗚 LOG" $2 $1 "" $FW -} -dbg() { - logs "󰯂 DBG" $2 $1 "" $FM -} -hint() { - logs " HNT" $2 $1 "" $FG -} -warn() { - logs " WRN" $2 $1 "" $FY -} -err() { - logs "󰟢 ERR" $2 $1 "" $FR -} -lsp() { - logs "󰘧 LSP" $2 $1 "" $FM -} -down() { - logs "���������������������������������������� down" $2 $1 "" $FB -} -trace() { - logs "󰆧 TRC" $2 $1 "" $FM -} - -# +---------------------+ cmds +- --------------------+ # -# | | # -# | define command functions. | # -# | | # -# +-----------------------------------------------------+ # - -function down-help() { - echo -e "\x1b[1m\x1b[33m\x1b[7m 󰘧 down \x1b[0m" - echo -e "\x1b[1m\x1b[33m\x1b[7m \x1b[0m v0.1.0-alpha.2\n" - echo -e "\x1b[1m\x1b[32m\x1b[7m 󰯂 INFO \x1b[0m " - echo -e "\x1b[1m\x1b[32m\x1b[7m \x1b[0m down\x1b[0m is a dev-focused, familiar note-taking" - echo -e "\x1b[1m\x1b[32m\x1b[7m \x1b[0m environment for\x1b[32m 󰍔\x1b[0m\x1b[32m Markdown\x1b[0m, in development.\n" - echo -e "\x1b[1m\x1b[36m\x1b[7m 󰒓 USAGE \x1b[0m " - echo -e "\x1b[1m\x1b[36m\x1b[7m \x1b[0m down [options]\x1b[0m [file]\x1b[0m\n" - echo -e "\x1b[1m\x1b[34m\x1b[7m 󰆧 OPTS \x1b[0m " - echo -e "\x1b[1m\x1b[34m\x1b[7m \x1b[0m -h\x1b[0m, --help\x1b[0m Show help and exit" - echo -e "\x1b[1m\x1b[34m\x1b[7m \x1b[0m -v\x1b[0m, --version\x1b[0m Show version and exit " - echo -e "\x1b[1m\x1b[34m\x1b[7m \x1b[0m -d\x1b[0m, --debug \x1b[0m Run in debug mode " - echo -e "\x1b[1m\x1b[34m\x1b[7m \x1b[0m -c\x1b[0m, --config\x1b[0m Specify a config file\n" - echo -e "\x1b[1m\x1b[35m\x1b[7m 󰷐 CMDS \x1b[0m " - echo -e "\x1b[1m\x1b[35m\x1b[7m \x1b[0m serve | s Run the server " - echo -e "\x1b[1m\x1b[35m\x1b[7m \x1b[0m update | u Update the server " - echo -e "\x1b[1m\x1b[35m\x1b[7m \x1b[0m config | c Configure the server " - echo -e "\x1b[1m\x1b[35m\x1b[7m \x1b[0m help | h Show this help \n" - echo -e "\x1b[1m\x1b[31m\x1b[7m  ARGS \x1b[0m " - echo -e "\x1b[1m\x1b[31m\x1b[7m \x1b[0m [file] The file to open \n" -} -function show-help() { - echo -e " " - echo -e " $B$FY$R$D$L 󰘧 down-lsp $X v0.1.0-alpha.2 $X " - echo -e " " - echo -e " $B$FG$R$D$L 󰯂 ABOUT $X " - echo -e " down-lsp$X is a dev-focused note-taking " - echo -e " environment for$FG 󰍔$X$FG Markdown$X, in development. " - echo -e " " - echo -e " $B$FC$R$D$L 󰒓 USAGE $X " - echo -e " down-lsp$X [options]$X [file]$X " - echo -e " " - echo -e " $B$FB$R$D$L 󰆧 FLAGS $X " - echo -e " -h$X, $D--help$X Show help and exit " - echo -e " -v$X, $D--version$X Show version and exit " - echo -e " -i$X, $D--interactive$X Run in interactive mode " - echo -e " -e$X, $D--execute$X Run in execute mode " - echo -e " -c$X, $D--config$X Specify a config file " - echo -e " " - echo -e " $B$FM$R$D$L 󰷐 COMMAND $X " - echo -e " serve | s Run the server " - echo -e " update | u Update the server " - echo -e " config | c Configure the server " - echo -e " help | h Show this help " - echo -e " " - echo -e " $B$FR$R$D$L  ARG $X " - echo -e " [file] The file to open " - echo -e " " -} -function show-version() { - down "version" "0.0.1-alpha.1" -} -function shell() { - lsp "shell" "sh" -} - -function update() { - down "update" "..." -} - -# +---------------------+ main +----------------------+ # -# | | # -# | define and call main function. | # -# | | # -# +-----------------------------------------------------+ # - -function main() { - # if no subcommand, serve - - [[ $# -eq 0 ]] && lsp-serve - - case "$1" in - --markdown | -M | --md) DOWN_LSP_MARKDOWN=true ;; - --down | -D | --dn | --dwn) DOWN_LSP_DOWN=true ;; - --stdin | -i) DOWN_LSP_STDIN=true ;; - --config | -c) DOWN_LSP_CONFIG=$2 ;; - --stdio | -s) DOWN_LSP_STDIO=true ;; - --debug | -d) DOWN_LSP_DEBUG=true ;; - --port | -p) DOWN_LSP_PORT=$2 ;; - --host | -H) DOWN_LSP_HOST=$2 ;; - --console | -C) DOWN_LSP_CONSOLE=1 ;; - --style | -S) DOWN_LSP_STYLE=1 ;; - - serve | s | run | r) lsp-serve ;; - shell | sh) shell ;; - halp | --halp) show-help ;; - help | h | -h | --help) down-help ;; - test | t) lsp-test ;; - format | f) lsp-format ;; - version | v | --version | -v) show-version ;; - update | up | u) update ;; - esac -} - -main "$@" - -# +------------------+ down-lsp +---------------------+ # -# | | # -# | down-lsp v0.1.0-alpha.2 | # -# | | # -# | Chris Pecunies | # -# | | # -# +-----------------------------------------------------+ # - -#vim:ft=bash,ts=2,sw=2,sts=2,et diff --git a/scripts/bin/downls b/scripts/bin/downls deleted file mode 100755 index e253acb..0000000 --- a/scripts/bin/downls +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash - -NL=$'\r\n' -HEAD="Content-Length: " -CMP=$(head <"/usr/share/dict/words" -n 1000 | jq --raw-input --slurp 'split("\n")[:-1] | map({ label: . })') - -lsp-encode() { - local body="$1" - local len=${#body} - local resp="Content-Length: $len\r\n\r\n$body" - echo "$resp" >>/tmp/downls.log - echo -e "$resp" -} - -lsp-completions() { - echo '' -} - -lsp-notify() { - lsp-encode '{ - "method": "'"$1"'", - "params": '"$2"' - }' -} -lsp-reply() { - lsp-encode '{ - "jsonrpc": "2.0", - "id": '"$1"', - "result": '"$2"' - }' -} -lsp-req() { - lsp-encode '{ - "jsonrpc": "2.0", - "id": '"$1"', - "method": "'"$2"'", - "params": '"$3"' - }' -} -lsp-initialize() { - lsp-req "$1" "initialize" '{ - "rootPath": "/Users/clp/clp", - "workspaceFolders": [ - { - "uri": "file:///Users/clp/clp", - "name": "clp" - } - ], - }' -} - -lsp-handle() { - local id="$1" - case $2 in - 'initialize') lsp-reply id '{ - "serverInfo": { - "name": "downls", - "version": "0.1.2-alpha" - }, - "capabilities": { - "completionProvider": { - - }, - "hoverProvider": true, - "definitionProvider": true, - "workspaceSymbolProvider": true, - "workspace": { - "workspaceFolders": { - "supported": true, - "changeNotifications": true - } - }, - "textDocumentSync": 1 - } - }' ;; - 'workspace/configuration') lsp-reply id '{ - }' ;; - 'textDocument/completion') lsp-reply id '{ - "isIncomplete": false, - "items": '"$CMP"' - }' ;; - 'textDocument/codeAction') lsp-reply id '{ - }' ;; - 'textDocument/codeLens') lsp-reply id '{ - }' ;; - 'textDocument/definition') lsp-reply id '{ - }' ;; - 'textDocument/documentHighlight') lsp-reply id '{ - }' ;; - 'textDocument/documentSymbol') lsp-reply id '{ - }' ;; - 'textDocument/formatting') lsp-reply id '{ - }' ;; - 'shutdown') lsp-reply id 'null' ;; - 'exit') exit ;; - *) ;; - esac -} - -main() { - echo -e 'Starting lsp server' - while IFS= read -r line; do - [[ "$line" =~ ^Content-Length:\ ([0-9]+) ]] - len="${BASH_REMATCH[1]}" - len=$((len + 2)) - payload=$(head -c "$len") - echo -e "$payload $len $line" - id=$(echo -E "$payload" | jq -r '.id') - mt=$(echo -E "$payload" | jq -r '.method') - lsp-handle "$id" "$mt" - done -} - -main "$@" -#vim:ft=bash diff --git a/selene.toml b/selene.toml deleted file mode 100644 index 83ab4e8..0000000 --- a/selene.toml +++ /dev/null @@ -1,7 +0,0 @@ -std = "neovim" - -[rules] -global_usage = "follow" -mixed_table = "allow" -multiple_statements = "allow" -incorrect_standard_library_use = "allow" diff --git a/test/init.lua b/test/init.lua index b0f39fa..5a68b7c 100644 --- a/test/init.lua +++ b/test/init.lua @@ -7,7 +7,7 @@ T = {} ---@param config table? The configuration for the module. ---@return table T.down_setup = function(module, config) - local down = require("down") + local down = require('down') down.setup({ load = { base = {}, @@ -25,7 +25,7 @@ end function T.in_file(filename, content, cb) local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_name(buf, filename) - vim.api.nvim_buf_set_lines(buf, 0, -1, true, vim.split(content, "\n")) + vim.api.nvim_buf_set_lines(buf, 0, -1, true, vim.split(content, '\n')) cb(buf) @@ -33,3 +33,4 @@ function T.in_file(filename, content, cb) end return tests + diff --git a/lua/down/lsp/client/init.lua b/test/lsp/init.lua similarity index 100% rename from lua/down/lsp/client/init.lua rename to test/lsp/init.lua diff --git a/test/test.down b/test/test.down deleted file mode 100644 index e69de29..0000000 diff --git a/test/test.lua b/test/test.lua new file mode 100644 index 0000000..8c1a962 --- /dev/null +++ b/test/test.lua @@ -0,0 +1,35 @@ +#!/usr/bin/env lua + +T = {} + +--- Sets up down with a given module. +---@param module string The name of the module to load. +---@param config table? The configuration for the module. +---@return table +T.down_setup = function(module, config) + local down = require('down') + down.setup({ + load = { + base = {}, + [module] = { config = config }, + }, + }) + + return down +end + +--- Runs a callback in the context of a given file. +---@param filename string The name of the file (used to determine filetype) +---@param content string The content of the buffer. +---@param callback fun(bufnr: number) The function to execute with the buffer number provided. +function T.in_file(filename, content, cb) + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_name(buf, filename) + vim.api.nvim_buf_set_lines(buf, 0, -1, true, vim.split(content, '\n')) + + cb(buf) + + vim.api.nvim_buf_delete(buf, { force = true }) +end + +return T diff --git a/test/test.md b/test/test.md deleted file mode 100644 index ec329f2..0000000 --- a/test/test.md +++ /dev/null @@ -1,46 +0,0 @@ -# test - -## test 2 - -- [link](#test-3) -- [link to other](other.md) -- [link to url](https://github.com/clpi/down.lua) -- [file](./init.lua) - -> [!Note] -> -> This is a note - -### test 3 - -```lua -require("down").setup({ - mod = { - config = {}, - workspace = { - config = { - workspaces = { - home = "~/notes" - } - } - } - } -}) -``` -```mermaid -graph G - A-->B - A-->C - B-->D - C-->D -``` - -```mermaid -classDiagram -Mod <|-- Config : config -Mod : name string -Mod : hook() -Mod : user table -Mod : setup() -Config : version string -```