From 950ff17b931c8e1ded75e07f6ea69ef857983210 Mon Sep 17 00:00:00 2001 From: Chris Pecunies Date: Wed, 4 Dec 2024 15:14:22 -0800 Subject: [PATCH] changing fileops to file, other scaffolding --- LICENSE | 2 +- book/src/index.md | 15 ++ book/src/modules/example.md | 3 +- lua/{word/init.lua => word.lua} | 0 lua/word/mod/integration/init.lua | 76 +++++- lua/word/mod/integration/trouble/init.lua | 33 +++ lua/word/mod/lsp/init.lua | 10 +- .../lsp/workspace/{fileops => file}/README.md | 0 .../lsp/workspace/{fileops => file}/init.lua | 4 +- lua/word/mod/lsp/workspace/init.lua | 2 +- lua/word/mod/lsp/workspace/tag/README.md | 0 lua/word/mod/lsp/workspace/tag/init.lua | 10 +- lua/word/mod/todo/init.lua | 251 ++++++++++++++++++ lua/word/mod/ui/nav/init.lua | 16 +- lua/word/mod/ui/status/init.lua | 21 +- lua/word/util/log.lua | 184 ------------- lua/word/util/log/init.lua | 183 +++++++++++++ scripts/bin/word-lsp | 38 +-- 18 files changed, 625 insertions(+), 223 deletions(-) rename lua/{word/init.lua => word.lua} (100%) rename lua/word/mod/lsp/workspace/{fileops => file}/README.md (100%) rename lua/word/mod/lsp/workspace/{fileops => file}/init.lua (94%) create mode 100644 lua/word/mod/lsp/workspace/tag/README.md create mode 100644 lua/word/mod/todo/init.lua delete mode 100644 lua/word/util/log.lua diff --git a/LICENSE b/LICENSE index 8d303c1..16a5d4d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Chris Pecunies +Copyright (c) 2024 Chris Pecunies Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/book/src/index.md b/book/src/index.md index e69de29..00a2f50 100644 --- a/book/src/index.md +++ b/book/src/index.md @@ -0,0 +1,15 @@ +# `word.lua` Book Index + +## About + +## Links + +## Roadmap + +### For next version + +### For future versions + +### For later future + +## Bugs diff --git a/book/src/modules/example.md b/book/src/modules/example.md index 9260e98..450b6a1 100644 --- a/book/src/modules/example.md +++ b/book/src/modules/example.md @@ -58,6 +58,5 @@ end return M ``` -- See [example.lua](../../lua/module/example.lua) - +- See [example.lua](../../lua/module/example.lua) diff --git a/lua/word/init.lua b/lua/word.lua similarity index 100% rename from lua/word/init.lua rename to lua/word.lua diff --git a/lua/word/mod/integration/init.lua b/lua/word/mod/integration/init.lua index 8e3f032..1126d78 100644 --- a/lua/word/mod/integration/init.lua +++ b/lua/word/mod/integration/init.lua @@ -1,5 +1,71 @@ -local E = require('word.mod').create('integration', { - 'treesitter', - 'telescope', - 'blink', -}) +---TODO: imelement +local E = require('word.mod').create('integration') + +--TODO: implement config to initialize sub integrations depending on user config + +---@class word.integration.Config +E.config.public = { + ---@brief List of integrations to disable (relative to the integration dir) + disabled = { + + }, + ---@brief List of integrations to enable (relative to the integration dir) + enabled = { + "telescope", + "treesitter", + } +} + +---@class word.integration.Data +E.data = { + +} + +---@param ext string +---@return string +E.data.get = function(ext) +end + +---TODO: implement +---Returns either a table of the loaded dependencies or nil of one is unsuccessful +---@return table|nil: the loaded dependency package +---@param ext string: the integration module to check +E.data.deps = function(ext) + return nil +end +E.data.enabled = { +} + +---@return boolean, nil|nil +---@param ext string +E.data.has = function(ext) + return pcall(require, ext) +end + +--- Generic setup function for integration submodules +--- @param ext string: the integration to setup +--- @param req table: the modules required by the integration module +--- @return word.mod.Setup +E.data.setup = function(ext, req) + local ok, e = E.data.has(ext) + if ok then return { + requies = req, + loaded = true + } + else return { + loaded = false + } + end +end + +E.setup = function() + local enabled = { + + } + return { + loaded = true, + requires = enabled + } +end + +return E diff --git a/lua/word/mod/integration/trouble/init.lua b/lua/word/mod/integration/trouble/init.lua index e69de29..e9ff6b7 100644 --- a/lua/word/mod/integration/trouble/init.lua +++ b/lua/word/mod/integration/trouble/init.lua @@ -0,0 +1,33 @@ +local mod = require "word.mod" +---@alias word.integration.trouble.Trouble word.Mod +local T = mod.create("integration.trouble") +local tok, t = pcall(require, "trouble") + +---@class word.integration.trouble.Data +T.data = { + +} + +T.setup = function() + if not tok then return { + loadeed = false + } + else return { + loaded = true, + requires = { + "ui", + "ui.win", + "ui.popup" + } + } + end +end + +---@class word.integration.trouble.Config +T.config.public = { + +} + + + +return T diff --git a/lua/word/mod/lsp/init.lua b/lua/word/mod/lsp/init.lua index 1965f9b..42783dd 100644 --- a/lua/word/mod/lsp/init.lua +++ b/lua/word/mod/lsp/init.lua @@ -94,7 +94,7 @@ M.setup = function() "lsp.document.format", "lsp.document.lens", "lsp.document", - "lsp.workspace.fileops", + "lsp.workspace.file", "lsp.document.semantic", "lsp.refactor", "lsp.document.action", @@ -139,8 +139,8 @@ M.data = { hover = Mod.get_mod("lsp.document.hover"), ---@type lsp.refactor refactor = Mod.get_mod("lsp.refactor"), - ---@type lsp.workspace.fileops - ws_fileops = Mod.get_mod("lsp.workspace.fileops"), + ---@type lsp.workspace.file + ws_file = Mod.get_mod("lsp.workspace.file"), ---@type lsp.workspace.edit ws_edit = Mod.get_mod("lsp.workspace.edit"), ---@type lsp.workspace.diagnostic @@ -320,7 +320,7 @@ M.load = function() }) end M.data.ts = Mod.get_mod("integration.treesitter") -M.data.workspace_fileops = Mod.get_mod("lsp.workspace.fileops") +M.data.workspace_file = Mod.get_mod("lsp.workspace.file") M.data.workspace = Mod.get_mod("workspace") M.data.lsp_ws = Mod.get_mod("lsp.workspace") M.data.lsp_doc = Mod.get_mod("lsp.document") @@ -371,7 +371,7 @@ end M.data.capabilities = { workspace = { ---@type lsp.FileOperationOptions - fileOperations = Mod.get_mod("lsp.workspace.fileops").opts, + fileOperations = Mod.get_mod("lsp.workspace.file").opts, workspaceFolders = Mod.get_mod("lsp.workspace.folders").server.capabilities, -- workspaceSymbolProvider = Mod.get_mod("lsp.workspace.symbol").opts, }, diff --git a/lua/word/mod/lsp/workspace/fileops/README.md b/lua/word/mod/lsp/workspace/file/README.md similarity index 100% rename from lua/word/mod/lsp/workspace/fileops/README.md rename to lua/word/mod/lsp/workspace/file/README.md diff --git a/lua/word/mod/lsp/workspace/fileops/init.lua b/lua/word/mod/lsp/workspace/file/init.lua similarity index 94% rename from lua/word/mod/lsp/workspace/fileops/init.lua rename to lua/word/mod/lsp/workspace/file/init.lua index be88195..cee5916 100644 --- a/lua/word/mod/lsp/workspace/fileops/init.lua +++ b/lua/word/mod/lsp/workspace/file/init.lua @@ -1,4 +1,4 @@ -local F = Mod.create("lsp.workspace.fileops") +local F = Mod.create("lsp.workspace.file") function F.setup() return { @@ -9,7 +9,7 @@ function F.setup() } end ----@class lsp.workspace.fileops +---@class lsp.workspace.file F.data = { ---@type lsp.FileOperationClientCapabilities capabilities = { diff --git a/lua/word/mod/lsp/workspace/init.lua b/lua/word/mod/lsp/workspace/init.lua index c1ce917..f23b39c 100644 --- a/lua/word/mod/lsp/workspace/init.lua +++ b/lua/word/mod/lsp/workspace/init.lua @@ -5,7 +5,7 @@ local M = Mod.create("lsp.workspace", { "folders", "edit", "diagnostic", - "fileops", + "file", "symbol", }) diff --git a/lua/word/mod/lsp/workspace/tag/README.md b/lua/word/mod/lsp/workspace/tag/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lua/word/mod/lsp/workspace/tag/init.lua b/lua/word/mod/lsp/workspace/tag/init.lua index a24a8bf..f672e44 100644 --- a/lua/word/mod/lsp/workspace/tag/init.lua +++ b/lua/word/mod/lsp/workspace/tag/init.lua @@ -1,4 +1,4 @@ -local M = Mod.create("lsp.workspace.tag") +local M = require("word.mod").create("lsp.workspace.tag") function M.setup() return { @@ -9,6 +9,12 @@ function M.setup() } end ----@class lsp.workspace.symbol +---@class word.lsp.workspace.tag.Data M.data = {} + +---@class word.lsp.workspace.tag.Config +M.config.public = { + enable = true, +} + return M diff --git a/lua/word/mod/todo/init.lua b/lua/word/mod/todo/init.lua new file mode 100644 index 0000000..74c11ee --- /dev/null +++ b/lua/word/mod/todo/init.lua @@ -0,0 +1,251 @@ +local word = require("word") + +local M = Mod.create("todo") + +M.maps = function() + Map.nmap(",wt", "Telescope word todo") +end + +M.data = { + data = { + namespace = vim.api.nvim_create_namespace("word/todo"), + + --- List of active buffers + buffers = {}, + }, +} +---@class base.todo +M.config.public = { + + -- Highlight group to display introspector in. + -- + -- base to "Normal". + highlight_group = "Normal", + + -- + -- base to the following: `done`, `pending`, `undone`, `urgent`. + counted_statuses = { + "done", + "pending", + "undone", + "urgent", + }, + + -- Which status should count towards the completed count (should be a subset of counted_statuses). + -- + -- base to the following: `done`. + completed_statuses = { + "done", + }, + + -- Callback to format introspector. Takes in two parameters: + -- * `completed`: number of completed tasks + -- * `total`: number of total counted tasks + -- + -- Should return a string with the format you want to display the introspector in. + -- + -- base to "[completed/total] (progress%)" + format = function(completed, total) + -- stylua: ignore start + return string.format( + "[%d/%d] (%d%%)", + completed, + total, + (total ~= 0 and math.floor((completed / total) * 100) or 0) + ) + -- stylua: ignore end + end, +} +M.setup = function() + return { + loaded = true, + requires = { "integration.treesitter" }, + } +end + +M.load = function() + vim.api.nvim_create_autocmd("Filetype", { + pattern = "markdown", + desc = "Attaches the TODO introspector to any word buffer.", + callback = function(ev) + local buf = ev.buf + + if M.data.data.buffers[buf] then + return + end + + M.data.data.buffers[buf] = true + -- M.public.attach_introspector(buf) -- TODO + end, + }) +end + +--- Attaches the introspector to a given word buffer. +--- Errors if the target buffer is not a word buffer. +---@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" + then + error( + string.format( + "Could not attach to buffer %d, buffer is not a word file!", + buffer + ) + ) + end + + M.required["integration.treesitter"].execute_query( + [[ + (_ + state: (detached_modifier_extension)) @item + ]], + function(query, id, node) + if query.captures[id] == "item" then + M.data.perform_introspection(buffer, node) + end + end, + buffer + ) + + vim.api.nvim_buf_attach(buffer, false, { + on_lines = vim.schedule_wrap(function(_, buf, _, first) + if not vim.api.nvim_buf_is_valid(buf) then + return + end + -- If we delete the last line of a file `first` will point to a nonexistent line + -- For this reason we fall back to the line count (accounting for 0-based indexing) + -- whenever a change to the document is made. + first = math.min(first, vim.api.nvim_buf_line_count(buf) - 1) + + ---@type TSNode? + local node = + M.required["integration.treesitter"].get_first_node_on_line(buf, first) + + if not node then + return + end + + vim.api.nvim_buf_clear_namespace( + buffer, + M.data.data.namespace, + first + 1, + first + 1 + ) + + local function introspect(start_node) + local parent = start_node + + while parent do + local child = parent:named_child(1) + + if child and child:type() == "detached_modifier_extension" then + M.data.perform_introspection(buffer, parent) + -- NOTE: do not break here as we want the introspection to propagate all the way up the syntax tree + end + + parent = parent:parent() + end + end + + introspect(node) + + local node_above = + M.required["integration.treesitter"].get_first_node_on_line( + buf, + first - 1 + ) + + do + local todo_status = node_above:named_child(1) + + if + todo_status and todo_status:type() == "detached_modifier_extension" + then + introspect(node_above) + end + end + end), + + on_detach = function() + vim.api.nvim_buf_clear_namespace(buffer, M.data.data.namespace, 0, -1) + M.data.data.buffers[buffer] = nil + end, + }) +end + +--- Aggregates TODO item counts from children. +---@param node TSNode +---@return number completed Total number of completed tasks +---@return number total Total number of counted tasks +function M.data.calculate_items(node) + local counts = {} + for _, status in ipairs(M.config.public.counted_statuses) do + counts[status] = 0 + end + + local total = 0 + + -- Go through all the children of the current todo 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" + 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 not counts[type] then + break + end + + counts[type] = counts[type] + 1 + total = total + 1 + end + end + end + end + + local completed = 0 + for _, status in ipairs(M.config.public.completed_statuses) do + if counts[status] then + completed = completed + counts[status] + end + end + + return completed, total +end + +--- Displays the amount of done items in the form of an extmark. +---@param buffer number +---@param node TSNode +function M.data.perform_introspection(buffer, node) + local completed, total = M.data.calculate_items(node) + + local line, col = node:start() + + vim.api.nvim_buf_clear_namespace( + buffer, + M.data.data.namespace, + line, + line + 1 + ) + + if total == 0 then + return + end + + vim.api.nvim_buf_set_extmark(buffer, M.data.data.namespace, line, col, { + virt_text = { + { + M.config.public.format(completed, total), + M.config.public.highlight_group, + }, + }, + invalidate = true, + }) +end + +return init diff --git a/lua/word/mod/ui/nav/init.lua b/lua/word/mod/ui/nav/init.lua index 185c9f6..1fe315e 100644 --- a/lua/word/mod/ui/nav/init.lua +++ b/lua/word/mod/ui/nav/init.lua @@ -1,3 +1,17 @@ -local M = Mod.create("ui.nav") +local mod = require("word.mod") + +local M = mod.create("ui.nav") + +M.setup = function() + return { + loaded = true, + requires = {}, + } +end + +---@class word.ui.nav.Data +M.data = {} +---@class word.ui.nav.Config +M.config.public = {} return M diff --git a/lua/word/mod/ui/status/init.lua b/lua/word/mod/ui/status/init.lua index 710346e..aa54a2f 100644 --- a/lua/word/mod/ui/status/init.lua +++ b/lua/word/mod/ui/status/init.lua @@ -1,3 +1,22 @@ -local M = Mod.create("ui.status") +local mod = require("word.mod") + +local M = mod.create("ui.status") + +M.setup = function() return { + loaded = true, + requires = { + + } +} end + +---@class word.ui.status.Config +M.config.public = { + +} + +---@class word.ui.status.Data +M.data = { + +} return M diff --git a/lua/word/util/log.lua b/lua/word/util/log.lua deleted file mode 100644 index 3333a6c..0000000 --- a/lua/word/util/log.lua +++ /dev/null @@ -1,184 +0,0 @@ ---- @alias LogLevel ---- | "trace" ---- | "debug" ---- | "info" ---- | "warn" ---- | "error" ---- | "fatal" - ---- @class (exact) word.log.Config ---- @field plugin string Name of the plugin. Prepended to log messages. ---- @field use_console boolean Whether to print the output to Neovim while running. ---- @field highlights boolean Whether highlighting should be used in console (using `:echohl`). ---- @field use_file boolean Whether to write output to a file. ---- @field level LogLevel Any messages above this level will be logged. ---- @field modes ({ name: LogLevel, hl: string, level: number })[] Level config. ---- @field float_precision number Can limit the number of decimals displayed for floats. - -local vl, a, lvl, ext = vim.log, vim.api, vim.log.levels, vim.tbl_deep_extend - ---- User config section ---- @type word.log.Config -local default_config = { - plugin = "word", - - use_console = true, - - highlights = true, - - use_file = true, - - level = "warn", - - modes = { - { name = "trace", hl = "Comment", level = lvl.TRACE }, - { name = "debug", hl = "Comment", level = lvl.DEBUG }, - { name = "info", hl = "None", level = lvl.INFO }, - { name = "warn", hl = "WarningMsg", level = lvl.WARN }, - { name = "error", hl = "ErrorMsg", level = lvl.ERROR }, - { name = "fatal", hl = "ErrorMsg", level = 5 }, - }, - - float_precision = 0.01, -} - --- {{{ NO NEED TO CHANGE -local Log = {} - -Log.get_default_config = function() - return require("word.config.default") -end -Log.get_base_config = function() - return default_config -end - --- local unpack = unpack or table.unpack - -Log.debug = function(inp) - -- print("ERROR: ", inp) -end -Log.warn = function(inp) - -- print("ERROR: ", inp) -end -Log.info = function(inp) - -- print("ERROR: ", inp) -end -Log.error = function(inp) - -- print("ERROR: ", inp) -end -Log.trace = function(inp) - -- print("TRACE: ", inp) -end - ---- @paraM.config.public word.log.config ---- @param standalone boolean -Log.new = function(config, standalone) - config = ext("force", default_config, config) - config.plugin = "word" -- Force the plugin name to be word - - local outfile = string.format( - "%s/%s.log", - a.nvim_call_function("stdpath", { "data" }), - config.plugin - ) - - local obj = standalone ~= nil and log or {} - - local levels = {} - for _, v in ipairs(config.modes) do - levels[v.name] = v.level - end - - local round = function(x, increment) - increment = increment or 1 - x = x / increment - return (x > 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)) * increment - end - - local make_string = function(...) - local t = {} - for i = 1, select("#", ...) do - local x = select(i, ...) - - if type(x) == "number" and config.float_precision then - x = tostring(round(x, config.float_precision)) - elseif type(x) == "table" then - x = vim.inspect(x) - else - x = tostring(x) - end - - t[#t + 1] = x - end - return table.concat(t, " ") - end - - local log_at_level = function(level_config, message_maker, ...) - -- Return early if we"re below the config.level - if levels[level_config.name] < levels[config.level] then - return - end - local nameupper = level_config.name:upper() - - local msg = message_maker(...) - local info = debug.getinfo(2, "Sl") - local lineinfo = info.short_src .. ":" .. info.currentline - - -- Output to console - if config.use_console then - local v = - string.format("(%s)\n%s\n%s", os.date("%H:%M:%S"), lineinfo, msg) - - if config.highlights and level_config.hl then - (vim.schedule_wrap(function() - vim.cmd(string.format("echohl %s", level_config.hl)) - end))() - end - - (vim.schedule_wrap(function() - vim.notify( - string.format("[%s] %s", config.plugin, vim.fn.escape(v, '"')), - level_config.level - ) - -- vim.cmd(string.format([[echom "[%s] %s"]], config.plugin, vim.fn.escape(v, '"'))) - end))() - - if config.highlights and level_config.hl then - (vim.schedule_wrap(function() - vim.cmd("echohl NONE") - end))() - end - end - - -- Output to log file - if config.use_file then - local fp = assert(io.open(outfile, "a")) - local str = - string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg) - fp:write(str) - fp:close() - end - end - - for _, x in ipairs(config.modes) do - obj[x.name] = function(...) - return log_at_level(x, make_string, ...) - end - - obj[("fmt_%s"):format(x.name)] = function() - return log_at_level(x, function(...) - local passed = { ... } - local fmt = table.remove(passed, 1) - local inspected = {} - for _, v in ipairs(passed) do - table.insert(inspected, vim.inspect(v)) - end - return string.format(fmt, table.unpack(inspected)) - end) - end - end -end - --- }}} - -return Log diff --git a/lua/word/util/log/init.lua b/lua/word/util/log/init.lua index e69de29..b7cb160 100644 --- a/lua/word/util/log/init.lua +++ b/lua/word/util/log/init.lua @@ -0,0 +1,183 @@ +--- @alias LogLevel +--- | "trace" +--- | "debug" +--- | "info" +--- | "warn" +--- | "error" +--- | "fatal" + +--- @class (exact) word.log.Config +--- @field plugin string Name of the plugin. Prepended to log messages. +--- @field use_console boolean Whether to print the output to Neovim while running. +--- @field highlights boolean Whether highlighting should be used in console (using `:echohl`). +--- @field use_file boolean Whether to write output to a file. +--- @field level LogLevel Any messages above this level will be logged. +--- @field modes ({ name: LogLevel, hl: string, level: number })[] Level config. +--- @field float_precision number Can limit the number of decimals displayed for floats. + +local vl, a, lvl, ext = vim.log, vim.api, vim.log.levels, vim.tbl_deep_extend + +--- User config section +--- @type word.log.Config +local default_config = { + plugin = "word", + + use_console = true, + + highlights = true, + + use_file = true, + + level = "warn", + + modes = { + { name = "trace", hl = "Comment", level = lvl.TRACE }, + { name = "debug", hl = "Comment", level = lvl.DEBUG }, + { name = "info", hl = "None", level = lvl.INFO }, + { name = "warn", hl = "WarningMsg", level = lvl.WARN }, + { name = "error", hl = "ErrorMsg", level = lvl.ERROR }, + { name = "fatal", hl = "ErrorMsg", level = 5 }, + }, + + float_precision = 0.01, +} + +local Log = {} + +Log.get_default_config = function() + return require("word.config.default") +end +Log.get_base_config = function() + return default_config +end + +-- local unpack = unpack or table.unpack + +Log.debug = function(inp) + -- print("ERROR: ", inp) +end +Log.warn = function(inp) + -- print("ERROR: ", inp) +end +Log.info = function(inp) + -- print("ERROR: ", inp) +end +Log.error = function(inp) + -- print("ERROR: ", inp) +end +Log.trace = function(inp) + -- print("TRACE: ", inp) +end + +--- @paraM.config.public word.log.config +--- @param standalone boolean +Log.new = function(config, standalone) + config = ext("force", default_config, config) + config.plugin = "word" -- Force the plugin name to be word + + local outfile = string.format( + "%s/%s.log", + a.nvim_call_function("stdpath", { "data" }), + config.plugin + ) + + local obj = standalone ~= nil and Log or {} + + local levels = {} + for _, v in ipairs(config.modes) do + levels[v.name] = v.level + end + + local round = function(x, increment) + increment = increment or 1 + x = x / increment + return (x > 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)) * increment + end + + local make_string = function(...) + local t = {} + for i = 1, select("#", ...) do + local x = select(i, ...) + + if type(x) == "number" and config.float_precision then + x = tostring(round(x, config.float_precision)) + elseif type(x) == "table" then + x = vim.inspect(x) + else + x = tostring(x) + end + + t[#t + 1] = x + end + return table.concat(t, " ") + end + + local log_at_level = function(level_config, message_maker, ...) + -- Return early if we"re below the config.level + if levels[level_config.name] < levels[config.level] then + return + end + local nameupper = level_config.name:upper() + + local msg = message_maker(...) + local info = debug.getinfo(2, "Sl") + local lineinfo = info.short_src .. ":" .. info.currentline + + -- Output to console + if config.use_console then + local v = + string.format("(%s)\n%s\n%s", os.date("%H:%M:%S"), lineinfo, msg) + + if config.highlights and level_config.hl then + (vim.schedule_wrap(function() + vim.cmd(string.format("echohl %s", level_config.hl)) + end))() + end + + (vim.schedule_wrap(function() + vim.notify( + string.format("[%s] %s", config.plugin, vim.fn.escape(v, '"')), + level_config.level + ) + -- vim.cmd(string.format([[echom "[%s] %s"]], config.plugin, vim.fn.escape(v, '"'))) + end))() + + if config.highlights and level_config.hl then + (vim.schedule_wrap(function() + vim.cmd("echohl NONE") + end))() + end + end + + -- Output to log file + if config.use_file then + local fp = assert(io.open(outfile, "a")) + local str = + string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg) + fp:write(str) + fp:close() + end + end + + for _, x in ipairs(config.modes) do + obj[x.name] = function(...) + return log_at_level(x, make_string, ...) + end + + obj[("fmt_%s"):format(x.name)] = function() + return log_at_level(x, function(...) + local passed = { ... } + local fmt = table.remove(passed, 1) + local inspected = {} + for _, v in ipairs(passed) do + table.insert(inspected, vim.inspect(v)) + end + return string.format(fmt, table.unpack(inspected)) + end) + end + end +end + +-- }}} + +return Log diff --git a/scripts/bin/word-lsp b/scripts/bin/word-lsp index 4ea5598..bc8cebe 100755 --- a/scripts/bin/word-lsp +++ b/scripts/bin/word-lsp @@ -4,17 +4,17 @@ # ----------------------- exports ----------------------- -export word_LSP_BIN="word-lsp" -export word_LSP_COMPLETIONS=$(head