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
|
||||
|
||||
require "lazy_setup"
|
||||
require "polish"
|
||||
require "polish.init"
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
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