From 468322ca4ffe14ebe3c137a4b89bfe1e8f3db9b0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 13 Mar 2024 22:50:36 +0800 Subject: [PATCH] fix(powershell): fix default powershell formatters --- .../neoformat/formatters/powershell.vim | 16 ++++++++++++---- .../autoload/neoformat/formatters/ps1.vim | 8 ++++---- bundle/neoformat/doc/neoformat.txt | 18 ++++++++++++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/bundle/neoformat/autoload/neoformat/formatters/powershell.vim b/bundle/neoformat/autoload/neoformat/formatters/powershell.vim index 53df0d9e5..2c9ddc45f 100644 --- a/bundle/neoformat/autoload/neoformat/formatters/powershell.vim +++ b/bundle/neoformat/autoload/neoformat/formatters/powershell.vim @@ -12,20 +12,28 @@ " @section PowerShell formatters, supported-filetypes-powershell " @parentsection supported-filetypes " For PowerShell script, there are two default formatters. +" `Edit-DTWBeautifyScript` and `Invoke-Formatter`. +" +" Before using these default formatters, you need to install the PowerShell +" modules. +" > +" Install-Module -Name PowerShell-Beautifier -Scope CurrentUser +" Install-Module -Name PSScriptAnalyzer -Scope CurrentUser +" < " " @subsection PowerShellBeautifier " > " { -" 'exe' : 'Edit-DTWBeautifyScript', -" 'args' : ["-IndentType FourSpaces", "-StandardOutput"], +" 'exe' : 'powershell', +" 'args' : ['-noprofile', '-Command', "Edit-DTWBeautifyScript", "-IndentType", "FourSpaces", "-StandardOutput"], " 'stdin' : 0, " } " < " @subsection PSScriptAnalyzer " > " { -" 'exe' : 'Invoke-Formatter', -" 'args' : ['-ScriptDefinition (Get-Content ' . expand('%') . ' -Raw)'], +" 'exe' : 'powershell', +" 'args' : ['-noprofile', '-Command', 'Invoke-Formatter', '-ScriptDefinition (Get-Content ' . expand('%') . ' -Raw)'], " 'stdin' : 0, " 'no_append' : 1, " } diff --git a/bundle/neoformat/autoload/neoformat/formatters/ps1.vim b/bundle/neoformat/autoload/neoformat/formatters/ps1.vim index ebe206de2..9fbacb6ef 100644 --- a/bundle/neoformat/autoload/neoformat/formatters/ps1.vim +++ b/bundle/neoformat/autoload/neoformat/formatters/ps1.vim @@ -4,16 +4,16 @@ endfunction function! neoformat#formatters#ps1#PowerShellBeautifier() abort return { - \ 'exe' : 'Edit-DTWBeautifyScript', - \ 'args' : ["-IndentType FourSpaces", "-StandardOutput"], + \ 'exe' : 'powershell', + \ 'args' : ['-noprofile', '-Command', "Edit-DTWBeautifyScript", "-IndentType", "FourSpaces", "-StandardOutput"], \ 'stdin' : 0, \ } endfunction function! neoformat#formatters#ps1#PSScriptAnalyzer() abort return { - \ 'exe' : 'Invoke-Formatter', - \ 'args' : ['-ScriptDefinition (Get-Content ' . expand('%') . ' -Raw)'], + \ 'exe' : 'powershell', + \ 'args' : ['-noprofile', '-Command', 'Invoke-Formatter', '-ScriptDefinition (Get-Content ' . expand('%') . ' -Raw)'], \ 'stdin' : 0, \ 'no_append' : 1, \ } diff --git a/bundle/neoformat/doc/neoformat.txt b/bundle/neoformat/doc/neoformat.txt index 3eb9d2cad..8237c8eed 100644 --- a/bundle/neoformat/doc/neoformat.txt +++ b/bundle/neoformat/doc/neoformat.txt @@ -232,13 +232,22 @@ This is a list of default formatters. POWERSHELL FORMATTERS *neoformat-supported-filetypes-powershell* For PowerShell script, there are two default formatters. +`Edit-DTWBeautifyScript` and `Invoke-Formatter`. + +Before using these default formatters, you need to install the PowerShell +modules. +> + Install-Module -Name PowerShell-Beautifier -Scope CurrentUser + Install-Module -Name PSScriptAnalyzer -Scope CurrentUser +< POWERSHELLBEAUTIFIER > { - 'exe' : 'Edit-DTWBeautifyScript', - 'args' : ["-IndentType FourSpaces", "-StandardOutput"], + 'exe' : 'powershell', + 'args' : ['-noprofile', '-Command', "Edit-DTWBeautifyScript", + "-IndentType", "FourSpaces", "-StandardOutput"], 'stdin' : 0, } < @@ -246,8 +255,9 @@ PSSCRIPTANALYZER > { - 'exe' : 'Invoke-Formatter', - 'args' : ['-ScriptDefinition (Get-Content ' . expand('%') . ' -Raw)'], + 'exe' : 'powershell', + 'args' : ['-noprofile', '-Command', 'Invoke-Formatter', '-ScriptDefinition + (Get-Content ' . expand('%') . ' -Raw)'], 'stdin' : 0, 'no_append' : 1, }