feat: remove ow directory, keep ow in type annotations only
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
|
|
||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
|
|
||||||
local files = {
|
local files = {
|
||||||
"globals",
|
"globals",
|
||||||
@@ -10,7 +10,7 @@ local files = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, file in ipairs(files) do
|
for _, file in ipairs(files) do
|
||||||
local pkg = "ow.core." .. file
|
local pkg = "core." .. file
|
||||||
local ok, err = pcall(require, pkg)
|
local ok, err = pcall(require, pkg)
|
||||||
if not ok then
|
if not ok then
|
||||||
log.error("Error while loading package " .. pkg)
|
log.error("Error while loading package " .. pkg)
|
||||||
@@ -19,7 +19,7 @@ for _, file in ipairs(files) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err = pcall(require, "ow.bootstrap")
|
local ok, err = pcall(require, "bootstrap")
|
||||||
if not ok then
|
if not ok then
|
||||||
log.error("Error during bootstrap")
|
log.error("Error during bootstrap")
|
||||||
log.error(err:gsub("\t", " "))
|
log.error(err:gsub("\t", " "))
|
||||||
@@ -60,4 +60,4 @@ local opts = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require("lazy").setup("ow.plugins", opts)
|
require("lazy").setup("plugins", opts)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ if version.major == 0 then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local util = require("ow.util")
|
local util = require("util")
|
||||||
|
|
||||||
-- Install lazy.nvim
|
-- Install lazy.nvim
|
||||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local Item = require("ow.dap.item")
|
local Item = require("dap.item")
|
||||||
local Node = require("ow.dap.hover.node")
|
local Node = require("dap.hover.node")
|
||||||
local Window = require("ow.dap.hover.window")
|
local Window = require("dap.hover.window")
|
||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
|
|
||||||
---@async
|
---@async
|
||||||
local function hover_async()
|
local function hover_async()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local Item = require("ow.dap.item")
|
local Item = require("dap.item")
|
||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
|
|
||||||
---@class ow.dap.hover.Node
|
---@class ow.dap.hover.Node
|
||||||
---@field lang string
|
---@field lang string
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local Content = require("ow.dap.hover.content")
|
local Content = require("dap.hover.content")
|
||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
|
|
||||||
---@class ow.dap.hover.Window
|
---@class ow.dap.hover.Window
|
||||||
---@field NAMESPACE string
|
---@field NAMESPACE string
|
||||||
@@ -14,7 +14,7 @@ local log = require("ow.log")
|
|||||||
local Window = {}
|
local Window = {}
|
||||||
Window.__index = Window
|
Window.__index = Window
|
||||||
|
|
||||||
Window.NAMESPACE = "ow.dap.hover.Window"
|
Window.NAMESPACE = "dap.hover.Window"
|
||||||
Window.NS_ID = vim.api.nvim_create_namespace(Window.NAMESPACE)
|
Window.NS_ID = vim.api.nvim_create_namespace(Window.NAMESPACE)
|
||||||
|
|
||||||
local function setup_highlights()
|
local function setup_highlights()
|
||||||
@@ -23,12 +23,7 @@ end
|
|||||||
---@param var dap.Variable
|
---@param var dap.Variable
|
||||||
---@return ow.dap.Item
|
---@return ow.dap.Item
|
||||||
function Item.from_var(var)
|
function Item.from_var(var)
|
||||||
return Item.new(
|
return Item.new(var.name, var.type, var.value, var.variablesReference)
|
||||||
var.name,
|
|
||||||
var.type,
|
|
||||||
var.value,
|
|
||||||
var.variablesReference
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Item
|
return Item
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
---@type fun(name: string, cfg: vim.lsp.Config)
|
---@type fun(name: string, cfg: vim.lsp.Config)
|
||||||
vim.lsp.config = vim.lsp.config
|
vim.lsp.config = vim.lsp.config
|
||||||
|
|
||||||
local keymap = require("ow.lsp.keymap")
|
local Keymap = require("lsp.keymap")
|
||||||
local linter = require("ow.lsp.linter")
|
local Linter = require("lsp.linter")
|
||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
local util = require("ow.util")
|
local util = require("util")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ function M.with_defaults(server, fn)
|
|||||||
default_cb(client, bufnr)
|
default_cb(client, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
keymap.set_defaults(bufnr)
|
Keymap.set_defaults(bufnr)
|
||||||
|
|
||||||
-- For document highlight
|
-- For document highlight
|
||||||
vim.cmd.highlight({ "link LspReferenceRead Visual", bang = true })
|
vim.cmd.highlight({ "link LspReferenceRead Visual", bang = true })
|
||||||
@@ -134,7 +134,7 @@ function M.setup()
|
|||||||
"zsh",
|
"zsh",
|
||||||
},
|
},
|
||||||
on_attach = M.with_defaults("bashls", function(_, bufnr)
|
on_attach = M.with_defaults("bashls", function(_, bufnr)
|
||||||
keymap.set(bufnr, {
|
Keymap.set(bufnr, {
|
||||||
{
|
{
|
||||||
mode = "n",
|
mode = "n",
|
||||||
lhs = "<leader>lf",
|
lhs = "<leader>lf",
|
||||||
@@ -164,7 +164,7 @@ function M.setup()
|
|||||||
},
|
},
|
||||||
single_file_support = true,
|
single_file_support = true,
|
||||||
on_attach = M.with_defaults("clangd", function(_, bufnr)
|
on_attach = M.with_defaults("clangd", function(_, bufnr)
|
||||||
linter.add(bufnr, {
|
Linter.add(bufnr, {
|
||||||
cmd = {
|
cmd = {
|
||||||
"clang-tidy",
|
"clang-tidy",
|
||||||
"-p=build",
|
"-p=build",
|
||||||
@@ -191,7 +191,7 @@ function M.setup()
|
|||||||
zero_idx_lnum = true,
|
zero_idx_lnum = true,
|
||||||
ignore_stderr = true,
|
ignore_stderr = true,
|
||||||
})
|
})
|
||||||
keymap.set(bufnr, {
|
Keymap.set(bufnr, {
|
||||||
{
|
{
|
||||||
mode = "n",
|
mode = "n",
|
||||||
lhs = "gs",
|
lhs = "gs",
|
||||||
@@ -215,7 +215,7 @@ function M.setup()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
on_attach = M.with_defaults("gopls", function(_, bufnr)
|
on_attach = M.with_defaults("gopls", function(_, bufnr)
|
||||||
keymap.set(bufnr, {
|
Keymap.set(bufnr, {
|
||||||
{
|
{
|
||||||
mode = "n",
|
mode = "n",
|
||||||
lhs = "<leader>lf",
|
lhs = "<leader>lf",
|
||||||
@@ -249,7 +249,7 @@ function M.setup()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
on_attach = M.with_defaults("intelephense", function(_, bufnr)
|
on_attach = M.with_defaults("intelephense", function(_, bufnr)
|
||||||
linter.add(bufnr, {
|
Linter.add(bufnr, {
|
||||||
cmd = {
|
cmd = {
|
||||||
"phpcs",
|
"phpcs",
|
||||||
"--standard=PSR12",
|
"--standard=PSR12",
|
||||||
@@ -271,7 +271,7 @@ function M.setup()
|
|||||||
zero_idx_lnum = true,
|
zero_idx_lnum = true,
|
||||||
})
|
})
|
||||||
|
|
||||||
keymap.set(bufnr, {
|
Keymap.set(bufnr, {
|
||||||
{
|
{
|
||||||
mode = "n",
|
mode = "n",
|
||||||
lhs = "<leader>lf",
|
lhs = "<leader>lf",
|
||||||
@@ -364,7 +364,7 @@ function M.setup()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
on_attach = M.with_defaults("lua_ls", function(_, bufnr)
|
on_attach = M.with_defaults("lua_ls", function(_, bufnr)
|
||||||
keymap.set(bufnr, {
|
Keymap.set(bufnr, {
|
||||||
{
|
{
|
||||||
mode = "n",
|
mode = "n",
|
||||||
lhs = "<leader>lf",
|
lhs = "<leader>lf",
|
||||||
@@ -425,7 +425,7 @@ function M.setup()
|
|||||||
|
|
||||||
vim.lsp.config("ruff", {
|
vim.lsp.config("ruff", {
|
||||||
on_attach = M.with_defaults("ruff", function(_, bufnr)
|
on_attach = M.with_defaults("ruff", function(_, bufnr)
|
||||||
keymap.set(bufnr, {
|
Keymap.set(bufnr, {
|
||||||
{
|
{
|
||||||
mode = "n",
|
mode = "n",
|
||||||
lhs = "<leader>lf",
|
lhs = "<leader>lf",
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
local util = require("ow.util")
|
local util = require("util")
|
||||||
|
|
||||||
---@class Keymap
|
---@class ow.lsp.Keymap
|
||||||
---@field mode string|string[]
|
---@field mode string|string[]
|
||||||
---@field lhs string
|
---@field lhs string
|
||||||
---@field rhs string|function
|
---@field rhs string|function
|
||||||
---@field opts? vim.keymap.set.Opts
|
---@field opts? vim.keymap.set.Opts
|
||||||
|
|
||||||
local M = {}
|
local Keymap = {}
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param keymaps Keymap[]
|
---@param keymaps ow.lsp.Keymap[]
|
||||||
function M.set(bufnr, keymaps)
|
function Keymap.set(bufnr, keymaps)
|
||||||
for _, keymap in ipairs(keymaps) do
|
for _, keymap in ipairs(keymaps) do
|
||||||
keymap.opts = vim.tbl_extend(
|
keymap.opts = vim.tbl_extend(
|
||||||
"force",
|
"force",
|
||||||
@@ -22,8 +22,8 @@ function M.set(bufnr, keymaps)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
function M.set_defaults(bufnr)
|
function Keymap.set_defaults(bufnr)
|
||||||
---@type Keymap[]
|
---@type ow.lsp.Keymap[]
|
||||||
local keymaps = {
|
local keymaps = {
|
||||||
{ mode = { "n" }, lhs = "<leader>df", rhs = vim.diagnostic.open_float },
|
{ mode = { "n" }, lhs = "<leader>df", rhs = vim.diagnostic.open_float },
|
||||||
{
|
{
|
||||||
@@ -105,7 +105,7 @@ function M.set_defaults(bufnr)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
M.set(bufnr, keymaps)
|
Keymap.set(bufnr, keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return Keymap
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
local util = require("ow.util")
|
local util = require("util")
|
||||||
|
|
||||||
---@class Linter
|
---@alias ow.lsp.linter.Group
|
||||||
---@field namespace number
|
|
||||||
---@field augroup number
|
|
||||||
---@field bufnr number
|
|
||||||
---@field config LinterConfig
|
|
||||||
M = {}
|
|
||||||
M.__index = M
|
|
||||||
|
|
||||||
---@alias Group
|
|
||||||
---| "lnum"
|
---| "lnum"
|
||||||
---| "end_lnum"
|
---| "end_lnum"
|
||||||
---| "col"
|
---| "col"
|
||||||
@@ -19,7 +11,7 @@ M.__index = M
|
|||||||
---| "source"
|
---| "source"
|
||||||
---| "code"
|
---| "code"
|
||||||
|
|
||||||
---@class JsonConfig
|
---@class ow.lsp.linter.JsonConfig
|
||||||
---@field diagnostics_root? string
|
---@field diagnostics_root? string
|
||||||
---@field lnum? string
|
---@field lnum? string
|
||||||
---@field end_lnum? string
|
---@field end_lnum? string
|
||||||
@@ -31,11 +23,11 @@ M.__index = M
|
|||||||
---@field code? string
|
---@field code? string
|
||||||
---@field callback? fun(diag: vim.Diagnostic)
|
---@field callback? fun(diag: vim.Diagnostic)
|
||||||
|
|
||||||
---@class DiagnosticTagMap
|
---@class ow.lsp.linter.DiagnosticTagMap
|
||||||
---@field unnecessary? string[]
|
---@field unnecessary? string[]
|
||||||
---@field deprecated? string[]
|
---@field deprecated? string[]
|
||||||
|
|
||||||
---@class LinterConfig
|
---@class ow.lsp.linter.Config
|
||||||
--- Command to run. The following keywords get replaces by the specified values:
|
--- Command to run. The following keywords get replaces by the specified values:
|
||||||
--- * %file% - path to the current file
|
--- * %file% - path to the current file
|
||||||
--- * %filename% - name of the current file
|
--- * %filename% - name of the current file
|
||||||
@@ -53,7 +45,7 @@ M.__index = M
|
|||||||
--- Regex pattern to parse diagnostic lines (required if not using json)
|
--- Regex pattern to parse diagnostic lines (required if not using json)
|
||||||
---@field pattern? string
|
---@field pattern? string
|
||||||
--- Named capture groups for pattern matching (required if not using json)
|
--- Named capture groups for pattern matching (required if not using json)
|
||||||
---@field groups? Group[]
|
---@field groups? ow.lsp.linter.Group[]
|
||||||
--- Map severity strings to vim diagnostic levels
|
--- Map severity strings to vim diagnostic levels
|
||||||
---@field severity_map? table<string, vim.diagnostic.Severity>
|
---@field severity_map? table<string, vim.diagnostic.Severity>
|
||||||
--- Source name for diagnostics (default: command name)
|
--- Source name for diagnostics (default: command name)
|
||||||
@@ -61,9 +53,9 @@ M.__index = M
|
|||||||
--- Debounce delay in ms (default: 100)
|
--- Debounce delay in ms (default: 100)
|
||||||
---@field debounce? number
|
---@field debounce? number
|
||||||
--- Configuration for JSON output parsing
|
--- Configuration for JSON output parsing
|
||||||
---@field json? JsonConfig
|
---@field json? ow.lsp.linter.JsonConfig
|
||||||
--- Map diagnostic codes to tags
|
--- Map diagnostic codes to tags
|
||||||
---@field tags? DiagnosticTagMap
|
---@field tags? ow.lsp.linter.DiagnosticTagMap
|
||||||
--- Line numbers are 0-indexed (default: false, 1-indexed)
|
--- Line numbers are 0-indexed (default: false, 1-indexed)
|
||||||
---@field zero_idx_lnum? boolean
|
---@field zero_idx_lnum? boolean
|
||||||
--- Column numbers are 0-indexed (default: false, 1-indexed)
|
--- Column numbers are 0-indexed (default: false, 1-indexed)
|
||||||
@@ -71,14 +63,21 @@ M.__index = M
|
|||||||
--- Don't log stderr as errors (default: false)
|
--- Don't log stderr as errors (default: false)
|
||||||
---@field ignore_stderr? boolean
|
---@field ignore_stderr? boolean
|
||||||
--- Post-process diagnostics
|
--- Post-process diagnostics
|
||||||
---@field hook? fun(self: Linter, diagnostics: vim.Diagnostic[])
|
---@field hook? fun(self: ow.lsp.Linter, diagnostics: vim.Diagnostic[])
|
||||||
M.config = {}
|
|
||||||
|
---@class ow.lsp.Linter
|
||||||
|
---@field namespace number
|
||||||
|
---@field augroup number
|
||||||
|
---@field bufnr number
|
||||||
|
---@field config ow.lsp.linter.Config
|
||||||
|
Linter = {}
|
||||||
|
Linter.__index = Linter
|
||||||
|
|
||||||
-- Extract a value from a JSON object using a path
|
-- Extract a value from a JSON object using a path
|
||||||
---@param obj table The JSON object
|
---@param obj table The JSON object
|
||||||
---@param path string Path to the value (dot notation string)
|
---@param path string Path to the value (dot notation string)
|
||||||
---@return any The value at the specified path, or nil if not found
|
---@return any The value at the specified path, or nil if not found
|
||||||
function M.get_json_value(obj, path)
|
function Linter.get_json_value(obj, path)
|
||||||
if not obj then
|
if not obj then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -110,7 +109,7 @@ end
|
|||||||
|
|
||||||
--- Clamp column to line length
|
--- Clamp column to line length
|
||||||
---@param diag vim.Diagnostic
|
---@param diag vim.Diagnostic
|
||||||
function M:clamp_col(diag)
|
function Linter:clamp_col(diag)
|
||||||
local lines =
|
local lines =
|
||||||
vim.api.nvim_buf_get_lines(self.bufnr, diag.lnum, diag.lnum + 1, false)
|
vim.api.nvim_buf_get_lines(self.bufnr, diag.lnum, diag.lnum + 1, false)
|
||||||
if #lines == 0 then
|
if #lines == 0 then
|
||||||
@@ -125,7 +124,7 @@ end
|
|||||||
|
|
||||||
--- Add diagnostic tags
|
--- Add diagnostic tags
|
||||||
---@param diag vim.Diagnostic
|
---@param diag vim.Diagnostic
|
||||||
function M:add_tags(diag)
|
function Linter:add_tags(diag)
|
||||||
if not self.config.tags then
|
if not self.config.tags then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -158,7 +157,7 @@ end
|
|||||||
|
|
||||||
--- Resolve 0/1-based indexing for lnum/col
|
--- Resolve 0/1-based indexing for lnum/col
|
||||||
---@param diag vim.Diagnostic
|
---@param diag vim.Diagnostic
|
||||||
function M:fix_indexing(diag)
|
function Linter:fix_indexing(diag)
|
||||||
if not self.config.zero_idx_lnum then
|
if not self.config.zero_idx_lnum then
|
||||||
if diag.lnum then
|
if diag.lnum then
|
||||||
diag.lnum = diag.lnum - 1
|
diag.lnum = diag.lnum - 1
|
||||||
@@ -180,13 +179,13 @@ function M:fix_indexing(diag)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:process_json_output(json)
|
function Linter:process_json_output(json)
|
||||||
---@type vim.Diagnostic[]
|
---@type vim.Diagnostic[]
|
||||||
local diagnostics = {}
|
local diagnostics = {}
|
||||||
|
|
||||||
local items = json
|
local items = json
|
||||||
if self.config.json.diagnostics_root then
|
if self.config.json.diagnostics_root then
|
||||||
items = M.get_json_value(json, self.config.json.diagnostics_root)
|
items = Linter.get_json_value(json, self.config.json.diagnostics_root)
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(items) ~= "table" then
|
if type(items) ~= "table" then
|
||||||
@@ -203,7 +202,7 @@ function M:process_json_output(json)
|
|||||||
|
|
||||||
for field, path in pairs(self.config.json) do
|
for field, path in pairs(self.config.json) do
|
||||||
if field ~= "diagnostics_root" and field ~= "callback" then
|
if field ~= "diagnostics_root" and field ~= "callback" then
|
||||||
diag[field] = M.get_json_value(item, path)
|
diag[field] = Linter.get_json_value(item, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -232,9 +231,9 @@ function M:process_json_output(json)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Validate input
|
--- Validate input
|
||||||
---@param config LinterConfig
|
---@param config ow.lsp.linter.Config
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.validate(config)
|
function Linter.validate(config)
|
||||||
local ok, resp = pcall(vim.validate, {
|
local ok, resp = pcall(vim.validate, {
|
||||||
config = { config, "table" },
|
config = { config, "table" },
|
||||||
})
|
})
|
||||||
@@ -308,7 +307,7 @@ function M.validate(config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@return boolean success
|
---@return boolean success
|
||||||
function M:run()
|
function Linter:run()
|
||||||
local input
|
local input
|
||||||
|
|
||||||
if self.config.stdin then
|
if self.config.stdin then
|
||||||
@@ -410,9 +409,9 @@ function M:run()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param config LinterConfig
|
---@param config ow.lsp.linter.Config
|
||||||
function M.add(bufnr, config)
|
function Linter.add(bufnr, config)
|
||||||
if not M.validate(config) then
|
if not Linter.validate(config) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -420,16 +419,13 @@ function M.add(bufnr, config)
|
|||||||
config.events = config.events or { "TextChanged", "TextChangedI" }
|
config.events = config.events or { "TextChanged", "TextChangedI" }
|
||||||
|
|
||||||
local linter = {
|
local linter = {
|
||||||
namespace = vim.api.nvim_create_namespace("ow.lsp.linter"),
|
namespace = vim.api.nvim_create_namespace("lsp.linter"),
|
||||||
augroup = vim.api.nvim_create_augroup(
|
augroup = vim.api.nvim_create_augroup("lsp.linter", { clear = false }),
|
||||||
"ow.lsp.linter",
|
|
||||||
{ clear = false }
|
|
||||||
),
|
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
config = config,
|
config = config,
|
||||||
}
|
}
|
||||||
|
|
||||||
linter = setmetatable(linter, M)
|
linter = setmetatable(linter, Linter)
|
||||||
|
|
||||||
local success = linter:run()
|
local success = linter:run()
|
||||||
if not success then
|
if not success then
|
||||||
@@ -456,4 +452,4 @@ function M.add(bufnr, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return Linter
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
---@type LazyPluginSpec
|
---@type LazyPluginSpec
|
||||||
return {
|
return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
config = require("ow.lsp").setup,
|
config = require("lsp").setup,
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ return {
|
|||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
end,
|
end,
|
||||||
build = (
|
build = (
|
||||||
require("ow.util").os_name ~= "Windows_NT"
|
require("util").os_name ~= "Windows_NT"
|
||||||
and "make install_jsregexp"
|
and "make install_jsregexp"
|
||||||
or nil
|
or nil
|
||||||
),
|
),
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
-- https://github.com/mfussenegger/nvim-dap
|
-- https://github.com/mfussenegger/nvim-dap
|
||||||
local log = require("ow.log")
|
local hover = require("dap.hover")
|
||||||
local hover = require("ow.dap.hover")
|
local log = require("log")
|
||||||
|
|
||||||
---@type LazyPluginSpec
|
---@type LazyPluginSpec
|
||||||
return {
|
return {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
local util = require("ow.util")
|
local util = require("util")
|
||||||
|
|
||||||
local function override_highlights()
|
local function override_highlights()
|
||||||
-- File Icon
|
-- File Icon
|
||||||
@@ -89,7 +89,7 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local signs = require("ow.lsp").diagnostic_signs
|
local signs = require("lsp").diagnostic_signs
|
||||||
require("nvim-tree").setup({
|
require("nvim-tree").setup({
|
||||||
on_attach = function(bufnr)
|
on_attach = function(bufnr)
|
||||||
local function opts(desc)
|
local function opts(desc)
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
local log = require("ow.log")
|
local log = require("log")
|
||||||
|
|
||||||
local M = {}
|
local Util = {}
|
||||||
|
|
||||||
M.os_name = vim.uv.os_uname().sysname
|
Util.os_name = vim.uv.os_uname().sysname
|
||||||
|
|
||||||
--- Get the module path of a file
|
--- Get the module path of a file
|
||||||
---@param file string
|
---@param file string
|
||||||
@@ -45,16 +45,16 @@ end
|
|||||||
--- Check that an executable is available
|
--- Check that an executable is available
|
||||||
--- @param exe string Array to look for
|
--- @param exe string Array to look for
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
function M.is_executable(exe)
|
function Util.is_executable(exe)
|
||||||
return vim.fn.executable(exe) == 1
|
return vim.fn.executable(exe) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check that at least one executable is available
|
--- Check that at least one executable is available
|
||||||
--- @param exes table Array of exes
|
--- @param exes table Array of exes
|
||||||
--- @return boolean
|
--- @return boolean
|
||||||
function M.any_installed(exes)
|
function Util.any_installed(exes)
|
||||||
for _, e in ipairs(exes) do
|
for _, e in ipairs(exes) do
|
||||||
if M.is_executable(e) then
|
if Util.is_executable(e) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -65,16 +65,16 @@ end
|
|||||||
--- Asserts that an executable is available
|
--- Asserts that an executable is available
|
||||||
--- Raises error if missing.
|
--- Raises error if missing.
|
||||||
--- @param exe string Array to look for
|
--- @param exe string Array to look for
|
||||||
function M.assert_installed(exe)
|
function Util.assert_installed(exe)
|
||||||
assert(M.is_executable(exe), "Missing executable '" .. exe .. "'.")
|
assert(Util.is_executable(exe), "Missing executable '" .. exe .. "'.")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Asserts that at least one executable is available
|
--- Asserts that at least one executable is available
|
||||||
--- Raises error if missing.
|
--- Raises error if missing.
|
||||||
--- @param exes table Array of exes
|
--- @param exes table Array of exes
|
||||||
function M.assert_any_installed(exes)
|
function Util.assert_any_installed(exes)
|
||||||
assert(
|
assert(
|
||||||
M.any_installed(exes),
|
Util.any_installed(exes),
|
||||||
"At least one of the following is required:\n"
|
"At least one of the following is required:\n"
|
||||||
.. table.concat(exes, ", ")
|
.. table.concat(exes, ", ")
|
||||||
)
|
)
|
||||||
@@ -82,8 +82,8 @@ end
|
|||||||
|
|
||||||
--- Asserts that a python module is installed
|
--- Asserts that a python module is installed
|
||||||
---@param mod string The python module to check
|
---@param mod string The python module to check
|
||||||
function M.python3_module_is_installed(mod)
|
function Util.python3_module_is_installed(mod)
|
||||||
if not M.is_executable("python3") then
|
if not Util.is_executable("python3") then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,8 +93,8 @@ end
|
|||||||
|
|
||||||
--- Asserts that a python module is installed
|
--- Asserts that a python module is installed
|
||||||
---@param mod string The python module to check
|
---@param mod string The python module to check
|
||||||
function M.assert_python3_module_installed(mod)
|
function Util.assert_python3_module_installed(mod)
|
||||||
if not M.python3_module_is_installed(mod) then
|
if not Util.python3_module_is_installed(mod) then
|
||||||
error("Python3 module " .. mod .. " not installed")
|
error("Python3 module " .. mod .. " not installed")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -102,7 +102,7 @@ end
|
|||||||
--- Attempts to load a module and logs errors on failure.
|
--- Attempts to load a module and logs errors on failure.
|
||||||
---@param module string The module to attempt to load.
|
---@param module string The module to attempt to load.
|
||||||
---@return any module The loaded module if successful, otherwise nil.
|
---@return any module The loaded module if successful, otherwise nil.
|
||||||
function M.try_require(module)
|
function Util.try_require(module)
|
||||||
local has_module, resp = pcall(require, module)
|
local has_module, resp = pcall(require, module)
|
||||||
|
|
||||||
if has_module then
|
if has_module then
|
||||||
@@ -115,7 +115,7 @@ end
|
|||||||
--- Checks if it is possible to require a module
|
--- Checks if it is possible to require a module
|
||||||
---@param module string
|
---@param module string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.has_module(module)
|
function Util.has_module(module)
|
||||||
local has_module, _ = pcall(require, module)
|
local has_module, _ = pcall(require, module)
|
||||||
return has_module
|
return has_module
|
||||||
end
|
end
|
||||||
@@ -144,7 +144,7 @@ end
|
|||||||
|
|
||||||
--- Format buffer
|
--- Format buffer
|
||||||
---@param opts FormatOptions
|
---@param opts FormatOptions
|
||||||
function M.format(opts)
|
function Util.format(opts)
|
||||||
opts = {
|
opts = {
|
||||||
cmd = opts.cmd,
|
cmd = opts.cmd,
|
||||||
output = opts.output,
|
output = opts.output,
|
||||||
@@ -308,7 +308,7 @@ end
|
|||||||
---@param kt type
|
---@param kt type
|
||||||
---@param vt type
|
---@param vt type
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_map(val, kt, vt)
|
function Util.is_map(val, kt, vt)
|
||||||
if type(val) ~= "table" then
|
if type(val) ~= "table" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -330,7 +330,7 @@ end
|
|||||||
---@param val any
|
---@param val any
|
||||||
---@param t? type
|
---@param t? type
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_list(val, t)
|
function Util.is_list(val, t)
|
||||||
if not vim.islist(val) then
|
if not vim.islist(val) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -352,11 +352,11 @@ end
|
|||||||
---@param val? any
|
---@param val? any
|
||||||
---@param t? type
|
---@param t? type
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_list_or_nil(val, t)
|
function Util.is_list_or_nil(val, t)
|
||||||
if val == nil then
|
if val == nil then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return M.is_list(val, t)
|
return Util.is_list(val, t)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -365,7 +365,7 @@ end
|
|||||||
---@param fn fun(...) Function to be debounced
|
---@param fn fun(...) Function to be debounced
|
||||||
---@param delay number Debounce delay in milliseconds
|
---@param delay number Debounce delay in milliseconds
|
||||||
---@return fun(...) function Debounced function
|
---@return fun(...) function Debounced function
|
||||||
function M.debounce(fn, delay)
|
function Util.debounce(fn, delay)
|
||||||
---@type uv_timer_t?
|
---@type uv_timer_t?
|
||||||
local timer = nil
|
local timer = nil
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ end
|
|||||||
---@param fn fun(...) Function to be debounced
|
---@param fn fun(...) Function to be debounced
|
||||||
---@param delay number Debounce delay in milliseconds
|
---@param delay number Debounce delay in milliseconds
|
||||||
---@return fun(id: any, ...) function Debounced function, where `id` is a unique identifier
|
---@return fun(id: any, ...) function Debounced function, where `id` is a unique identifier
|
||||||
function M.debounce_with_id(fn, delay)
|
function Util.debounce_with_id(fn, delay)
|
||||||
local map = {}
|
local map = {}
|
||||||
|
|
||||||
return function(id, ...)
|
return function(id, ...)
|
||||||
@@ -405,7 +405,7 @@ function M.debounce_with_id(fn, delay)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_hl_source(name)
|
function Util.get_hl_source(name)
|
||||||
local hl = vim.api.nvim_get_hl(0, { name = name })
|
local hl = vim.api.nvim_get_hl(0, { name = name })
|
||||||
while hl.link do
|
while hl.link do
|
||||||
hl = vim.api.nvim_get_hl(0, { name = hl.link })
|
hl = vim.api.nvim_get_hl(0, { name = hl.link })
|
||||||
@@ -414,4 +414,4 @@ function M.get_hl_source(name)
|
|||||||
return hl
|
return hl
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return Util
|
||||||
Reference in New Issue
Block a user