refactor: restructure polish module from single file to modular directory format

Signed-off-by: User <user@example.com>
This commit is contained in:
User 2025-10-11 19:26:47 +00:00
parent 6f1adc9381
commit 459fa712d9
3 changed files with 49 additions and 33 deletions

View File

@ -24,4 +24,4 @@ if not pcall(require, "lazy") then
end
require "lazy_setup"
require "polish"
require "polish.init"

View File

@ -1,9 +1,5 @@
--- @meta
--- Framework-specific tool configurations and installation utilities for Neovim.
--- This module provides automatic installation of language servers and tools
--- based on the current development framework environment.
--- It reads the FRAMEWORK environment variable to determine which tools to install.
--- Mason package installation utilities for Neovim.
--- This module provides functions for installing Mason packages based on framework environment.
--- @alias FrameworkName "python"|"vue"|string
@ -44,7 +40,7 @@ local FRAMEWORK_TOOLS = {
--- returns an empty table.
--- @return string[] tools List of tools to install for the detected framework, or empty table if no framework is set
local function get_framework_tools()
local current_framework = os.getenv("FRAMEWORK")
local current_framework = os.getenv "FRAMEWORK"
if current_framework then
local tools = FRAMEWORK_TOOLS[current_framework]
@ -62,9 +58,7 @@ end
local function is_valid_package_name(package_name)
-- Basic validation: package names should only contain alphanumeric characters, hyphens, and dots
-- This prevents command injection attacks
if type(package_name) ~= "string" or package_name == "" then
return false
end
if type(package_name) ~= "string" or package_name == "" then return false end
-- Additional security: check for potentially dangerous patterns
local dangerous_patterns = {
@ -74,13 +68,11 @@ local function is_valid_package_name(package_name)
"%&", -- Background process
"%`", -- Command substitution
"%$", -- Variable expansion
"%!" -- History expansion
"%!", -- History expansion
}
for _, pattern in ipairs(dangerous_patterns) do
if string.match(package_name, pattern) then
return false
end
if string.match(package_name, pattern) then return false end
end
-- Check for valid characters: alphanumeric, hyphen, dot, underscore
@ -95,7 +87,6 @@ local function is_mason_available()
return mason_ok
end
--- Installs Mason packages based on the current framework environment.
--- This function retrieves the appropriate tool set and installs them one by one
--- to handle individual failures gracefully. Each package installation is wrapped
@ -121,9 +112,7 @@ function InstallMyMasonPackages()
vim.notify("Skipping invalid package name: " .. package, vim.log.levels.WARN)
failed_count = failed_count + 1
else
local success, result = pcall(function()
vim.cmd("MasonInstall " .. package)
end)
local success, result = pcall(function() vim.cmd("MasonInstall " .. package) end)
if success then
installed_count = installed_count + 1
@ -137,25 +126,29 @@ function InstallMyMasonPackages()
-- Provide summary
if failed_count == 0 then
vim.notify("Framework-specific packages installation completed successfully. Installed: " .. installed_count .. " packages", vim.log.levels.INFO)
vim.notify(
"Framework-specific packages installation completed successfully. Installed: " .. installed_count .. " packages",
vim.log.levels.INFO
)
else
vim.notify("Framework-specific packages installation completed with " .. failed_count .. " failures. Successfully installed: " .. installed_count .. " packages", vim.log.levels.WARN)
vim.notify(
"Framework-specific packages installation completed with "
.. failed_count
.. " failures. Successfully installed: "
.. installed_count
.. " packages",
vim.log.levels.WARN
)
end
else
vim.notify("No framework detected or no packages to install", vim.log.levels.INFO)
end
end
-- Create user command for Mason installation
vim.api.nvim_create_user_command(
"MasonInstallR", -- Command name
InstallMyMasonPackages, -- Function to call
{ nargs = 0 } -- Command takes no arguments
)
-- Module exports
return {
FRAMEWORK_TOOLS = FRAMEWORK_TOOLS,
get_framework_tools = get_framework_tools,
InstallMyMasonPackages = InstallMyMasonPackages,
}

23
lua/polish/init.lua Normal file
View File

@ -0,0 +1,23 @@
--- @meta
--- Framework-specific tool configurations and installation utilities for Neovim.
--- This module provides automatic installation of language servers and tools
--- based on the current development framework environment.
--- It reads the FRAMEWORK environment variable to determine which tools to install.
-- Import Mason utilities from separate module
local mason = require "polish.framework_mason_packages"
-- Create user command for Mason installation
vim.api.nvim_create_user_command(
"MasonInstallRorFramework", -- Command name
mason.InstallMyMasonPackages, -- Function to call
{ nargs = 0 } -- Command takes no arguments
)
-- Module exports
return {
FRAMEWORK_TOOLS = mason.FRAMEWORK_TOOLS,
get_framework_tools = mason.get_framework_tools,
InstallMyMasonPackages = mason.InstallMyMasonPackages,
}