Skip to content

Commit

Permalink
feat: Support to starting the server. Legacy feature, soon deprecated.
Browse files Browse the repository at this point in the history
  • Loading branch information
barreiroleo committed Apr 28, 2024
1 parent c6f974c commit 38bf0ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
33 changes: 31 additions & 2 deletions lua/ltex_extra/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,45 @@ function LtexExtra:RegisterClientMethods()
vim.lsp.commands["_ltex.disableRules"] = require("ltex_extra.commands-lsp").disableRules
end

---@param opts Legacy_LtexExtraOpts
function LtexExtra:CheckLegacyOpts(opts)
local deprecated_in_use = {}
if opts.server_start then
table.insert(deprecated_in_use, "server_start")
end
if opts.server_opts then
table.insert(deprecated_in_use, "server_opts")
end
for _, opt in pairs(deprecated_in_use) do
vim.notify(string.format("[LtexExtra] %s will be deprecatd soon. Please consider updating your settings." ..
" Raise an issue at github.com/barreiroleo/ltex_extra.nvim if you have any concerns.", opt),
vim.log.levels.WARN)
end
end

---@deprecated
---@param opts LSPServerOpts
function LtexExtra:CallLtexServer(opts)
local ok, lspconfig = pcall(require, "lspconfig")
if not ok then
error("[LtexExtra] Cannot initialize ltex server. Lspconfig not found")
end
lspconfig["ltex"].setup(opts)
end

function ltex_extra_api.setup(opts)
opts = vim.tbl_deep_extend("force", legacy_opts, opts or {})
opts.path = vim.fs.normalize(opts.path)
-- Initialize the logger
LoggerBuilder:new({ logLevel = opts.log_level, usePlenary = true })
LtexExtra:new(opts)
-- Create LtexExtra commands
LtexExtra:RegisterAutocommands()
-- Register client side commands
LtexExtra:RegisterClientMethods()
-- Legacy support for server start. Deprecated soon.
if opts.server_start and opts.server_opts then
LtexExtra:CallLtexServer(opts.server_opts)
end
vim.schedule(function() LtexExtra:CheckLegacyOpts(opts) end)
return true
end

Expand Down
9 changes: 7 additions & 2 deletions lua/ltex_extra/opts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
---@field log_level LogLevel
---@field path string Path to store dictionaries. Relative to CWD or absolute

---@deprecated
---@alias server_start boolean
---@deprecated
---@alias server_opts LSPServerOpts|nil
---
---@class Legacy_LtexExtraOpts: LtexExtraOpts
---@field init_check boolean Perform a scan inmediatelly after load the dictionaries
---@field server_start boolean Enable the call to ltex. Usefull for migration and test
---@field server_start server_start Enable the call to ltex. Usefull for migration and test
---@field server_opts LSPServerOpts|nil


Expand All @@ -28,7 +33,7 @@ local legacy_opts = {
log_level = "none",
path = "",
---@deprecated
server_start = true,
server_start = false,
---@deprecated
server_opts = nil,
}
Expand Down

0 comments on commit 38bf0ce

Please sign in to comment.