refactor: restructure polish module from single file to modular directory format
Signed-off-by: User <user@example.com>
This commit is contained in:
parent
6f1adc9381
commit
459fa712d9
2
init.lua
2
init.lua
@ -24,4 +24,4 @@ if not pcall(require, "lazy") then
|
|||||||
end
|
end
|
||||||
|
|
||||||
require "lazy_setup"
|
require "lazy_setup"
|
||||||
require "polish"
|
require "polish.init"
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
--- @meta
|
--- Mason package installation utilities for Neovim.
|
||||||
|
--- This module provides functions for installing Mason packages based on framework environment.
|
||||||
--- 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.
|
|
||||||
|
|
||||||
--- @alias FrameworkName "python"|"vue"|string
|
--- @alias FrameworkName "python"|"vue"|string
|
||||||
|
|
||||||
@ -44,7 +40,7 @@ local FRAMEWORK_TOOLS = {
|
|||||||
--- returns an empty table.
|
--- returns an empty table.
|
||||||
--- @return string[] tools List of tools to install for the detected framework, or empty table if no framework is set
|
--- @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 function get_framework_tools()
|
||||||
local current_framework = os.getenv("FRAMEWORK")
|
local current_framework = os.getenv "FRAMEWORK"
|
||||||
|
|
||||||
if current_framework then
|
if current_framework then
|
||||||
local tools = FRAMEWORK_TOOLS[current_framework]
|
local tools = FRAMEWORK_TOOLS[current_framework]
|
||||||
@ -62,9 +58,7 @@ end
|
|||||||
local function is_valid_package_name(package_name)
|
local function is_valid_package_name(package_name)
|
||||||
-- Basic validation: package names should only contain alphanumeric characters, hyphens, and dots
|
-- Basic validation: package names should only contain alphanumeric characters, hyphens, and dots
|
||||||
-- This prevents command injection attacks
|
-- This prevents command injection attacks
|
||||||
if type(package_name) ~= "string" or package_name == "" then
|
if type(package_name) ~= "string" or package_name == "" then return false end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Additional security: check for potentially dangerous patterns
|
-- Additional security: check for potentially dangerous patterns
|
||||||
local dangerous_patterns = {
|
local dangerous_patterns = {
|
||||||
@ -74,13 +68,11 @@ local function is_valid_package_name(package_name)
|
|||||||
"%&", -- Background process
|
"%&", -- Background process
|
||||||
"%`", -- Command substitution
|
"%`", -- Command substitution
|
||||||
"%$", -- Variable expansion
|
"%$", -- Variable expansion
|
||||||
"%!" -- History expansion
|
"%!", -- History expansion
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pattern in ipairs(dangerous_patterns) do
|
for _, pattern in ipairs(dangerous_patterns) do
|
||||||
if string.match(package_name, pattern) then
|
if string.match(package_name, pattern) then return false end
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for valid characters: alphanumeric, hyphen, dot, underscore
|
-- Check for valid characters: alphanumeric, hyphen, dot, underscore
|
||||||
@ -95,7 +87,6 @@ local function is_mason_available()
|
|||||||
return mason_ok
|
return mason_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Installs Mason packages based on the current framework environment.
|
--- Installs Mason packages based on the current framework environment.
|
||||||
--- This function retrieves the appropriate tool set and installs them one by one
|
--- This function retrieves the appropriate tool set and installs them one by one
|
||||||
--- to handle individual failures gracefully. Each package installation is wrapped
|
--- 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)
|
vim.notify("Skipping invalid package name: " .. package, vim.log.levels.WARN)
|
||||||
failed_count = failed_count + 1
|
failed_count = failed_count + 1
|
||||||
else
|
else
|
||||||
local success, result = pcall(function()
|
local success, result = pcall(function() vim.cmd("MasonInstall " .. package) end)
|
||||||
vim.cmd("MasonInstall " .. package)
|
|
||||||
end)
|
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
installed_count = installed_count + 1
|
installed_count = installed_count + 1
|
||||||
@ -137,25 +126,29 @@ function InstallMyMasonPackages()
|
|||||||
|
|
||||||
-- Provide summary
|
-- Provide summary
|
||||||
if failed_count == 0 then
|
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
|
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
|
end
|
||||||
else
|
else
|
||||||
vim.notify("No framework detected or no packages to install", vim.log.levels.INFO)
|
vim.notify("No framework detected or no packages to install", vim.log.levels.INFO)
|
||||||
end
|
end
|
||||||
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
|
-- Module exports
|
||||||
return {
|
return {
|
||||||
FRAMEWORK_TOOLS = FRAMEWORK_TOOLS,
|
FRAMEWORK_TOOLS = FRAMEWORK_TOOLS,
|
||||||
get_framework_tools = get_framework_tools,
|
get_framework_tools = get_framework_tools,
|
||||||
InstallMyMasonPackages = InstallMyMasonPackages,
|
InstallMyMasonPackages = InstallMyMasonPackages,
|
||||||
}
|
}
|
||||||
|
|
||||||
23
lua/polish/init.lua
Normal file
23
lua/polish/init.lua
Normal 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,
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user