powershell.vim (2954B)
1 " Vim compiler file 2 " Compiler: powershell 3 " URL: https://github.com/PProvost/vim-ps1 4 " Contributors: Enno Nagel 5 " Last Change: 2024 Mar 29 6 " 2024 Apr 03 by the Vim Project (removed :CompilerSet definition) 7 " 2024 Apr 05 by the Vim Project (avoid leaving behind g:makeprg) 8 " 2024 Nov 19 by the Vim Project (properly escape makeprg setting) 9 " 2025 Mar 11 by the Vim Project (add comment for Dispatch) 10 11 if exists("current_compiler") 12 finish 13 endif 14 let current_compiler = "powershell" 15 16 let s:cpo_save = &cpo 17 set cpo-=C 18 19 if !exists("g:ps1_makeprg_cmd") 20 if executable('pwsh') 21 " pwsh is the future 22 let g:ps1_makeprg_cmd = 'pwsh' 23 elseif executable('pwsh.exe') 24 let g:ps1_makeprg_cmd = 'pwsh.exe' 25 elseif executable('powershell.exe') 26 let g:ps1_makeprg_cmd = 'powershell.exe' 27 else 28 let g:ps1_makeprg_cmd = '' 29 endif 30 endif 31 32 if !executable(g:ps1_makeprg_cmd) 33 echoerr "To use the powershell compiler, please set g:ps1_makeprg_cmd to the powershell executable!" 34 endif 35 36 " Show CategoryInfo, FullyQualifiedErrorId, etc? 37 let g:ps1_efm_show_error_categories = get(g:, 'ps1_efm_show_error_categories', 0) 38 39 " Use absolute path because powershell requires explicit relative paths 40 " (./file.ps1 is okay, but # expands to file.ps1) 41 let s:makeprg = g:ps1_makeprg_cmd .. ' %:p:S' 42 43 " Parse file, line, char from callstacks: 44 " Write-Ouput : The term 'Write-Ouput' is not recognized as the name of a 45 " cmdlet, function, script file, or operable program. Check the spelling 46 " of the name, or if a path was included, verify that the path is correct 47 " and try again. 48 " At C:\script.ps1:11 char:5 49 " + Write-Ouput $content 50 " + ~~~~~~~~~~~ 51 " + CategoryInfo : ObjectNotFound: (Write-Ouput:String) [], CommandNotFoundException 52 " + FullyQualifiedErrorId : CommandNotFoundException 53 54 " CompilerSet makeprg=pwsh 55 " CompilerSet makeprg=powershell 56 execute 'CompilerSet makeprg=' .. escape(s:makeprg, ' \|"') 57 58 " Showing error in context with underlining. 59 CompilerSet errorformat=%+G+%m 60 " Error summary. 61 CompilerSet errorformat+=%E%*\\S\ :\ %m 62 " Error location. 63 CompilerSet errorformat+=%CAt\ %f:%l\ char:%c 64 " Errors that span multiple lines (may be wrapped to width of terminal). 65 CompilerSet errorformat+=%C%m 66 " Ignore blank/whitespace-only lines. 67 CompilerSet errorformat+=%Z\\s%# 68 69 if g:ps1_efm_show_error_categories 70 CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m 71 else 72 CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m 73 endif 74 75 76 " Parse file, line, char from of parse errors: 77 " At C:\script.ps1:22 char:16 78 " + Stop-Process -Name "invalidprocess 79 " + ~~~~~~~~~~~~~~~ 80 " The string is missing the terminator: ". 81 " + CategoryInfo : ParserError: (:) [], ParseException 82 " + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString 83 CompilerSet errorformat+=At\ %f:%l\ char:%c 84 85 86 let &cpo = s:cpo_save 87 unlet s:cpo_save 88 89 " vim:set sw=2 sts=2: