Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: clean up object access #58

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lua/package-info/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ M.options = {
},
}

M.__get_command = {
M.get_command = {
--- Returns the delete command based on package manager
-- @param package-name - string
delete = function(package_name)
Expand Down Expand Up @@ -78,15 +78,15 @@ M.__get_command = {
end,
}

M.__namespace = {
M.namespace = {
id = "",
--- Registers the namespace for the plugin
register = function()
M.__namespace.id = vim.api.nvim_create_namespace("package-ui")
M.namespace.id = vim.api.nvim_create_namespace("package-ui")
end,
}

M.__state = {
M.state = {
displayed = M.options.autostart or false,
}

Expand Down Expand Up @@ -157,7 +157,7 @@ M.setup = function(user_options)
M.__register_autostart()
M.__register_256color_support()
M.__register_highlight_groups()
M.__namespace.register()
M.namespace.register()
end

return M
20 changes: 10 additions & 10 deletions lua/package-info/modules/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ M.__set_virtual_text = function(dependencies, outdated_dependencies)
local virtual_text = package_metadata.icon .. package_metadata.version
local position = dependency_positions[package_name]

vim.api.nvim_buf_set_extmark(0, config.__namespace.id, position, 0, {
vim.api.nvim_buf_set_extmark(0, config.namespace.id, position, 0, {
virt_text = { { virtual_text, package_metadata.group } },
virt_text_pos = "eol",
priority = 200,
Expand All @@ -164,14 +164,14 @@ M.show = function()
M.__set_virtual_text(dependencies.dev, outdated_dependencies_json)
M.__set_virtual_text(dependencies.prod, outdated_dependencies_json)

config.__state.displayed = true
config.state.displayed = true
end)
end

M.hide = function()
vim.api.nvim_buf_clear_namespace(0, config.__namespace.id, 0, -1)
vim.api.nvim_buf_clear_namespace(0, config.namespace.id, 0, -1)

config.__state.displayed = false
config.state.displayed = false
end

M.delete = function()
Expand All @@ -184,13 +184,13 @@ M.delete = function()
logger.error("No package under current line.")
else
ui.display_prompt({
command = config.__get_command.delete(package_name),
command = config.get_command.delete(package_name),
title = " Delete [" .. package_name .. "] Package ",
callback = function()
logger.info(package_name .. " deleted successfully")
vim.cmd(":e")

if config.__state.displayed then
if config.state.displayed then
M.hide()
M.show()
end
Expand All @@ -209,13 +209,13 @@ M.update = function()
logger.error("No package under current line.")
else
ui.display_prompt({
command = config.__get_command.update(package_name),
command = config.get_command.update(package_name),
title = " Update [" .. package_name .. "] Package ",
callback = function()
logger.info(package_name .. " updated successfully")
vim.cmd(":e")

if config.__state.displayed then
if config.state.displayed then
M.hide()
M.show()
end
Expand All @@ -233,15 +233,15 @@ M.install = function()
return
end

local command = config.__get_command.install(dependency_type, dependency_name)
local command = config.get_command.install(dependency_type, dependency_name)

vim.fn.jobstart(command, {
on_stdout = function(_, stdout)
if table.concat(stdout) == "" then
logger.info(dependency_name .. " installed successfully")
vim.cmd(":e")

if config.__state.displayed then
if config.state.displayed then
M.hide()
M.show()
end
Expand Down