Skip to content

Commit 88a477c

Browse files
committed
feat: remove old deprecated API
The old Workspaces [add|remove|list|open] API has been deprecated for many months. This commit removes it from the API. This is a breaking change.
1 parent a29d26b commit 88a477c

File tree

1 file changed

+2
-57
lines changed

1 file changed

+2
-57
lines changed

lua/workspaces/init.lua

+2-57
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ M.add = function(path, name)
161161
end
162162
end
163163

164-
-- TODO: make this the default api in v1.0
164+
-- This function is a legacy of the older api, but it's not worth
165+
-- it to try to merge this with the add function. It works fine, don't touch it!
165166
-- currently it is a mess trying to get it to conform to the old api
166167
---@param name string|nil
167168
---@param path string|nil
@@ -285,15 +286,6 @@ M.name = function()
285286
return current_workspace
286287
end
287288

288-
local subcommands = {"add", "remove", "list", "open"}
289-
290-
local subcommand_complete = function(lead)
291-
return vim.tbl_filter(function(item)
292-
return vim.startswith(item, lead)
293-
end, subcommands)
294-
end
295-
296-
297289
local workspace_name_complete = function(lead)
298290
local workspaces = vim.tbl_filter(function(workspace)
299291
if lead == "" then return true end
@@ -310,59 +302,12 @@ M.workspace_complete = function(lead, _, _)
310302
return workspace_name_complete(lead)
311303
end
312304

313-
-- DEPRECATED: will be removed in v1.0
314-
-- used to provide autocomplete for user commands
315-
M.complete = function(lead, line, pos)
316-
-- remove the command name from the front
317-
line = string.sub(line, #"Workspaces " + 1)
318-
pos = pos - #"Workspaces "
319-
320-
-- completion for subcommands
321-
if #line == 0 then return subcommands end
322-
local index = string.find(line, " ")
323-
if not index or pos < index then
324-
return subcommand_complete(lead)
325-
end
326-
327-
local subcommand = string.sub(line, 1, index - 1)
328-
329-
-- completion not provided past 2 args
330-
if string.find(line, " ", index + 1) then return {} end
331-
332-
-- subcommand completion for remove and open
333-
if subcommand == "remove" or subcommand == "open" then
334-
return workspace_name_complete(lead)
335-
end
336-
337-
return {}
338-
end
339-
340-
-- entry point to the api from user commands
341-
-- subcommand is one of {add, remove, list, open}
342-
-- and arg1 and arg2 are optional. If set arg1 is a name and arg2 is a path
343-
M.parse_args = function(subcommand, arg1, arg2)
344-
notify.warn("The command :Workspaces [add|remove|list|open] is deprecated and will be removed in v1.0. Use :Workspaces[Add|Remove|List|Open] instead.")
345-
if subcommand == "add" then
346-
M.add(arg1, arg2)
347-
elseif subcommand == "remove" then
348-
M.remove(arg1)
349-
elseif subcommand == "list" then
350-
M.list()
351-
elseif subcommand == "open" then
352-
M.open(arg1)
353-
else
354-
notify.err(string.format("Invalid subcommand '%s'", subcommand))
355-
end
356-
end
357-
358305
-- run to setup user commands and custom config
359306
M.setup = function(opts)
360307
opts = opts or {}
361308
config = vim.tbl_deep_extend("force", {}, config, opts)
362309

363310
vim.cmd[[
364-
command! -nargs=+ -complete=customlist,v:lua.require'workspaces'.complete Workspaces lua require("workspaces").parse_args(<f-args>)
365-
366311
command! -nargs=* -complete=file WorkspacesAdd lua require("workspaces").add_swap(<f-args>)
367312
command! -nargs=? -complete=customlist,v:lua.require'workspaces'.workspace_complete WorkspacesRemove lua require("workspaces").remove(<f-args>)
368313
command! WorkspacesList lua require("workspaces").list()

0 commit comments

Comments
 (0)