From 196eb0aa4ec454f7c7d00193b6ffb8dc55ca4d11 Mon Sep 17 00:00:00 2001 From: Meisterlala <6453306+Meisterlala@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:01:02 +0100 Subject: [PATCH] 2025-11-21-21:01:02 --- lua/plugins/powershell.lua | 6 ++++++ lua/pwsh_lsp.lua | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lua/plugins/powershell.lua b/lua/plugins/powershell.lua index d5704a0..0d2a4c6 100644 --- a/lua/plugins/powershell.lua +++ b/lua/plugins/powershell.lua @@ -6,5 +6,11 @@ return { ---@type powershell.user_config opts = { bundle_path = vim.fn.stdpath 'data' .. '/mason/packages/powershell-editor-services', + settings = { + powershell = { + enableProfileLoading = false, + enableConsoleRepl = true, + }, + }, }, } diff --git a/lua/pwsh_lsp.lua b/lua/pwsh_lsp.lua index feeb919..598036a 100644 --- a/lua/pwsh_lsp.lua +++ b/lua/pwsh_lsp.lua @@ -1,5 +1,8 @@ local M = {} +-- default excluded rules +M.ExculeRules = { 'PSAvoidGlobalVars', 'PSUseSingularNouns', 'PSAvoidUsingWriteHost' } + -- auto-install PSScriptAnalyzer if missing local function ensure_pssa() local check = vim.fn.systemlist 'pwsh -NoProfile -Command "Get-Module -ListAvailable -Name PSScriptAnalyzer"' @@ -28,6 +31,15 @@ function M.run_pssa() local ns = vim.api.nvim_create_namespace 'PSSA' local buf_text = vim.api.nvim_buf_get_lines(0, 0, -1, false) local buffer_content = table.concat(buf_text, '\n') + local rules_str = '"' .. table.concat(M.ExculeRules, '", "') .. '"' + local pwsh_command = string.format( + [[ + Import-Module PSScriptAnalyzer -Force; + Invoke-ScriptAnalyzer -Settings @{ExcludeRules=@(%s)} -ScriptDefinition ([Console]::In.ReadToEnd()) | + ForEach-Object { "$($_.Line):$($_.Column):$($_.Severity):$($_.RuleName):$($_.Message)" } + ]], + rules_str + ) local Job = require 'plenary.job' Job:new({ @@ -36,14 +48,10 @@ function M.run_pssa() '-NoProfile', '-NoLogo', '-Command', - [[ -Import-Module PSScriptAnalyzer -Force; -Invoke-ScriptAnalyzer -Settings @{ExcludeRules=@("PSAvoidGlobalVars", "PSUseSingularNouns")} -ScriptDefinition ([Console]::In.ReadToEnd()) | -ForEach-Object { "$($_.Line):$($_.Column):$($_.Severity):$($_.RuleName):$($_.Message)" } -]], + pwsh_command, }, writer = buffer_content, -- plenary pipes this to stdin - on_exit = function(j, return_val) + on_exit = function(j, _) local output = j:result() local diagnostics = {} -- 2.51.2