diff --git a/config/nvim-lazyvim/lua/plugins/lsp-additional.lua b/config/nvim-lazyvim/lua/plugins/lsp-additional.lua new file mode 100644 index 00000000..298fe7d2 --- /dev/null +++ b/config/nvim-lazyvim/lua/plugins/lsp-additional.lua @@ -0,0 +1,60 @@ +-- Additional cross-platform LSP configurations +-- Auto-detects available tools and only configures relevant LSPs + +return { + "neovim/nvim-lspconfig", + dependencies = { + "mason.nvim", + "mason-org/mason-lspconfig.nvim", + }, + opts = function(_, opts) + local function has(cmd) + return vim.fn.executable(cmd) == 1 + end + + opts.servers = opts.servers or {} + + -- Go LSP (only when Go is available) + if has("go") then + opts.servers.gopls = { + settings = { + gopls = { + analyses = { + unusedparams = true, + shadow = true, + }, + staticcheck = true, + }, + }, + } + end + + -- Rust LSP (only when Cargo is available) + if has("cargo") then + opts.servers.rust_analyzer = { + settings = { + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + }, + }, + }, + } + end + + -- Python LSP (only when Python is available) + if has("python") or has("python3") then + opts.servers.pyright = { + settings = { + python = { + analysis = { + typeCheckingMode = "basic", + }, + }, + }, + } + end + + return opts + end, +} \ No newline at end of file diff --git a/config/nvim-lazyvim/lua/plugins/lsp-bash.lua b/config/nvim-lazyvim/lua/plugins/lsp-bash.lua new file mode 100644 index 00000000..92d7245f --- /dev/null +++ b/config/nvim-lazyvim/lua/plugins/lsp-bash.lua @@ -0,0 +1,31 @@ +-- Cross-platform Bash LSP configuration +-- Only configures Bash LSP when shell tools are available + +return { + "neovim/nvim-lspconfig", + dependencies = { + "mason.nvim", + "mason-org/mason-lspconfig.nvim", + }, + opts = function(_, opts) + local function has(cmd) + return vim.fn.executable(cmd) == 1 + end + + opts.servers = opts.servers or {} + + -- Bash LSP (only when shell is available) + if has("bash") or has("sh") or has("zsh") then + opts.servers.bashls = { + filetypes = { "sh", "bash", "zsh" }, + settings = { + bashIde = { + globPattern = "*@(.sh|.inc|.bash|.command)", + }, + }, + } + end + + return opts + end, +} \ No newline at end of file diff --git a/config/nvim-lazyvim/lua/plugins/lsp-powershell.lua b/config/nvim-lazyvim/lua/plugins/lsp-powershell.lua new file mode 100644 index 00000000..c228ddfc --- /dev/null +++ b/config/nvim-lazyvim/lua/plugins/lsp-powershell.lua @@ -0,0 +1,50 @@ +-- PowerShell LSP configuration +-- Only configures PowerShell LSP when PowerShell is available (cross-platform) + +return { + "neovim/nvim-lspconfig", + dependencies = { + "mason.nvim", + "mason-org/mason-lspconfig.nvim", + }, + opts = function(_, opts) + local function has(cmd) + return vim.fn.executable(cmd) == 1 + end + + opts.servers = opts.servers or {} + + -- PowerShell LSP (only when PowerShell is available) + if has("pwsh") or has("powershell") then + opts.servers.powershell_es = { + filetypes = { "ps1", "psm1", "psd1" }, + single_file_support = true, + settings = { + powershell = { + codeFormatting = { + Preset = "OTBS", + openBraceOnSameLine = true, + newLineAfterOpenBrace = true, + newLineAfterCloseBrace = true, + pipelineIndentationStyle = "IncreaseIndentationAfterEveryPipeline", + whitespaceBeforeOpenBrace = true, + whitespaceBeforeOpenParen = true, + whitespaceAroundOperator = true, + whitespaceAfterSeparator = true, + ignoreOneLineBlock = true, + }, + scriptAnalysis = { + enable = true, + settingsPath = "", + }, + developer = { + editorServicesLogLevel = "Normal", + }, + }, + }, + } + end + + return opts + end, +} diff --git a/config/nvim-lazyvim/lua/plugins/mason.lua b/config/nvim-lazyvim/lua/plugins/mason.lua index 8bb87659..3dfacedb 100644 --- a/config/nvim-lazyvim/lua/plugins/mason.lua +++ b/config/nvim-lazyvim/lua/plugins/mason.lua @@ -1,11 +1,59 @@ return { "mason-org/mason.nvim", - opts = { - ensure_installed = { - "stylua", - "shellcheck", - "shfmt", - "flake8", - }, - }, + opts = function(_, opts) + -- Function to check if a command exists + local function has(cmd) + return vim.fn.executable(cmd) == 1 + end + + -- Base tools for all platforms + local base_tools = { + "stylua", -- Lua formatter + "shellcheck", -- Shell script linter + "shfmt", -- Shell script formatter + } + + -- Conditional tools based on what's available + local conditional_tools = {} + + -- Python tools (if Python is available) + if has("python") or has("python3") then + table.insert(conditional_tools, "flake8") + table.insert(conditional_tools, "black") + end + + -- Bash LSP (if any shell is available) + if has("bash") or has("sh") or has("zsh") then + table.insert(conditional_tools, "bash-language-server") + end + + -- PowerShell LSP (if PowerShell is available) + if has("pwsh") or has("powershell") then + table.insert(conditional_tools, "powershell-editor-services") + end + + -- Node.js tools (if Node is available) + if has("node") or has("npm") then + table.insert(conditional_tools, "prettier") + table.insert(conditional_tools, "eslint_d") + end + + -- Go tools (if Go is available) + if has("go") then + table.insert(conditional_tools, "gopls") + table.insert(conditional_tools, "gofumpt") + end + + -- Rust tools (if Cargo is available) + if has("cargo") then + table.insert(conditional_tools, "rust-analyzer") + end + + -- Combine all tools + local ensure_installed = base_tools + vim.list_extend(ensure_installed, conditional_tools) + + opts.ensure_installed = ensure_installed + return opts + end, } \ No newline at end of file diff --git a/config/nvim-work/lua/lsp/auto_servers.lua b/config/nvim-work/lua/lsp/auto_servers.lua index 3445f7d2..f4e53ad1 100644 --- a/config/nvim-work/lua/lsp/auto_servers.lua +++ b/config/nvim-work/lua/lsp/auto_servers.lua @@ -11,7 +11,10 @@ local server_tool_requirements = { -- npm-based servers ansiblels = "ansible", azure_pipelines_ls = "ansible", - bashls = "bash", + bashls = function() + -- Bash LSP is useful if we have bash or any shell + return has("bash") or has("sh") or has("zsh") + end, css_variables = "npm", cssls = "npm", cssmodules_ls = "npm", @@ -40,7 +43,10 @@ local server_tool_requirements = { lua_ls = "lua", marksman = "cargo", postgres_lsp = "psql", - powershell_es = "pwsh", + powershell_es = function() + -- PowerShell is available if we have pwsh or powershell + return has("pwsh") or has("powershell") + end, superhtml = nil, tflint = "tflint", @@ -106,9 +112,18 @@ local cached_servers = nil local function server_tool_available(server) local required_tool = server_tool_requirements[server] + + -- No requirement means always available if not required_tool then return true end + + -- If it's a function, call it to check availability + if type(required_tool) == "function" then + return required_tool() + end + + -- Otherwise check if the tool executable exists return has(required_tool) end diff --git a/config/nvim-work/lua/lsp/core.lua b/config/nvim-work/lua/lsp/core.lua index ae40d73f..a931f745 100644 --- a/config/nvim-work/lua/lsp/core.lua +++ b/config/nvim-work/lua/lsp/core.lua @@ -82,6 +82,14 @@ function M.setup(ensure_installed) on_attach = M.on_attach, } end, + ["powershell_es"] = function() + local powershell_config = require("lsp.servers.powershell").powershell_es() + if powershell_config then + powershell_config.capabilities = M.capabilities + powershell_config.on_attach = M.on_attach + require("lspconfig").powershell_es.setup(powershell_config) + end + end, ["pyright"] = function() require("lspconfig").pyright.setup { settings = { diff --git a/config/nvim-work/lua/lsp/plugins/mason.lua b/config/nvim-work/lua/lsp/plugins/mason.lua index 79b7d12f..2abbc680 100644 --- a/config/nvim-work/lua/lsp/plugins/mason.lua +++ b/config/nvim-work/lua/lsp/plugins/mason.lua @@ -1,13 +1,30 @@ --- Mason plugin: sets up mason and mason-lspconfig. Actual servers to install are passed when core.setup is invoked. return { - "mason-org/mason-lspconfig.nvim", - dependencies = { - { "mason-org/mason.nvim" }, - "neovim/nvim-lspconfig", - }, - config = function() - -- minimal bootstrap here; core.setup will drive ensure_installed later - require("mason").setup() - require("mason-lspconfig").setup() - end, -} + "mason-org/mason.nvim", + opts = function(_, opts) + -- Detect platform + local is_windows = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1 + + -- Base tools for all platforms + local base_tools = { + "stylua", + "shellcheck", + "shfmt", + "flake8", + "bash-language-server", -- Bash LSP for all platforms + } + + -- Windows-specific tools + local windows_tools = { + "powershell-editor-services", -- PowerShell LSP + } + + -- Combine tools based on platform + local ensure_installed = base_tools + if is_windows then + vim.list_extend(ensure_installed, windows_tools) + end + + opts.ensure_installed = ensure_installed + return opts + end, +} \ No newline at end of file diff --git a/config/nvim-work/lua/lsp/servers/powershell.lua b/config/nvim-work/lua/lsp/servers/powershell.lua new file mode 100644 index 00000000..eb8336b8 --- /dev/null +++ b/config/nvim-work/lua/lsp/servers/powershell.lua @@ -0,0 +1,47 @@ +-- PowerShell LSP server configuration +-- Cross-platform: works on Windows, Linux, and macOS when PowerShell is installed + +local M = {} + +function M.powershell_es() + -- Only configure if PowerShell is actually available + local pwsh_available = vim.fn.executable("pwsh") == 1 + local powershell_available = vim.fn.executable("powershell") == 1 + + if not (pwsh_available or powershell_available) then + return nil + end + + return { + filetypes = { "ps1", "psm1", "psd1" }, + root_dir = function(fname) + return require("lspconfig.util").find_git_ancestor(fname) or vim.fn.getcwd() + end, + single_file_support = true, + settings = { + powershell = { + codeFormatting = { + Preset = "OTBS", -- One True Brace Style + openBraceOnSameLine = true, + newLineAfterOpenBrace = true, + newLineAfterCloseBrace = true, + pipelineIndentationStyle = "IncreaseIndentationAfterEveryPipeline", + whitespaceBeforeOpenBrace = true, + whitespaceBeforeOpenParen = true, + whitespaceAroundOperator = true, + whitespaceAfterSeparator = true, + ignoreOneLineBlock = true, + }, + scriptAnalysis = { + enable = true, + settingsPath = "", + }, + developer = { + editorServicesLogLevel = "Normal", + }, + }, + }, + } +end + +return M \ No newline at end of file diff --git a/config/nvim/lua/lsp/auto_servers.lua b/config/nvim/lua/lsp/auto_servers.lua index 3445f7d2..f4e53ad1 100644 --- a/config/nvim/lua/lsp/auto_servers.lua +++ b/config/nvim/lua/lsp/auto_servers.lua @@ -11,7 +11,10 @@ local server_tool_requirements = { -- npm-based servers ansiblels = "ansible", azure_pipelines_ls = "ansible", - bashls = "bash", + bashls = function() + -- Bash LSP is useful if we have bash or any shell + return has("bash") or has("sh") or has("zsh") + end, css_variables = "npm", cssls = "npm", cssmodules_ls = "npm", @@ -40,7 +43,10 @@ local server_tool_requirements = { lua_ls = "lua", marksman = "cargo", postgres_lsp = "psql", - powershell_es = "pwsh", + powershell_es = function() + -- PowerShell is available if we have pwsh or powershell + return has("pwsh") or has("powershell") + end, superhtml = nil, tflint = "tflint", @@ -106,9 +112,18 @@ local cached_servers = nil local function server_tool_available(server) local required_tool = server_tool_requirements[server] + + -- No requirement means always available if not required_tool then return true end + + -- If it's a function, call it to check availability + if type(required_tool) == "function" then + return required_tool() + end + + -- Otherwise check if the tool executable exists return has(required_tool) end diff --git a/config/nvim/lua/lsp/core.lua b/config/nvim/lua/lsp/core.lua index ae40d73f..a931f745 100644 --- a/config/nvim/lua/lsp/core.lua +++ b/config/nvim/lua/lsp/core.lua @@ -82,6 +82,14 @@ function M.setup(ensure_installed) on_attach = M.on_attach, } end, + ["powershell_es"] = function() + local powershell_config = require("lsp.servers.powershell").powershell_es() + if powershell_config then + powershell_config.capabilities = M.capabilities + powershell_config.on_attach = M.on_attach + require("lspconfig").powershell_es.setup(powershell_config) + end + end, ["pyright"] = function() require("lspconfig").pyright.setup { settings = { diff --git a/config/nvim/lua/lsp/servers/powershell.lua b/config/nvim/lua/lsp/servers/powershell.lua new file mode 100644 index 00000000..eb8336b8 --- /dev/null +++ b/config/nvim/lua/lsp/servers/powershell.lua @@ -0,0 +1,47 @@ +-- PowerShell LSP server configuration +-- Cross-platform: works on Windows, Linux, and macOS when PowerShell is installed + +local M = {} + +function M.powershell_es() + -- Only configure if PowerShell is actually available + local pwsh_available = vim.fn.executable("pwsh") == 1 + local powershell_available = vim.fn.executable("powershell") == 1 + + if not (pwsh_available or powershell_available) then + return nil + end + + return { + filetypes = { "ps1", "psm1", "psd1" }, + root_dir = function(fname) + return require("lspconfig.util").find_git_ancestor(fname) or vim.fn.getcwd() + end, + single_file_support = true, + settings = { + powershell = { + codeFormatting = { + Preset = "OTBS", -- One True Brace Style + openBraceOnSameLine = true, + newLineAfterOpenBrace = true, + newLineAfterCloseBrace = true, + pipelineIndentationStyle = "IncreaseIndentationAfterEveryPipeline", + whitespaceBeforeOpenBrace = true, + whitespaceBeforeOpenParen = true, + whitespaceAroundOperator = true, + whitespaceAfterSeparator = true, + ignoreOneLineBlock = true, + }, + scriptAnalysis = { + enable = true, + settingsPath = "", + }, + developer = { + editorServicesLogLevel = "Normal", + }, + }, + }, + } +end + +return M \ No newline at end of file