Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 1 | " Vim compiler file |
| 2 | " Compiler: powershell |
| 3 | " URL: https://github.com/PProvost/vim-ps1 |
Enno | 18d730d | 2024-03-31 18:37:05 +0200 | [diff] [blame] | 4 | " Contributors: Enno Nagel |
| 5 | " Last Change: 2024 Mar 29 |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 6 | |
| 7 | if exists("current_compiler") |
| 8 | finish |
| 9 | endif |
| 10 | let current_compiler = "powershell" |
| 11 | |
| 12 | if exists(":CompilerSet") != 2 " older Vim always used :setlocal |
| 13 | command -nargs=* CompilerSet setlocal <args> |
| 14 | endif |
| 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) |
Enno | 18d730d | 2024-03-31 18:37:05 +0200 | [diff] [blame] | 41 | let makeprg = g:ps1_makeprg_cmd .. ' %:p:S' |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 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 | |
Enno | 18d730d | 2024-03-31 18:37:05 +0200 | [diff] [blame] | 54 | execute 'CompilerSet makeprg=' .. escape(makeprg, ' ') |
| 55 | |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 56 | " Showing error in context with underlining. |
| 57 | CompilerSet errorformat=%+G+%m |
| 58 | " Error summary. |
| 59 | CompilerSet errorformat+=%E%*\\S\ :\ %m |
| 60 | " Error location. |
| 61 | CompilerSet errorformat+=%CAt\ %f:%l\ char:%c |
| 62 | " Errors that span multiple lines (may be wrapped to width of terminal). |
| 63 | CompilerSet errorformat+=%C%m |
| 64 | " Ignore blank/whitespace-only lines. |
| 65 | CompilerSet errorformat+=%Z\\s%# |
| 66 | |
| 67 | if g:ps1_efm_show_error_categories |
| 68 | CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m |
| 69 | else |
| 70 | CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m |
| 71 | endif |
| 72 | |
| 73 | |
| 74 | " Parse file, line, char from of parse errors: |
| 75 | " At C:\script.ps1:22 char:16 |
| 76 | " + Stop-Process -Name "invalidprocess |
| 77 | " + ~~~~~~~~~~~~~~~ |
| 78 | " The string is missing the terminator: ". |
| 79 | " + CategoryInfo : ParserError: (:) [], ParseException |
| 80 | " + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString |
| 81 | CompilerSet errorformat+=At\ %f:%l\ char:%c |
| 82 | |
| 83 | |
| 84 | let &cpo = s:cpo_save |
| 85 | unlet s:cpo_save |
| 86 | |
| 87 | " vim:set sw=2 sts=2: |