Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions config/nvim-lazyvim/lua/plugins/lsp-additional.lua
Original file line number Diff line number Diff line change
@@ -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,
}
31 changes: 31 additions & 0 deletions config/nvim-lazyvim/lua/plugins/lsp-bash.lua
Original file line number Diff line number Diff line change
@@ -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,
}
50 changes: 50 additions & 0 deletions config/nvim-lazyvim/lua/plugins/lsp-powershell.lua
Original file line number Diff line number Diff line change
@@ -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,
}
64 changes: 56 additions & 8 deletions config/nvim-lazyvim/lua/plugins/mason.lua
Original file line number Diff line number Diff line change
@@ -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,
}
19 changes: 17 additions & 2 deletions config/nvim-work/lua/lsp/auto_servers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",

Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions config/nvim-work/lua/lsp/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
41 changes: 29 additions & 12 deletions config/nvim-work/lua/lsp/plugins/mason.lua
Original file line number Diff line number Diff line change
@@ -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,
}
47 changes: 47 additions & 0 deletions config/nvim-work/lua/lsp/servers/powershell.lua
Original file line number Diff line number Diff line change
@@ -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
Loading