feat: remove ow directory, keep ow in type annotations only

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