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 |
Konfekt | 4927dae | 2024-11-19 22:41:14 +0100 | [diff] [blame] | 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) |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 9 | |
| 10 | if exists("current_compiler") |
| 11 | finish |
| 12 | endif |
| 13 | let current_compiler = "powershell" |
| 14 | |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 15 | let s:cpo_save = &cpo |
| 16 | set cpo-=C |
| 17 | |
| 18 | if !exists("g:ps1_makeprg_cmd") |
| 19 | if executable('pwsh') |
| 20 | " pwsh is the future |
| 21 | let g:ps1_makeprg_cmd = 'pwsh' |
| 22 | elseif executable('pwsh.exe') |
| 23 | let g:ps1_makeprg_cmd = 'pwsh.exe' |
| 24 | elseif executable('powershell.exe') |
| 25 | let g:ps1_makeprg_cmd = 'powershell.exe' |
| 26 | else |
| 27 | let g:ps1_makeprg_cmd = '' |
| 28 | endif |
| 29 | endif |
| 30 | |
| 31 | if !executable(g:ps1_makeprg_cmd) |
| 32 | echoerr "To use the powershell compiler, please set g:ps1_makeprg_cmd to the powershell executable!" |
| 33 | endif |
| 34 | |
| 35 | " Show CategoryInfo, FullyQualifiedErrorId, etc? |
| 36 | let g:ps1_efm_show_error_categories = get(g:, 'ps1_efm_show_error_categories', 0) |
| 37 | |
| 38 | " Use absolute path because powershell requires explicit relative paths |
| 39 | " (./file.ps1 is okay, but # expands to file.ps1) |
zeertzjq | b73faa1 | 2024-04-06 02:01:16 +0800 | [diff] [blame] | 40 | let s:makeprg = g:ps1_makeprg_cmd .. ' %:p:S' |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 41 | |
| 42 | " Parse file, line, char from callstacks: |
| 43 | " Write-Ouput : The term 'Write-Ouput' is not recognized as the name of a |
| 44 | " cmdlet, function, script file, or operable program. Check the spelling |
| 45 | " of the name, or if a path was included, verify that the path is correct |
| 46 | " and try again. |
| 47 | " At C:\script.ps1:11 char:5 |
| 48 | " + Write-Ouput $content |
| 49 | " + ~~~~~~~~~~~ |
| 50 | " + CategoryInfo : ObjectNotFound: (Write-Ouput:String) [], CommandNotFoundException |
| 51 | " + FullyQualifiedErrorId : CommandNotFoundException |
| 52 | |
Konfekt | 4927dae | 2024-11-19 22:41:14 +0100 | [diff] [blame] | 53 | execute 'CompilerSet makeprg=' .. escape(s:makeprg, ' \|"') |
Enno | 18d730d | 2024-03-31 18:37:05 +0200 | [diff] [blame] | 54 | |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 55 | " Showing error in context with underlining. |
| 56 | CompilerSet errorformat=%+G+%m |
| 57 | " Error summary. |
| 58 | CompilerSet errorformat+=%E%*\\S\ :\ %m |
| 59 | " Error location. |
| 60 | CompilerSet errorformat+=%CAt\ %f:%l\ char:%c |
| 61 | " Errors that span multiple lines (may be wrapped to width of terminal). |
| 62 | CompilerSet errorformat+=%C%m |
| 63 | " Ignore blank/whitespace-only lines. |
| 64 | CompilerSet errorformat+=%Z\\s%# |
| 65 | |
| 66 | if g:ps1_efm_show_error_categories |
| 67 | CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m |
| 68 | else |
| 69 | CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m |
| 70 | endif |
| 71 | |
| 72 | |
| 73 | " Parse file, line, char from of parse errors: |
| 74 | " At C:\script.ps1:22 char:16 |
| 75 | " + Stop-Process -Name "invalidprocess |
| 76 | " + ~~~~~~~~~~~~~~~ |
| 77 | " The string is missing the terminator: ". |
| 78 | " + CategoryInfo : ParserError: (:) [], ParseException |
| 79 | " + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString |
| 80 | CompilerSet errorformat+=At\ %f:%l\ char:%c |
| 81 | |
| 82 | |
| 83 | let &cpo = s:cpo_save |
| 84 | unlet s:cpo_save |
| 85 | |
| 86 | " vim:set sw=2 sts=2: |