summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorJesse Harris <zigford@gmail.com>2019-04-13 21:24:56 +1000
committerw0rp <w0rp@users.noreply.github.com>2019-04-13 12:24:56 +0100
commit2ed53108c4f000e0a36a79c4317dad4fdfb545fe (patch)
tree85c7e046cab44b4e4a776b215c1378aaeec528a0 /autoload
parentd7395906ba0f9aca2fb1a6c32df236bfd4ab32f6 (diff)
downloadale-2ed53108c4f000e0a36a79c4317dad4fdfb545fe.zip
Linter for powershell syntax errors (#2413)
* Linter for powershell syntax errors
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/powershell.vim32
1 files changed, 32 insertions, 0 deletions
diff --git a/autoload/ale/powershell.vim b/autoload/ale/powershell.vim
new file mode 100644
index 00000000..8c163206
--- /dev/null
+++ b/autoload/ale/powershell.vim
@@ -0,0 +1,32 @@
+" Author: zigford <zigford@gmail.com>
+" Description: Functions for integrating with Powershell linters.
+
+" Write a powershell script to a temp file for execution
+" return the command used to execute it
+function! s:TemporaryPSScript(buffer, input) abort
+ let l:filename = 'script.ps1'
+ " Create a temp dir to house our temp .ps1 script
+ " a temp dir is needed as powershell needs the .ps1
+ " extension
+ let l:tempdir = ale#util#Tempname() . (has('win32') ? '\' : '/')
+ let l:tempscript = l:tempdir . l:filename
+ " Create the temporary directory for the file, unreadable by 'other'
+ " users.
+ call mkdir(l:tempdir, '', 0750)
+ " Automatically delete the directory later.
+ call ale#command#ManageDirectory(a:buffer, l:tempdir)
+ " Write the script input out to a file.
+ call ale#util#Writefile(a:buffer, a:input, l:tempscript)
+
+ return l:tempscript
+endfunction
+
+function! ale#powershell#RunPowerShell(buffer, base_var_name, command) abort
+ let l:executable = ale#Var(a:buffer, a:base_var_name . '_executable')
+ let l:tempscript = s:TemporaryPSScript(a:buffer, a:command)
+
+ return ale#Escape(l:executable)
+ \ . ' -Exe Bypass -NoProfile -File '
+ \ . ale#Escape(l:tempscript)
+ \ . ' %t'
+endfunction