Skip to content

Commit

Permalink
moving around lsp mods
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 4, 2024
1 parent ca9c154 commit e299548
Show file tree
Hide file tree
Showing 37 changed files with 462 additions and 540 deletions.
2 changes: 1 addition & 1 deletion lua/word/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local C = {}
local osi = require("word.util").get_os_info()
local f = vim.fn

--- @type word.Config
--- @type word.mod.Config
C.config = {
---@type word.config.User
user = {
Expand Down
24 changes: 14 additions & 10 deletions lua/word/core/data/cache.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
---@class word.core.data.cache.Cache
---@field public head any
---@field public tail any
---@field public len integer
---@field public cache table<any, any>
---@field public cap integer
local Cache = {}

Cache.__index = Cache

function Cache.newcache() end

function Cache:new(cap)
return setmetatable({
cap = cap,
cache = setmetatable({
__index = self,
__newindex = function(k, v)
self[k] = v
end,
}, self.cache),
function Cache.new(cap)
local c = {
head = nil,
tail = nil,
len = 0,
}, Cache)
cap = cap,
cache = { }
}
return setmetatable({
__index = c,
}, c)
end

Cache.__len = function()
Expand Down
1 change: 1 addition & 0 deletions lua/word/core/data/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@class word.core.data.Data
local D = {}

D.cache = require("word.core.data.cache")
Expand Down
13 changes: 9 additions & 4 deletions lua/word/core/init.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
local C = {}

---@type word.core.parse.Parse
C.parse = require("word.core.parse")

---@type word.core.Graph
---@type word.core.graph.Graph
C.graph = require("word.core.graph")

---@type word.core.Node
C.node = require("word.core.graph").node
---@type word.core.graph.node.Node
C.node = require("word.core.graph.node")

---@type word.core.graph.edge.Edge
C.edge = require("word.core.graph").edge
C.edge = require("word.core.graph.edge")

---@type word.core.data.Data
C.data = require("word.core.data")

---@type word.core.data.cache.Cache
C.cache = require("word.core.data.cache")

return C
6 changes: 6 additions & 0 deletions lua/word/core/parse/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---@class word.core.parse.Parse
local P = {}



return P
7 changes: 3 additions & 4 deletions lua/word/mod/data/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
local M = require("word.mod").create("data", {
"log",
"mod",
"sync",
"dirs",
"tag",
"clipboard",
"template",
"metadata",
Expand All @@ -10,6 +12,7 @@ local M = require("word.mod").create("data", {
})

M.setup = function()
---@type word.mod.Setup
return {
loaded = true,
requires = {
Expand Down Expand Up @@ -78,15 +81,11 @@ M.data = {
--- Grabs the data present on disk and overwrites it with the data present in memory
sync = function()
local file = io.open(M.config.public.path, "r")

if not file then
return
end

local content = file:read("*a")

io.close(file)

local c = vim.mpack.decode(content)
M.data.data.data = vim.mpack.decode and vim.mpack.decode(content)
end,
Expand Down
3 changes: 3 additions & 0 deletions lua/word/mod/data/media/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local M = Mod.create("data.media")

---@class data.media.Data
M.data = {}

return M
73 changes: 38 additions & 35 deletions lua/word/mod/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Mod.default_mod = function(name)
events = {
subscribed = { -- The events that the init is subscribed to
},
defined = { -- The events that the init itself has defined
defined = { -- The events that the init itself has defined
},
},
required = {},
Expand All @@ -81,8 +81,8 @@ function Mod.create(name, imports)
if not Mod.load_mod(fullpath) then
log.error(
"Unable to load import '"
.. fullpath
.. "'! An error (see traceback below):"
.. fullpath
.. "'! An error (see traceback below):"
)
assert(false)
end
Expand Down Expand Up @@ -174,20 +174,20 @@ function Mod.load_mod_from_table(m)
-- Invoke the setup function. This function returns whether or not the loading of the init was successful and some metadata.
---@type word.mod.Setup
local mod_load = m.setup and m.setup()
or {
loaded = true,
replaces = {},
merge = false,
requires = {},
wants = {},
}
or {
loaded = true,
replaces = {},
merge = false,
requires = {},
wants = {},
}

-- 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"
.. m.name
.. "does not handle init loading correctly; init.setup() returned nil. Omitting..."
.. m.name
.. "does not handle init loading correctly; init.setup() returned nil. Omitting..."
)
return false
end
Expand Down Expand Up @@ -219,15 +219,15 @@ function Mod.load_mod_from_table(m)
if config.user.mod[req_mod] then
log.trace(
"Wanted init"
.. req_mod
.. "isn't loaded but can be as it's defined in the user's config. Loading..."
.. 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("word.util.log").error(
"Unable to load wanted init for"
.. m.name
.. "- the init didn't load successfully"
.. m.name
.. "- the init didn't load successfully"
)

-- Modake sure to clean up after ourselves if the init failed to load
Expand All @@ -236,7 +236,8 @@ 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!"):format(
("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
)
Expand Down Expand Up @@ -295,7 +296,8 @@ function Mod.load_mod_from_table(m)
-- If this flag has already been set before, then throw an error - there is no way for us to know which hotswapped init should take priority.
if mod_to_replace.replaced then
log.error(
("Unable to replace init %s - init replacement clashing detected. This error triggers when a init tries to be replaced more than two times - word doesn't know which replacement to prioritize."):format(
("Unable to replace init %s - init replacement clashing detected. This error triggers when a init tries to be replaced more than two times - word doesn't know which replacement to prioritize.")
:format(
mod_to_replace.name
)
)
Expand Down Expand Up @@ -346,7 +348,7 @@ function Mod.load_mod_from_table(m)
filename = "",
filehead = "",
cursor_position = { 0, 0 },
referrer = "",
referrer = m.name,
line_content = "",
content = m,
payload = m,
Expand Down Expand Up @@ -374,17 +376,18 @@ function Mod.load_mod(modn, cfg)
if not modl then
log.error(
"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!"
.. modn
.. "- 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"
.. 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!"
.. 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!"
)
return false
end
Expand All @@ -397,8 +400,8 @@ function Mod.load_mod(modn, cfg)
-- print(modl.config.custom, modl.config.public, config.mod[modn])
modl.config.custom = config.mod[modn]
modl.config.public =
-- vim.tbl_extend("force", modl.config.public, modl.config.custom or {})
utils.extend(modl.config.public, modl.config.custom or {})
-- vim.tbl_extend("force", modl.config.public, modl.config.custom or {})
utils.extend(modl.config.public, modl.config.custom or {})
end

-- Pass execution onto load_mod_from_table() and let it handle the rest
Expand Down Expand Up @@ -450,8 +453,8 @@ function Mod.get_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."
.. modn
.. "failed - init is not loaded."
)
return
end
Expand All @@ -474,8 +477,8 @@ function Mod.get_mod_version(modn)
if not Mod.is_mod_loaded(modn) then
log.trace(
"Attempt to get init version with name"
.. modn
.. "failed - init is not loaded."
.. modn
.. "failed - init is not loaded."
)
return
end
Expand All @@ -487,8 +490,8 @@ function Mod.get_mod_version(modn)
if not version then
log.trace(
"Attempt to get init version with name"
.. modn
.. "failed - version variable not present."
.. modn
.. "failed - version variable not present."
)
return
end
Expand Down Expand Up @@ -597,7 +600,7 @@ function Mod.create_event(m, type, content, ev)

-- Retrieve the template from init.events.defined
local event_template =
Mod.get_event_template(Mod.loaded_mod[modn] or { name = "" }, type)
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...")
Expand All @@ -623,7 +626,7 @@ function Mod.create_event(m, type, content, ev)
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]
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
Expand All @@ -641,8 +644,8 @@ function Mod.broadcast_event(event, callback)
if not event.split_type then
log.error(
"Unable to broadcast event of type"
.. event.type
.. "- invalid event name"
.. event.type
.. "- invalid event name"
)
return
end
Expand Down
1 change: 1 addition & 0 deletions lua/word/mod/lsp/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function C.setup()
}
end

---@class lsp.command.Config
C.config.public = {
}

Expand Down
1 change: 1 addition & 0 deletions lua/word/mod/lsp/completion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Completion
4 changes: 4 additions & 0 deletions lua/word/mod/lsp/completion/documentation/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ D.setup = function()
}
end

---@class lsp.completion.documentation.Data
D.data = {
}

return D
Loading

0 comments on commit e299548

Please sign in to comment.