From 459fa712d9367c785091d33733f10966ca5e0196 Mon Sep 17 00:00:00 2001 From: User Date: Sat, 11 Oct 2025 19:26:47 +0000 Subject: [PATCH] refactor: restructure polish module from single file to modular directory format Signed-off-by: User --- init.lua | 2 +- .../framework_mason_packages.lua} | 57 ++++++++----------- lua/polish/init.lua | 23 ++++++++ 3 files changed, 49 insertions(+), 33 deletions(-) rename lua/{polish.lua => polish/framework_mason_packages.lua} (75%) create mode 100644 lua/polish/init.lua diff --git a/init.lua b/init.lua index 424e48d..b72e913 100644 --- a/init.lua +++ b/init.lua @@ -24,4 +24,4 @@ if not pcall(require, "lazy") then end require "lazy_setup" -require "polish" +require "polish.init" diff --git a/lua/polish.lua b/lua/polish/framework_mason_packages.lua similarity index 75% rename from lua/polish.lua rename to lua/polish/framework_mason_packages.lua index 0476742..95dd17c 100644 --- a/lua/polish.lua +++ b/lua/polish/framework_mason_packages.lua @@ -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,25 +58,21 @@ 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 = { "%.%.%/", -- Path traversal - "%;", -- Command separator - "%|", -- Pipe - "%&", -- Background process - "%`", -- Command substitution - "%$", -- Variable expansion - "%!" -- History expansion + "%;", -- Command separator + "%|", -- Pipe + "%&", -- Background process + "%`", -- Command substitution + "%$", -- Variable 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, } + diff --git a/lua/polish/init.lua b/lua/polish/init.lua new file mode 100644 index 0000000..5787d86 --- /dev/null +++ b/lua/polish/init.lua @@ -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, +}